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

Bundle installation mode #36

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "pipz"
version = "1.2.2"
version = "1.3.0"
requires = ["bleeding_rez-2.29+", "python>=2,<4"]

tools = [
Expand Down
32 changes: 27 additions & 5 deletions python/pipz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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" % (
Expand Down Expand Up @@ -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
Expand All @@ -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)))
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
25 changes: 17 additions & 8 deletions python/pipz/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -356,7 +365,7 @@ def make_root(variant, destination_root):

with retain_cwd():
os.chdir(root)
make_root(variant_, root)
_deploy(root)

return variant_

Expand Down