From 163140c2170bacd9befbda04961f58bb2897aab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sat, 3 Sep 2022 09:35:00 -0700 Subject: [PATCH] Move to hatch with VCS version tracking and src layout, requires 3.7+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- .gitignore | 11 +--- MANIFEST.in | 1 - Makefile | 38 ------------- README.rst | 2 +- pyproject.toml | 62 ++++++++++++++++++++- pytest.ini | 14 ----- setup.py | 53 ------------------ pipdeptree.py => src/pipdeptree/__init__.py | 34 +++++------ src/pipdeptree/__main__.py | 6 ++ tox.ini | 28 ++++++---- 10 files changed, 99 insertions(+), 150 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 Makefile delete mode 100644 pytest.ini delete mode 100644 setup.py rename pipdeptree.py => src/pipdeptree/__init__.py (98%) create mode 100644 src/pipdeptree/__main__.py diff --git a/.gitignore b/.gitignore index 9bf295c..50c46c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,6 @@ *.pyc -__pycache__ -*~ -*.egg-info/ -build/ +*.egg-info dist/ .tox/ +/src/pipdeptree/version.py tests/virtualenvs/equimapper/ -.coverage -coverage.xml -htmlcov/ -.cache/ -.pytest_cache/ \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 26b0dd0..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include LICENSE CHANGES.md \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 2de3f5f..0000000 --- a/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -.PHONY: clean test-env test test-cov test-tox-all test-e2e - -TOX_ENV ?= py36 - -E2E_PYTHON_EXE ?= python3.6 - -clean: - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rmdir {} + - -test-env: - pip install -r dev-requirements.txt - -test: - tox -e $(TOX_ENV) - -test-cov: - tox -e $(TOX_ENV) -- -x -vv --cov=pipdeptree --cov-report=xml --cov-report=html --cov-report=term-missing - -# Requires all the versions of python executables to be present (See -# tox.ini for list of python versions) -test-tox-all: - tox - -clean-e2e: - rm -rf tests/profiles/*/.env_$(E2E_PYTHON_EXE)* - -test-e2e: clean-e2e - cd tests && ./e2e-tests webapp - cd tests && ./e2e-tests conflicting - cd tests && ./e2e-tests cyclic - -test-e2e-quick: - cd tests && ./e2e-tests webapp - cd tests && ./e2e-tests conflicting - cd tests && ./e2e-tests cyclic diff --git a/README.rst b/README.rst index 8c93b73..dfede04 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,7 @@ requires some effort. It's also tedious to resolve conflicting dependencies that could have been installed because older version of ``pip`` didn't have true dependency resolution [1]_. ``pipdeptree`` can help here by identifying conflicting dependencies installed in the -environment. +environment.R To some extent, ``pipdeptree`` is inspired by the ``lein deps :tree`` command of `Leiningen `_. diff --git a/pyproject.toml b/pyproject.toml index 885b10d..f064dc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,61 @@ [build-system] -requires = ["setuptools>=65.1.1"] -build-backend = "setuptools.build_meta" +build-backend = "hatchling.build" +requires = ["hatchling>=1.8.1", "hatch-vcs>=0.2"] + +[project] +name = "pipdeptree" +description = 'Command line utility to show dependency tree of packages.' +readme = "README.rst" +license.file = "LICENSE" +maintainers = [ + { name = "Bernát Gábor", email = "gaborjbernat@gmail.com" }, + { name = "Vineet Naik", email = "naikvin@gmail.com" }, +] +urls.Documentation = "https://github.com/tox-dev/pipdeptree/blob/main/README.rst#pipdeptree" +urls.Homepage = "https://github.com/tox-dev/pipdeptree" +urls.Source = "https://github.com/tox-dev/pipdeptree" +urls.Tracker = "https://github.com/tox-dev/pipdeptree/issues" +requires-python = ">=3.7" +optional-dependencies.test = [ + "covdefaults>=2.2", + "diff-cover>=6.5.1", + "pip>=22.2.2", + "pytest>=7.1.3", + "pytest-cov>=3", + "pytest-mock>=3.8.2", + "virtualenv<21,>=20.16.4", +] +optional-dependencies.graphviz = [ + "graphviz>=0.20.1", +] +scripts.pipdeptree = "pipdeptree:main" +keywords = ["application", "cache", "directory", "log", "user"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", +] +dynamic = ["version"] + +[tool.hatch] +build.hooks.vcs.version-file = "src/pipdeptree/version.py" +version.source = "vcs" + +[tool.black] +line-length = 120 + +[tool.isort] +profile = "black" +known_first_party = ["pipdeptree"] + +[tool.coverage] +html.show_contexts = true +html.skip_covered = false +paths.source = ["src", ".tox/*/lib/python*/site-packages", "*/src"] +run.parallel = true +run.plugins = ["covdefaults"] diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index c76dee9..0000000 --- a/pytest.ini +++ /dev/null @@ -1,14 +0,0 @@ -[pytest] -norecursedirs = build docs/_build *.egg .tox *.venv profiles -addopts = - # --verbose - --tb=short - # Turn on --capture to have brief, less noisy output - # You will only see output if the test fails - # Use --capture no if you want to see it all or have problems debugging - # --capture=fd - # --capture=no - # show extra test summary info as specified by chars (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed. - -rfEsxX - # --junitxml=junit.xml - # --cov=pipdeptree --cov-report=xml --cov-report=html --cov-report=term-missing diff --git a/setup.py b/setup.py deleted file mode 100644 index b93b754..0000000 --- a/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -import re -import ast - -from setuptools import setup - - -_version_re = re.compile(r'__version__\s+=\s+(.*)') - -with open('pipdeptree.py', 'rb') as f: - version = str(ast.literal_eval(_version_re.search( - f.read().decode('utf-8')).group(1))) - - -with open('./README.rst') as f: - long_desc = f.read() - - -install_requires = ["pip >= 6.0.0"] - - -setup( - name='pipdeptree', - version=version, - author='Vineet Naik', - author_email='naikvin@gmail.com', - url='https://github.com/naiquevin/pipdeptree', - license='MIT License', - license_file='LICENSE', - description='Command line utility to show dependency tree of packages', - long_description=long_desc, - install_requires=install_requires, - extras_require={'graphviz': ['graphviz']}, - python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*', - py_modules=['pipdeptree'], - entry_points={ - 'console_scripts': [ - 'pipdeptree = pipdeptree:main' - ] - }, - classifiers=[ - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9' - ] -) diff --git a/pipdeptree.py b/src/pipdeptree/__init__.py similarity index 98% rename from pipdeptree.py rename to src/pipdeptree/__init__.py index 6e2c3b3..5f3d6ce 100644 --- a/pipdeptree.py +++ b/src/pipdeptree/__init__.py @@ -1,6 +1,7 @@ from __future__ import print_function import os import inspect +import shutil import sys import subprocess from itertools import chain @@ -9,7 +10,7 @@ import argparse import json from importlib import import_module import tempfile - +from .version import version as __version__ try: from collections import OrderedDict except ImportError: @@ -30,9 +31,6 @@ except ImportError: # from graphviz import parameters -__version__ = '2.2.1' - - flatten = chain.from_iterable @@ -829,19 +827,17 @@ def handle_non_host_target(args): del argv[py_at] elif value.startswith("--python"): del argv[py_at] - # feed the file as argument, instead of file - # to avoid adding the file path to sys.path, that can affect result - file_path = inspect.getsourcefile(sys.modules[__name__]) - with open(file_path, 'rt') as file_handler: - content = file_handler.read() - cmd = [of_python, "-c", content] - cmd.extend(argv) - # invoke from an empty folder to avoid cwd altering sys.path - cwd = tempfile.mkdtemp() - try: - return subprocess.call(cmd, cwd=cwd) - finally: - os.removedirs(cwd) + + main_file = inspect.getsourcefile(sys.modules[__name__]) + with tempfile.TemporaryDirectory() as project: + dest = os.path.join(project, 'pipdeptree') + shutil.copytree(os.path.dirname(main_file), dest) + # invoke from an empty folder to avoid cwd altering sys.path + env = os.environ.copy() + env['PYTHONPATH'] = project + cmd = [of_python, '-m', 'pipdeptree'] + cmd.extend(argv) + return subprocess.call(cmd, cwd=project, env=env) return None @@ -922,7 +918,3 @@ def main(): render_text(tree, args.all, args.freeze) return return_code - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/src/pipdeptree/__main__.py b/src/pipdeptree/__main__.py new file mode 100644 index 0000000..85cca3c --- /dev/null +++ b/src/pipdeptree/__main__.py @@ -0,0 +1,6 @@ +import sys + +from pipdeptree import main + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tox.ini b/tox.ini index 5cddad5..bdf5bb5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [tox] envlist = - fix py310 py39 py38 @@ -11,17 +10,24 @@ skip_missing_interpreters = true minversion = 3.14 [testenv] -description = run test suite under {basepython} -commands = - pytest {posargs:-vv} -deps = - graphviz>=0.20.1 - pip>=22.2.2 - pytest>=7.1.3 - pytest-cov>=3 - virtualenv<21,>=20.16.4 +description = run the unit tests with pytest under {basepython} +setenv = + COVERAGE_FILE = {toxworkdir}/.coverage.{envname} + COVERAGE_PROCESS_START = {toxinidir}/setup.cfg + _COVERAGE_SRC = {envsitepackagesdir}/sphinx_argparse_cli extras = - graphviz + graphviz + test +commands = + python -m pytest {tty:--color=yes} {posargs: \ + --junitxml {toxworkdir}{/}junit.{envname}.xml --cov {envsitepackagesdir}{/}pipdeptree \ + --cov {toxinidir}{/}tests --cov-fail-under=75 \ + --cov-config=pyproject.toml --no-cov-on-fail --cov-report term-missing:skip-covered --cov-context=test \ + --cov-report html:{envtmpdir}{/}htmlcov --cov-report xml:{toxworkdir}{/}coverage.{envname}.xml \ + tests} + diff-cover --compare-branch {env:DIFF_AGAINST:origin/main} {toxworkdir}{/}coverage.{envname}.xml +package = wheel +wheel_build_env = .pkg [testenv:readme] description = check that the long description is valid