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
3 changes: 3 additions & 0 deletions src/pickley/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def _locked_by(self):
if not runez.check_pid(pid):
return None # PID is no longer active

if pid is not None:
return "-no args-" # Holder is alive, but was invoked without CLI args (so there's no 2nd line)

def __enter__(self):
"""Acquire lock"""
if self.lock_path:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def test_describe(cli, monkeypatch):
runez.write(".pk/config.json", '{"bake_time": 300, "pinned": {"cowsay": {"python": "3.999"}}}', logger=None)
cli.run("-vv describe mgit==1.3.0")
assert cli.succeeded
assert " -vv describe " in cli.logged.stdout
assert "pip show mgit" in cli.logged.stdout
assert " -vv describe " in cli.logged
assert "pip show mgit" in cli.logged
assert "mgit: version 1.3.0" in cli.logged.stdout
assert "Applying bake_time of 5 minutes" in cli.logged.stdout
assert "Applying bake_time of 5 minutes" in cli.logged

cli.run("-vv describe cowsay")
assert cli.failed
Expand Down
19 changes: 11 additions & 8 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_base(cli, monkeypatch):

cli.run("-n base foo")
assert cli.failed
assert "Can't find 'foo', try:" in cli.logged.stdout
assert "Can't find 'foo', try:" in cli.logged

monkeypatch.delenv("PICKLEY_ROOT")
assert find_base("/foo/.venv/bin/pickley") == CFG.resolved_path("/foo/.venv/dev_mode")
Expand Down Expand Up @@ -365,13 +365,16 @@ def test_lock(temp_cfg, monkeypatch):
with pytest.raises(SystemExit):
runez.abort("oops")

with SoftLock("foo", give_up=600) as lock:
assert str(lock) == "lock foo"
assert os.path.exists(lock_path)
with pytest.raises(SoftLockException, match="giving up"):
# Try to grab same lock a seconds time, give up after 1 second
with SoftLock("foo", give_up=1, invalid=600):
raise AssertionError("should not be reached") # pragma: no cover
# Lock holder is reported with the CLI args it was invoked with (if any)
for argv, holder in ((["pickley", "install", "foo"], "install foo"), (["pickley"], "-no args-")):
monkeypatch.setattr(sys, "argv", argv)
with SoftLock("foo", give_up=600) as lock:
assert str(lock) == "lock foo"
assert os.path.exists(lock_path)
with pytest.raises(SoftLockException, match=f"giving up\nIt is being held by: pickley .*{holder}"):
# Try to grab same lock a seconds time, give up after 1 second
with SoftLock("foo", give_up=1, invalid=600):
raise AssertionError("should not be reached") # pragma: no cover

assert not os.path.exists(lock_path) # Check that lock was released

Expand Down
Loading