Skip to content
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
6 changes: 4 additions & 2 deletions src/pickley/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,16 @@ def resolve(self, settings: "TrackedSettings"):
venv.logger = self.logger
venv.create_venv()
bake_time = runez.to_int(CFG.get_value("bake_time", package_name=canonical_name))
env = None
if bake_time:
# uv allows to exclude newer packages, but pip does not
# This can fail if project is new (bake time did not elapse yet since project release)
LOG.debug("Applying bake_time of %s", runez.represented_duration(bake_time))
ago = time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime(time.time() - bake_time))
os.environ["UV_EXCLUDE_NEWER"] = ago
env = dict(os.environ)
env["UV_EXCLUDE_NEWER"] = ago

r = venv.pip_install(pip_spec, no_deps=True, quiet=True, fatal=False)
r = venv.pip_install(pip_spec, no_deps=True, quiet=True, fatal=False, env=env)
if r.failed:
lines = r.full_output.strip().splitlines()
if lines:
Expand Down
10 changes: 6 additions & 4 deletions src/pickley/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def create_venv(self):
def create_venv_with_uv(self):
uv_path = CFG.uv_bootstrap.uv_path
seed = "--seed" if self.settings.uv_seed else None
r = runez.run(uv_path, "-q", "venv", seed, "-p", self.settings.python_executable, self.folder, logger=self.logger)
env = dict(os.environ)
env.pop("UV_VENV_SEED", None) # We explicitly state `--seed` if/when needed
r = runez.run(uv_path, "-q", "venv", seed, "-p", self.settings.python_executable, self.folder, logger=self.logger, env=env)
if self.groom_uv_venv:
venv_python = self.folder / "bin/python"
if venv_python.is_symlink():
Expand All @@ -74,7 +76,7 @@ def create_venv_with_pip(self):
runez.run(self.settings.python_executable, "-mvenv", self.folder, logger=self.logger)
return self._run_py_pip("install", "-U", *bstrap.pip_auto_upgrade())

def pip_install(self, *args, fatal=True, no_deps=False, quiet=None):
def pip_install(self, *args, fatal=True, no_deps=False, quiet=None, env=None):
"""`pip install` into target venv`"""
cmd = list(self._auto_quiet_args("install", no_deps and "--no-deps", quiet=quiet))
if quiet is True:
Expand All @@ -84,9 +86,9 @@ def pip_install(self, *args, fatal=True, no_deps=False, quiet=None):
passthrough = quiet is False or "-q" not in cmd

if self.use_pip:
return self._run_py_pip(*cmd, *args, fatal=fatal, passthrough=passthrough)
return self._run_py_pip(*cmd, *args, fatal=fatal, passthrough=passthrough, env=env)
Copy link

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that _run_py_pip (and similarly _run_uv on line 91) can handle the additional 'env' parameter; update their signatures if needed to ensure consistency.

Copilot uses AI. Check for mistakes.

return self._run_uv(*cmd, *args, fatal=fatal, passthrough=passthrough)
return self._run_uv(*cmd, *args, fatal=fatal, passthrough=passthrough, env=env)

def run_pip(self, command, *args, **kwargs):
"""Run `pip` command, this only works for commands that are common between `pip` and `uv`"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import runez


def test_describe(cli):
def test_describe(cli, monkeypatch):
monkeypatch.setenv("UV_VENV_SEED", "1")
cli.run("describe pickley==1.0")
assert cli.succeeded
assert "pickley: version 1.0 (pinned)\n" in cli.logged.stdout
Expand Down
Loading