Skip to content

Commit

Permalink
Merge branch 'release-0.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
sinoroc committed Jan 13, 2020
2 parents 216ea33 + 140a657 commit 94100d6
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 54 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

.. Keep the current version number on line number 5
0.0.8
=====

2020-01-13

* Add '--flat' display option


0.0.7
=====

2019-11-13

* Fix issue with unknown project in reverse


Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ check:

.PHONY: lint
lint:
python3 -m pytest --codestyle --pylint -m 'codestyle or pylint'
python3 -m pytest --pycodestyle --pylint -m 'pycodestyle or pylint'


.PHONY: pycodestyle
pycodestyle:
python3 -m pytest --codestyle -m codestyle
python3 -m pytest --pycodestyle -m pycodestyle


.PHONY: pylint
Expand All @@ -65,7 +65,7 @@ pytest:

.PHONY: review
review: check
python3 -m pytest --codestyle --pylint
python3 -m pytest --pycodestyle --pylint


.PHONY: clean
Expand Down
63 changes: 32 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ Features

* Show dependencies or dependents

* Detects circular dependencies
* Detect circular dependencies

* Detects missing dependencies
* Detect missing dependencies


Usage
=====

.. code::
usage: deptree [-h] [--version] [-r] [project [project ...]]
usage: deptree [-h] [--version] [-r] [-f] [project [project ...]]
positional arguments:
project name of project whose dependencies (or dependents) to show
Expand All @@ -38,44 +38,43 @@ Usage
-h, --help show this help message and exit
--version show program's version number and exit
-r, --reverse show dependent projects instead of dependencies
-f, --flat show flat list instead of tree
Examples
--------

.. code::
$ deptree twine
twine==2.0.0 # twine
pkginfo==1.5.0.1 # pkginfo>=1.4.2
readme-renderer==24.0 # readme-renderer>=21.0
bleach==3.1.0 # bleach>=2.1.0
six==1.13.0 # six>=1.9.0
webencodings==0.5.1 # webencodings
docutils==0.15.2 # docutils>=0.13.1
Pygments==2.4.2 # Pygments
six==1.13.0 # six
requests==2.22.0 # requests>=2.20
certifi==2019.9.11 # certifi>=2017.4.17
chardet==3.0.4 # chardet<3.1.0,>=3.0.2
idna==2.8 # idna<2.9,>=2.5
urllib3==1.25.7 # urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
requests-toolbelt==0.9.1 # requests-toolbelt!=0.9.0,>=0.8.0
requests==2.22.0 # requests<3.0.0,>=2.0.1
certifi==2019.9.11 # certifi>=2017.4.17
chardet==3.0.4 # chardet<3.1.0,>=3.0.2
idna==2.8 # idna<2.9,>=2.5
urllib3==1.25.7 # urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
setuptools==39.0.1 # setuptools>=0.7.0
tqdm==4.38.0 # tqdm>=4.14
$ deptree cryptography
cryptography==2.8 # cryptography
cffi==1.13.2 # cffi!=1.11.3,>=1.8
pycparser==2.19 # pycparser
six==1.13.0 # six>=1.4.1
.. code::
$ deptree --reverse cryptography
cryptography==2.8 #
SecretStorage==3.1.1 # cryptography
keyring==21.0.0 # secretstorage; sys_platform == "linux"
twine==3.1.1 # keyring>=15.1
.. code::
$ deptree --flat cryptography
cryptography==2.8
# cffi!=1.11.3,>=1.8
# six>=1.4.1
.. code::
$ deptree -r requests
requests==2.22.0 #
requests-toolbelt==0.9.1 # requests<3.0.0,>=2.0.1
twine==2.0.0 # requests-toolbelt!=0.9.0,>=0.8.0
twine==2.0.0 # requests>=2.20
$ deptree --flat --reverse cryptography
# secretstorage cryptography
cryptography==2.8
Repositories
Expand All @@ -100,6 +99,7 @@ Details
Similar projects
----------------

* `johnnydep`_
* `pipdeptree`_


Expand Down Expand Up @@ -150,6 +150,7 @@ Outside of a Python virtual environment run the following command::
.. Links
.. _`GNU Make`: https://www.gnu.org/software/make/
.. _`johnnydep`: https://pypi.org/project/johnnydep/
.. _`pipdeptree`: https://pypi.org/project/pipdeptree/
.. _`pytest`: https://pytest.org/
.. _`tox`: https://tox.readthedocs.io/
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ url = https://pypi.org/project/deptree/

[options]
install_requires =
importlib_metadata
importlib-metadata
setuptools
package_dir =
= src
Expand Down
72 changes: 60 additions & 12 deletions src/deptree/_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def _display_missing(requirement, depth):
)


