Skip to content

Commit

Permalink
Faster recompiles via pixi update (#438)
Browse files Browse the repository at this point in the history
* drop carryover lockfile warning

* add update, rename lock -> install

* rename carryover -> update, use that as default recompile behavior

* oops update not --update

* try new recompile

* recompile the other two
  • Loading branch information
cisaacstern authored Nov 15, 2024
1 parent 3887263 commit c96e86d
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 457 deletions.
268 changes: 130 additions & 138 deletions examples/events/ecoscope-workflows-events-workflow/pixi.lock

Large diffs are not rendered by default.

268 changes: 130 additions & 138 deletions examples/patrols/ecoscope-workflows-patrols-workflow/pixi.lock

Large diffs are not rendered by default.

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ push-all = { cmd = "./publish/push.sh" }

# examples ---------------------------------------------------------------------------------

recompile-events = { cmd = "./dev/recompile.sh events --lock", depends-on = ["build-release"] }
recompile-patrols = { cmd = "./dev/recompile.sh patrols --lock", depends-on = ["build-release"] }
recompile-subject-tracking = { cmd = "./dev/recompile.sh subject-tracking --lock", depends-on = ["build-release"] }
compile-events = { cmd = "./dev/recompile.sh events --install", depends-on = ["build-release"] }
compile-patrols = { cmd = "./dev/recompile.sh patrols --install", depends-on = ["build-release"] }
compile-subject-tracking = { cmd = "./dev/recompile.sh subject-tracking --install", depends-on = ["build-release"] }
compile-all = { cmd ="echo 'compile-all' complete", depends-on = [
"compile-events",
"compile-patrols",
"compile-subject-tracking",
]}
recompile-events = { cmd = "./dev/recompile.sh events --update" }
recompile-patrols = { cmd = "./dev/recompile.sh patrols --update" }
recompile-subject-tracking = { cmd = "./dev/recompile.sh subject-tracking --update" }
recompile-all = { cmd ="echo 'recompile-all' complete", depends-on = [
"recompile-events",
"recompile-patrols",
"recompile-subject-tracking",
]}
recompile-events-carryover-lockfile = { cmd = "./dev/recompile.sh events --no-lock --carryover-lockfile" }
recompile-patrols-carryover-lockfile = { cmd = "./dev/recompile.sh patrols --no-lock --carryover-lockfile" }
recompile-subject-tracking-carryover-lockfile = { cmd = "./dev/recompile.sh subject-tracking --no-lock --carryover-lockfile" }
recompile-all-carryover-lockfile = { cmd ="echo 'recompile-all-carryover-lockfile' complete", depends-on = [
"recompile-events-carryover-lockfile",
"recompile-patrols-carryover-lockfile",
"recompile-subject-tracking-carryover-lockfile",
]}


pytest-events-params = { cmd = "./dev/pytest-examples-params.sh events" }
pytest-patrols-params = { cmd = "./dev/pytest-examples-params.sh patrols" }
Expand Down
38 changes: 15 additions & 23 deletions src/ecoscope-workflows-core/ecoscope_workflows_core/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from io import TextIOWrapper

import click
Expand All @@ -8,11 +7,6 @@

yaml = ruamel.yaml.YAML(typ="safe")

CARRYOVER_LOCKFILE_WARNING = (
"Warning: it is much safer to always re-lock the package, as the lockfile may be out of "
"date or otherwise incorrect. This option is given as a convenience for development purposes."
)


@click.command()
@click.option(
Expand All @@ -28,42 +22,40 @@
help="Whether or not to clobber an existing build directory.",
)
@click.option(
"--lock/--no-lock",
"--install/--no-install",
is_flag=True,
default=True,
help="Whether or not to generate a pixi lockfile for the package.",
default=False,
help="Whether or not to generate a new pixi lockfile for the package and install all dependencies.",
)
@click.option(
"--carryover-lockfile/--no-carryover-lockfile",
"--update/--no-update",
is_flag=True,
default=False,
help=(
"In the case of combining the options `--clobber` + `--no-lock`, whether or not to "
"carryover the lockfile from the clobbered directory. If true, this option allows for "
"rebuilding the package with a (potentially!) functional lockfile, without paying the "
"cost of actually re-locking the package. " + CARRYOVER_LOCKFILE_WARNING
"carryover the lockfile from the clobbered directory and updating it."
),
)
def compile(
spec: TextIOWrapper,
clobber: bool,
lock: bool,
carryover_lockfile: bool,
install: bool,
update: bool,
):
if carryover_lockfile and not (clobber and not lock):
if update and not (clobber and not install):
raise ValueError(
"The `--carryover-lockfile` option is only valid when used in conjunction with "
"both `--clobber` option and `--no-lock` option."
"The `--update` option is only valid when used in conjunction with "
"both `--clobber` option and `--no-install` option."
)
if carryover_lockfile:
warnings.warn(CARRYOVER_LOCKFILE_WARNING)
spec_text = spec.read()
compilation_spec = Spec(**yaml.load(spec_text))
dc = DagCompiler(spec=compilation_spec)
wa = dc.generate_artifacts(spec_relpath=spec.name)
wa.dump(clobber=clobber, carryover_lockfile=carryover_lockfile)
if lock:
wa.lock()
wa.dump(clobber=clobber, update=update)
if install:
wa.install()
elif update:
wa.update()


@click.group()
Expand Down
19 changes: 11 additions & 8 deletions src/ecoscope-workflows-core/ecoscope_workflows_core/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,23 @@ def release_dir(self) -> Path:
Path().cwd().joinpath(self.spec_relpath).parent.joinpath(self.release_name)
)

def lock(self):
def install(self):
subprocess.run(
f"pixi install -a --manifest-path {self.release_dir.joinpath('pixi.toml')}".split()
)

def dump(self, clobber: bool = False, carryover_lockfile: bool = False):
def update(self):
subprocess.run(
f"pixi update --manifest-path {self.release_dir.joinpath('pixi.toml')}".split()
)

def dump(self, clobber: bool = False, update: bool = False):
"""Dump the artifacts to disk.
Args:
clobber (bool, optional): Whether or not to clobber an existing build directory. Defaults to False.
carryover_lockfile (bool, optional): In the case of combining the options `--clobber` + `--no-lock`,
whether or not to carryover the lockfile from the clobbered directory. If true, this option
allows for rebuilding the package with a (potentially!) functional lockfile, without paying
the cost of actually re-locking the package. Defaults to False.
update (bool, optional): In the case of combining the options `--clobber` + `--no-install`,
whether or not to carryover the lockfile from the clobbered directory.
"""
if self.release_dir.exists() and not clobber:
raise FileExistsError(
Expand All @@ -189,7 +192,7 @@ def dump(self, clobber: bool = False, carryover_lockfile: bool = False):
f"Cannot clobber existing '{self.release_dir}'; not a directory."
)
if self.release_dir.exists() and clobber:
if carryover_lockfile:
if update:
lockfile = self.release_dir.joinpath("pixi.lock")
if not lockfile.exists():
raise FileNotFoundError(
Expand All @@ -203,7 +206,7 @@ def dump(self, clobber: bool = False, carryover_lockfile: bool = False):
# root artifacts
self.pixi_toml.dump(self.release_dir.joinpath("pixi.toml"))
self.pydot_graph.write_png(path=self.release_dir.joinpath("graph.png"))
if carryover_lockfile:
if update:
self.release_dir.joinpath("pixi.lock").write_text(original_lockfile)
for k, v in {
"pyproject.toml": self.pyproject_toml,
Expand Down

0 comments on commit c96e86d

Please sign in to comment.