Skip to content

Commit

Permalink
Merge pull request #14 from davidlatwe/dev
Browse files Browse the repository at this point in the history
Refactor CLI, PackageLoader; Add package deploy callback
  • Loading branch information
davidlatwe authored Jun 10, 2021
2 parents 6e1d563 + 89043a0 commit 3b0de84
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 306 deletions.
2 changes: 1 addition & 1 deletion src/deliver/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

__version__ = "0.6.1"
__version__ = "0.7.0"


def package_info():
Expand Down
3 changes: 2 additions & 1 deletion src/deliver/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from deliver.repository import PackageLoader
from deliver.solve import PackageInstaller, RequestSolver
from deliver.solve import RequestSolver
from deliver.install import PackageInstaller
from deliver.exceptions import (
RezDeliverError,
RezDeliverRequestError,
Expand Down
2 changes: 1 addition & 1 deletion src/deliver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def list_developer_packages(requests=None):
def deploy_packages(requests, path, dry_run=False, yes=False):

installer = api.PackageInstaller()
installer.target(path)
installer.deploy_to(path)

installer.resolve(*requests)

Expand Down
3 changes: 1 addition & 2 deletions src/deliver/gui/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ def defer_search_packages(self, on_time=50):
timer.start(on_time)

def on_package_searched(self):
self._state["loader"].load()
self._models["pkgBook"].reset(self.iter_dev_packages())

def on_target_changed(self, path):
installer = self._state["installer"]
installer.target(path)
installer.deploy_to(path)
self._models["pkgManifest"].clear()

def on_manifested(self):
Expand Down
117 changes: 117 additions & 0 deletions src/deliver/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

import os
import sys
import argparse
import subprocess

from rez.config import config as rezconfig

from deliver.solve import RequestSolver
from deliver.lib import clear_repo_cache


class PackageInstaller(RequestSolver):
"""Extended from `RequestSolver` to execute installation"""

def run(self):
for _ in self.run_iter():
pass

def run_iter(self):
deliverconfig = rezconfig.plugins.command.deliver

for requested in self._requirements:
if requested.status != self.Ready:
# TODO: prompt warning if the status is `ResolveFailed`
continue

if requested.source == self.loader.maker_source:
self._make(requested.name,
variant=requested.index)
else:
self._build(requested.name,
os.path.dirname(requested.source),
variant=requested.index)

deliverconfig.on_package_deployed_callback(
name=requested.name,
path=self.deploy_path,
)

yield requested

def _make(self, name, variant=None):
deploy_path = self.deploy_path
if not os.path.isdir(deploy_path):
os.makedirs(deploy_path)

made_pkg = self.loader.get_maker_made_package(name)
made_pkg.__install__(deploy_path, variant)

clear_repo_cache(deploy_path)

def _build(self, name, src_dir, variant=None):
variant_cmd = [] if variant is None else ["--variants", str(variant)]
deploy_path = self.deploy_path

if not os.path.isdir(deploy_path):
os.makedirs(deploy_path)

if variant is not None:
name += "[%d]" % variant

env = os.environ.copy()
cmd = [sys.executable, "-m", "deliver.install", name]

if self._release:
env["REZ_RELEASE_PACKAGES_PATH"] = deploy_path
cmd += ["--release"]
else:
env["REZ_LOCAL_PACKAGES_PATH"] = deploy_path
cmd += ["--install"]

cmd += variant_cmd
self._run_command(cmd, cwd=src_dir, env=env)

clear_repo_cache(deploy_path)

def _run_command(self, cmd_args, **kwargs):
print("Running command:\n %s\n" % cmd_args)
subprocess.check_call(cmd_args, **kwargs)


def main():
from rez.cli._main import run
from deliver.solve import RequestSolver
from deliver.lib import override_config

parser = argparse.ArgumentParser("deliver.install")
parser.add_argument("PKG")
parser.add_argument("--release", action="store_true")
opts, remains = parser.parse_known_args()

# for case like:
#
# `tests.test_manifest.TestManifest.test_buildtime_variants`
#
# which requires to scan packages to list out current available variants,
# we resolve the request here again and append loader paths for including
# developer packages in that scan.
#
solver = RequestSolver()
solver.resolve(opts.PKG)

# build/release
#
settings = {
# developer packages loader paths appended, see comment above.
"packages_path": solver.installed_packages_path + solver.loader.paths,
}
with override_config(settings):
command = "release" if opts.release else "build"
sys.argv = ["rez-" + command] + remains
run(command)


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion src/deliver/maker/rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def find_python_package_versions(release):
versions = set()

loader = PackageLoader()
loader.load(name=python)

paths = rezconfig.nonlocal_packages_path[:] if release \
else rezconfig.packages_path[:]
Expand Down
Loading

0 comments on commit 3b0de84

Please sign in to comment.