Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry show <package> now also shows which packages depend on it #2351

Merged
merged 6 commits into from
Sep 19, 2021
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
5 changes: 4 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,13 @@ name : pendulum
version : 1.4.2
description : Python datetimes made easy

dependencies:
dependencies
- python-dateutil >=2.6.1
- tzlocal >=1.4
- pytzdata >=2017.2.2

required by
- calendar >=1.4.0
```

### Options
Expand Down
15 changes: 15 additions & 0 deletions poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ def handle(self) -> Optional[int]:

return 0

required_by = {}
for locked in locked_packages:
dependencies = {d.name: d.pretty_constraint for d in locked.requires}

if pkg.name in dependencies:
required_by[locked.pretty_name] = dependencies[pkg.name]

rows = [
["<info>name</>", " : <c1>{}</>".format(pkg.pretty_name)],
["<info>version</>", " : <b>{}</b>".format(pkg.pretty_version)],
Expand All @@ -199,6 +206,14 @@ def handle(self) -> Optional[int]:
)
)

if required_by:
self.line("")
self.line("<info>required by</info>")
for parent, requires_version in required_by.items():
self.line(
" - <c1>{}</c1> <b>{}</b>".format(parent, requires_version)
)

return 0

show_latest = self.option("latest")
Expand Down
75 changes: 75 additions & 0 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,3 +1419,78 @@ def test_show_tree_no_dev(tester, poetry, installed):
"""

assert expected == tester.io.fetch_output()


def test_show_required_by_deps(tester, poetry, installed):
poetry.package.add_dependency(Factory.create_dependency("cachy", "^0.2.0"))
poetry.package.add_dependency(Factory.create_dependency("pendulum", "2.0.0"))

cachy2 = get_package("cachy", "0.2.0")
cachy2.add_dependency(Factory.create_dependency("msgpack-python", ">=0.5 <0.6"))

pendulum = get_package("pendulum", "2.0.0")
pendulum.add_dependency(Factory.create_dependency("CachY", "^0.2.0"))

installed.add_package(cachy2)
installed.add_package(pendulum)

poetry.locker.mock_lock_data(
{
"package": [
{
"name": "cachy",
"version": "0.2.0",
"description": "",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
"dependencies": {"msgpack-python": ">=0.5 <0.6"},
},
{
"name": "pendulum",
"version": "2.0.0",
"description": "Pendulum package",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
"dependencies": {"cachy": ">=0.2.0 <0.3.0"},
},
{
"name": "msgpack-python",
"version": "0.5.1",
"description": "",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"hashes": {"cachy": [], "pendulum": [], "msgpack-python": []},
},
}
)

tester.execute("cachy")

expected = """\
name : cachy
version : 0.2.0
description :

dependencies
- msgpack-python >=0.5 <0.6

required by
- pendulum >=0.2.0 <0.3.0
""".splitlines()
actual = [line.rstrip() for line in tester.io.fetch_output().splitlines()]
assert actual == expected