def deploy(distribution, target): """Convert `distribution` into Rez package at `target`""" name = distribution.name maker = PackageMaker(name) maker.version = distribution.version maker.requires = distribution.requirements maker.url = distribution.url maker.description = distribution.description maker.variants = distribution.variants commands = set() for relpath, alias, args in distribution.binaries(): # Temporarily expose app dir to PATH # TODO: Implement Scoop's "shims" for this purpose # Reason they aren't implemented at the moment is # because shims carry an absolute path to their # executable, which we can't put into a package as # packages may come from differently mounted paths # or network locations at any given time. dirname = os.path.dirname(relpath).replace("\\", "/") commands.add("env.PATH.prepend(r'{root}/app/%s')" % dirname) maker.commands = "\n".join(commands) package = maker.get_package() variant = next(package.iter_variants()) root = variant.install(target).root appdir = os.path.join(root, "app") bindir = os.path.join(root, "bin") try: os.makedirs(root) os.makedirs(bindir) except OSError as e: if e.errno == errno.EEXIST: # That's ok pass else: raise shutil.copytree(distribution.root, appdir) # NOTE: Currently unused, see note above for relpath, alias, args in distribution.binaries(): fname = os.path.basename(relpath) name, ext = os.path.splitext(fname) args = " ".join(args) bat = os.path.join(bindir, (alias or name) + ".bat") with open(bat, "w") as f: f.write("\n".join([ "@echo off", "call %~dp0../app/{relpath} {args} %*".format(**locals()) ]))
def convert(distribution, variants=None, dumb=False): """Make a Rez package out of `distribution` Arguments: distribution (distlib.database.InstalledDistribution): Source variants (list, optional): Explicitly provide variants, defaults to automatically detecting the correct variants using the WHEEL metadata of `distribution`. """ # determine variant requirements variants_ = variants or [] if not variants_: WHEEL = os.path.join(distribution.egg_info, "WHEEL") with open(WHEEL) as f: variants_.extend(wheel_to_variants(f.read())) requirements = _pip_to_rez_requirements(distribution) maker = PackageMaker(_rez_name(distribution.project_name), package_cls=DeveloperPackage) maker.version = distribution.version if requirements: maker.requires = requirements if variants_: maker.variants = [variants_] maker.commands = '\n'.join([ "env.PATH.prepend('{root}/bin')", "env.PYTHONPATH.prepend('{root}/python')" ]) package = maker.get_package() data = maker._get_data() data["pipz"] = True # breadcrumb for preprocessing # preprocessing result = package._get_preprocessed(data) if result: package, data = result # Store reference for deployment distribution.dumb = dumb _package_to_distribution[package] = distribution return package
def deploy(distribution, target): """Convert `distribution` into Rez package at `target`""" name = distribution.name maker = PackageMaker(name) maker.version = distribution.version maker.requires = distribution.requirements maker.url = distribution.url maker.description = distribution.description maker.variants = distribution.variants commands = set() for relpath, alias, args in distribution.binaries(): # Temporarily expose app dir to PATH # TODO: Implement Scoop's "shims" for this purpose # Reason they aren't implemented at the moment is # because shims carry an absolute path to their # executable, which we can't put into a package as # packages may come from differently mounted paths # or network locations at any given time. dirname = os.path.dirname(relpath).replace("\\", "/") commands.add("env.PATH.prepend(r'{root}/app/%s')" % dirname) # Handle PATH environment variables # NOTE: This presumes all environment variables are paths, # and that they branch out from the app/ directory. There may(?) # be variables that aren't paths too for key, value in distribution.envs(): commands.add("env.%s.prepend('{root}/app/%s')" % (key, value)) # Handle the odd case of no commands being present # This is probably a bad package then if not commands: print("WARNING: No commands made by this package, " "inspect it to see if it's allright") commands.add("pass") maker.commands = "\n".join(commands) package = maker.get_package() variant = next(package.iter_variants()) root = variant.install(target).root appdir = os.path.join(root, "app") bindir = os.path.join(root, "bin") try: os.makedirs(root) os.makedirs(bindir) except OSError as e: if e.errno == errno.EEXIST: # That's ok pass else: raise shutil.copytree(distribution.root, appdir) # NOTE: Currently unused, see note above for relpath, alias, args in distribution.binaries(): fname = os.path.basename(relpath) name, ext = os.path.splitext(fname) args = " ".join(args) bat = os.path.join(bindir, (alias or name) + ".bat") with open(bat, "w") as f: f.write("\n".join([ "@echo off", "call %~dp0../app/{relpath} {args} %*".format(**locals()) ]))