def _display_forward(project_req):
return _display_forward_one(project_req, [])
def _display_forward_tree(project_req):
_display_forward_branch(project_req, [])


def _display_forward_one(project_req, chain):
def _display_forward_branch(project_req, chain):
depth = len(chain)
project_key = project_req.key
if project_key in chain:
Expand All @@ -84,17 +84,17 @@ def _display_forward_one(project_req, chain):
print(unknown_extra_exception)
else:
for dependency_req in dependency_reqs:
_display_forward_one(
_display_forward_branch(
dependency_req,
chain + [distribution.key],
)


def _display_reverse(distributions, project_requirement):
return _display_reverse_one(distributions, project_requirement, None, [])
def _display_reverse_tree(distributions, project_requirement):
_display_reverse_branch(distributions, project_requirement, None, [])


def _display_reverse_one(distributions, project_req, dependency_req, chain):
def _display_reverse_branch(distributions, project_req, dependency_req, chain):
depth = len(chain)
project_key = project_req.key
if project_key in chain:
Expand All @@ -110,14 +110,49 @@ def _display_reverse_one(distributions, project_req, dependency_req, chain):
dependents = distributions[project_key]['dependents'].items()
for (dependent_key, next_dependency_req) in sorted(dependents):
dependent_req = pkg_resources.Requirement.parse(dependent_key)
_display_reverse_one(
_display_reverse_branch(
distributions,
dependent_req,
next_dependency_req,
chain + [project_key],
)


def _display_forward_flat(project_requirement):
project_key = project_requirement.key
try:
distribution = pkg_resources.get_distribution(project_key)
except pkg_resources.DistributionNotFound:
print("{} # !!! MISSING")
else:
print("{}=={}".format(distribution.project_name, distribution.version))
try:
dependency_requirements = sorted(
distribution.requires(extras=project_requirement.extras),
key=lambda req: req.key,
)
except pkg_resources.UnknownExtra as unknown_extra_exception:
print(unknown_extra_exception)
else:
for dependency_requirement in dependency_requirements:
print("# {}".format(dependency_requirement))
print("")


def _display_reverse_flat(distributions, project_requirement):
project_key = project_requirement.key
try:
distribution = pkg_resources.get_distribution(project_key)
except pkg_resources.DistributionNotFound:
print("{} # !!! MISSING")
else:
dependents = distributions[project_key]['dependents'].items()
for (dependent_key, dependent_req) in sorted(dependents):
print("# {} {}".format(dependent_key, dependent_req))
print("{}=={}".format(distribution.project_name, distribution.version))
print("")


def _discover_distributions():
distributions = {}
working_set = pkg_resources.working_set
Expand All @@ -144,6 +179,11 @@ def _discover_distributions():
return distributions


def _select_all(distributions):
selection = sorted(distributions.keys())
return selection


def _select_top_level(distributions):
selection = [
key
Expand All @@ -168,24 +208,32 @@ def _select_bottom_level(distributions):
return selection


def main(selection, reverse):
def main(selection, reverse, flat):
""" Main function """
distributions = None
if reverse or not selection:
distributions = _discover_distributions()

if not selection:
if reverse:
if flat:
selection = _select_all(distributions)
elif reverse:
selection = _select_bottom_level(distributions)
else:
selection = _select_top_level(distributions)

for item in selection:
requirement = pkg_resources.Requirement.parse(item)
if reverse:
_display_reverse(distributions, requirement)
if flat:
_display_reverse_flat(distributions, requirement)
else:
_display_reverse_tree(distributions, requirement)
else:
_display_forward(requirement)
if flat:
_display_forward_flat(requirement)
else:
_display_forward_tree(requirement)


# EOF
25 changes: 18 additions & 7 deletions src/deptree/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,34 @@
def main():
""" CLI main function
"""
parser = argparse.ArgumentParser(
args_parser = argparse.ArgumentParser(
allow_abbrev=False,
)
parser.add_argument('--version', action='version', version=_meta.VERSION)
parser.add_argument(
'-r', '--reverse',
args_parser.add_argument(
'--version',
action='version',
version=_meta.VERSION,
)
args_parser.add_argument(
'-r',
'--reverse',
action='store_true',
help=_("show dependent projects instead of dependencies"),
)
parser.add_argument(
args_parser.add_argument(
'-f',
'--flat',
action='store_true',
help=_("show flat list instead of tree"),
)
args_parser.add_argument(
'selected_projects',
help=_("name of project whose dependencies (or dependents) to show"),
metavar='project',
nargs='*',
)
args = parser.parse_args()
_pkg_resources.main(args.selected_projects, args.reverse)
args = args_parser.parse_args()
_pkg_resources.main(args.selected_projects, args.reverse, args.flat)


# EOF

0 comments on commit 94100d6

Please sign in to comment.