diff --git a/package.py b/package.py index 2f32aa1..7be7905 100644 --- a/package.py +++ b/package.py @@ -1,5 +1,5 @@ name = "pipz" -version = "1.2.2" +version = "1.3.0" requires = ["bleeding_rez-2.29+", "python>=2,<4"] tools = [ diff --git a/python/pipz/cli.py b/python/pipz/cli.py index 978f331..a3ecadd 100644 --- a/python/pipz/cli.py +++ b/python/pipz/cli.py @@ -85,6 +85,10 @@ def _install(opts, extra_args, tempdir): tell("Using pip-%s" % pip_version) tell("Using pipz-%s" % version) + as_bundle = bool(opts.bundle and int(os.getenv("REZ_BUILD_ENV", "0"))) + rez_installing = bool(int(os.getenv("REZ_BUILD_INSTALL", "0"))) + packagesdir = "" + try: with stage("Reading package lists... "): distributions = pip.download( @@ -120,11 +124,18 @@ def _install(opts, extra_args, tempdir): release_packages_path if opts.release else local_packages_path ) - if pip.exists(package, packagesdir): + if not as_bundle and pip.exists(package, packagesdir): exists.append(package) else: new.append(package) + if as_bundle: + prefix = opts.prefix or "" + if rez_installing: + packagesdir = os.environ["REZ_BUILD_INSTALL_PATH"] + prefix + else: + packagesdir = os.environ["REZ_BUILD_PATH"] + prefix + if not new: for package in exists: tell("%s-%s was already installed" % ( @@ -171,7 +182,7 @@ def format_variants(package): tell("Packages will be installed to %s" % packagesdir) tell("After this operation, %.2f mb will be used." % size) - if not opts.yes and not opts.quiet: + if not as_bundle and (not opts.yes and not opts.quiet): if not ask("Do you want to continue? [Y/n] "): print("Cancelled") return @@ -186,7 +197,8 @@ def format_variants(package): with stage(msg, timing=False): pip.deploy( package, - path=packagesdir + path=packagesdir, + as_bundle=as_bundle, ) tell("%d installed, %d skipped" % (len(new), len(exists))) @@ -224,6 +236,11 @@ def main(argv=sys.argv): parser.add_argument( "install", nargs="+", help="Install the package") + parser.add_argument( + "-b", "--bundle", action="store_true", + help="If enabled, and environment variable $REZ_BUILD_ENV is set, " + "all packages and their requirements will be deployed into " + "current Rez package build/install path.") parser.add_argument( "--search", nargs="+", help="Search for the package on PyPi") @@ -233,10 +250,15 @@ def main(argv=sys.argv): "locally only") parser.add_argument( "-va", "--variant", action="append", - help="Install package as variant, may be called multiple times.") + help="Install package as variant, may be called multiple times. " + "This option will be ignored if --bundle enabled and environment " + "variable $REZ_BUILD_ENV is set.") parser.add_argument( "-p", "--prefix", type=str, metavar="PATH", - help="Install to a custom package repository path.") + help="Install to a custom package repository path. If --bundle " + "enabled and environment variable $REZ_BUILD_ENV is set, " + "the --prefix will become the suffix of current Rez package " + "build/install path.") parser.add_argument( "-y", "--yes", action="store_true", help="Pre-emptively answer the question to continue") diff --git a/python/pipz/pip.py b/python/pipz/pip.py index 86a929a..047bbb3 100644 --- a/python/pipz/pip.py +++ b/python/pipz/pip.py @@ -288,16 +288,20 @@ def _files_from_distribution(dist): yield relpath -def deploy(package, path, shim="binary"): +def deploy(package, path, shim="binary", as_bundle=False): """Deploy `distribution` as `package` at `path` Arguments: package (rez.Package): Source package path (str): Path to install directory, e.g. "~/packages" + shim (str): Windows-only, whether to generate binary or bat scripts. + Valid input is "binary" or "bat", default is "binary". + as_bundle (bool): Deploy packages as one bundle. No variant will be + installed nor returned if this is `True`. """ - def make_root(variant, destination_root): + def _deploy(destination_root): distribution = _package_to_distribution[package] # Store files from distribution for deployment @@ -331,7 +335,7 @@ def make_root(variant, destination_root): if not console_scripts: return - dst = os.path.join(root, "bin") + dst = os.path.join(destination_root, "bin") dst = os.path.normpath(dst) if not os.path.exists(dst): @@ -340,11 +344,16 @@ def make_root(variant, destination_root): for exe, command in console_scripts.items(): write_console_script(dst, exe, command, shim == "binary") - variant = next(package.iter_variants()) - variant_ = variant.install(path) + if as_bundle: + root = path + variant_ = None + else: + variant = next(package.iter_variants()) + variant_ = variant.install(path) + + root = variant_.root - root = variant_.root - if make_root and root: + if root: try: os.makedirs(root) except OSError as e: @@ -356,7 +365,7 @@ def make_root(variant, destination_root): with retain_cwd(): os.chdir(root) - make_root(variant_, root) + _deploy(root) return variant_