AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
949 stars 338 forks source link

Modify package install_path based on build args #529

Open maty974 opened 6 years ago

maty974 commented 6 years ago

Hi

I'm trying to modify the install_path used in a rezbuild.py package so if I pass the argument dev to rez-build like so: rez-build --install --ba dev the install folder get renamed to ../dev instead of version found in the package.

Basically I want it to install package foo version 1.0.0 into the local package path but instead of install it into 1.0.0 folder I want dev folder name.

So I've to do this in rezbuild.py, but it seems that rez-build is doing something else to copy the package.py file to the default install_path with package version folder.

Here what I've done:

in rezbuild.py:

    def _rename_to_dev():
        # override install_path version if DEV args is found
        version_dir=os.path.basename(install_path)
        dev_install_path=install_path.replace(version_dir,'dev')

        print "Renaming %s to %s" %(install_path,dev_install_path)
        os.rename(install_path, dev_install_path)
....
    if "install" in (targets or []):
        _install()

        if "dev" in (build_args or []):
            _rename_to_dev()

After the build install I correctly have my folder renamed to dev but it missing the package.py file and this file has been put into the 1.0.0 folder version like so:

.../packages/builds/foo/1.0.0
contains only the package.py file
.../packages/builds/foo/dev
contains my deployed package files

Any idea on how I'm supposed to do this correctly ?

Thanks! Maty

nerdvegas commented 6 years ago

Hi Matthieu,

I don't think this approach is going to work. Even if you do manage to rename the installation path, you're going to end up with an odd case where package foo-1.0.0 is written into a path that doesn't match its version. This may lead to a number of issues; we're kinda messing with rez internals at this point and there won't be any guarantees things will work correctly. The way package repositories work is dependent on packages being written into the correct filesystem location, and that is dependent on the package version.

A better approach would be to implement your package version as an early binding function, which changes its version to 'dev' depending on the situation. As it stands, I don't think you'd be able to change version based on build args - these aren't stored into an env-var (but that could be fixed). However, you could do this:

# in package.py
name = "foo"

__version = "1.0.0"

@early()
def version():
    import os
    if os.getenv("FORCE_DEV"):
        return "dev"
    else:
        return __version

This would make your package switch to version "dev" if env-var FORCE_DEV is set; you put the actual package version into __version. See https://github.com/nerdvegas/rez/wiki/Package-Definition-Guide#package-attributes for more details.

If you wanted to always set version to dev for non-release installs, you could check the env-var REZ_BUILD_TYPE (see https://github.com/nerdvegas/rez/wiki/Environment-Variables#resolved-build-environment-variables ).

Hth A

On Wed, Sep 26, 2018 at 5:13 PM, Matthieu Cadet notifications@github.com wrote:

Hi

I'm trying to modify the install_path used in a rezbuild.py package so if I pass the argument dev to rez-build like so: rez-build --install --ba dev the install folder get renamed to ../dev instead of version found in the package.

Basically I want it to install package foo version 1.0.0 into the local package path but instead of install it into 1.0.0 folder I want dev folder name.

So I've to do this in rezbuild.py, but it seems that rez-build is doing something else to copy the package.py file to the default install_path with package version folder.

Here what I've done:

in rezbuild.py:

def _rename_to_dev():
    # override install_path version if DEV args is found
    version_dir=os.path.basename(install_path)
    dev_install_path=install_path.replace(version_dir,'dev')

    print "Renaming %s to %s" %(install_path,dev_install_path)
    os.rename(install_path, dev_install_path)....
if "install" in (targets or []):
    _install()

    if "dev" in (build_args or []):
        _rename_to_dev()

After the build install I correctly have my folder renamed to dev but it missing the package.py file and this file has been put into the 1.0.0 folder version like so:

.../packages/builds/foo/1.0.0 contains only the package.py file

.../packages/builds/foo/dev contains my deployed package files

Any idea on how I'm supposed to do this correctly ?

Thanks! Maty

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nerdvegas/rez/issues/529, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjqSv1xHlDVZLJnpqlytY7S11xrrK1Gks5ueykXgaJpZM4W6CFL .

maty974 commented 6 years ago

Hi @nerdvegas !

I've actually found a solution by using package_preprocess_function in my rez conf file, as I don't want to modify each package.py to support this custom version string.

Something like this:

import os

def version_to_dev(this, data):
    if "USE_DEV" in os.environ:
        data["version"]="dev"

Anyway, thanks for your help, I'll keep it like that as it seems to work fine with this solution. I will looking forward when this implementation will be done in rez ( access build args within package.py )

maty

nerdvegas commented 6 years ago

Oh yes, using the package preprocessing is also a perfectly acceptable fix for this, well spotted.

Thx A

On Thu, Sep 27, 2018 at 3:33 PM, Matthieu Cadet notifications@github.com wrote:

Hi @nerdvegas https://github.com/nerdvegas !

I've actually found a solution by using package_preprocess_function in my rez conf file, as I don't want to modify each package.py to support this custom version string.

Something like this:

import os def version_to_dev(this, data): if "USE_DEV" in os.environ: data["version"]="dev"

Anyway, thanks for your help, I'll keep it like that as it seems to work fine with this solution. I will looking forward when this implementation will be done in rez ( access build args within package.py )

maty

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nerdvegas/rez/issues/529#issuecomment-424964281, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjqSi_kFcOezjemFCjXD9a3ty97Glzvks5ufGMpgaJpZM4W6CFL .