Skip to content

Commit 504e0ef

Browse files
committed
pylock: add is_direct property
1 parent 51ddd3a commit 504e0ef

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/pip/_internal/models/pylock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self":
532532
)
533533
return package
534534

535+
@property
536+
def is_direct(self) -> bool:
537+
return not (self.sdist or self.wheels)
538+
535539

536540
@dataclass(frozen=True)
537541
class Pylock:

tests/unit/test_pylock.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pip._vendor.packaging.version import Version
1010

1111
from pip._internal.models.pylock import (
12+
Package,
13+
PackageDirectory,
1214
PackageWheel,
1315
Pylock,
1416
PylockRequiredKeyError,
@@ -290,3 +292,21 @@ def test_hash_validation(hashes: Dict[str, Any], expected_error: str) -> None:
290292
hashes=hashes,
291293
)
292294
assert str(exc_info.value) == expected_error
295+
296+
297+
def test_is_direct() -> None:
298+
direct_package = Package(
299+
name="example",
300+
directory=PackageDirectory(path="."),
301+
)
302+
assert direct_package.is_direct
303+
wheel_package = Package(
304+
name="example",
305+
wheels=[
306+
PackageWheel(
307+
url="https://example.com/example-1.0-py3-none-any.whl",
308+
hashes={"sha256": "f" * 40},
309+
)
310+
],
311+
)
312+
assert not wheel_package.is_direct

0 commit comments

Comments
 (0)