Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install as package part2 #845

Merged
merged 4 commits into from
Feb 19, 2020
Merged

Install as package part2 #845

merged 4 commits into from
Feb 19, 2020

Conversation

nerdvegas
Copy link
Contributor

Working off #579, but with following changes (@j0yu ):

  • Use of PackageMaker code in install.py was too fragile. Only a few rez modules are imported here, because rez isn't built yet. Importing PackageMaker greatly increases the amount of code we import in the installer, which means that any changes (like compiled source - which is coming) will probably break it. I've taken basically the same approach, but moved that functionality into the installation instead and done it that way.
  • Removed cli tools from the rez package. I don't want to encourage that use case - the production install is there for that, the rez package is intended for using the rez API.

@j0yu
Copy link
Contributor

j0yu commented Feb 6, 2020

Looks good, maybe you can add some Ci/tests to it, like the ones from #579 (which I could close in favour of this one)

@nerdvegas
Copy link
Contributor Author

nerdvegas commented Feb 7, 2020 via email

Copy link
Contributor

@j0yu j0yu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it more, I think what I was trying to achieve with #579
might be different than in this PR:

  • This PR looks to me to be focusing more just the rez and rezplugin
    Python modules, similar to rez bind rez

  • [Feature] Install as package #579 was trying to do a production install of rez and as a rez package,
    similar to python install.py DIR and then making DIR a rez package.

    • Adds rez production install scripts to PATH, and
    • Adds rez production install's rez and rezplugin to PYTHONPATH

I feel this PR should be prioritised though as I like the new functions and
installer.py introduced here. #579 can then be rebased and refactored to use
these.

I'm happy to have my my PR on hold while this is being merged.

# cleanup temp install
try:
shutil.rmtree(tmpdir)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except:
except Exception:

Comment on lines +161 to +176
def install_as_rez_package(repo_path):
"""Installs rez as a rez package.

Note that this can be used to install new variants of rez into an existing
rez package (you may require multiple platform installations for example).

Args:
repo_path (str): Full path to the package repository to install into.
"""
from tempfile import mkdtemp

# do a temp production (venv-based) rez install
tmpdir = mkdtemp(prefix="rez-install-")
install(tmpdir)

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this temp install setup can be turned into a context so it can be re-used in the future:

temp_install context
import contextlib


@contextlib.contextmanager
def temp_install(cleanup=True, print_welcome=False):
    """Do a temp production (venv-based) rez install.
    
    Args:
        cleanup (bool): Cleanup temp install when exiting context.
    """
    from tempfile import mkdtemp

    tmpdir = mkdtemp(prefix="rez-install-")
    install(tmpdir, print_welcome=print_welcome)

    try:
        yield tmpdir
    finally:
        if cleanup:
            try:
                shutil.rmtree(tmpdir)
            except Exception:
                pass


def install_as_rez_package(repo_path):
    """Installs rez as a rez package.
    
    Note that this can be used to install new variants of rez into an existing
    rez package (you may require multiple platform installations for example).
    
    Args:
        repo_path (str): Full path to the package repository to install into.
    """
    with temp_install() as tmpdir:
        # This extracts a rez package from the installation. See
        # rez.utils.installer.install_as_rez_package for more details.
        #
        args = (
            os.path.join(tmpdir, "bin", "python"), "-E", "-c",
            r"from rez.utils.installer import install_as_rez_package;"
            r"install_as_rez_package('%s')" % repo_path
        )
        print(subprocess.check_output(args))

@nerdvegas nerdvegas merged commit dfa97f8 into master Feb 19, 2020
@bpabel bpabel deleted the install_as_package_part2 branch January 19, 2023 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants