From bc4c18483060ea8c0df9f8dda2e8b823d6296a73 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 11:48:06 +0100 Subject: [PATCH 01/13] Added lib and pyvenv.cfg + cleaned up the file a bit --- .gitignore | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 02972dfd..619d9a60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,4 @@ -# From https://github.com/github/gitignore/blob/master/Python.gitignore - -# Pyc/pyo files. *.py[co] - -# Packages *.egg *.egg-info dist @@ -11,26 +6,12 @@ build eggs parts bin +lib +pyvenv.cfg var sdist develop-eggs .installed.cfg - -# Installer logs pip-log.txt - -# Unit test / coverage reports .coverage .tox -nosetests.xml - -#Translations -# *.mo -# ^^^ No, django needs the .mo files as it doesn't compile them on the fly. - -#Mr Developer -.mr.developer.cfg - -# Ignore generated apache config files -etc/*.apache.conf -htmlcov/ From 6671d6123a5173fc979771c4e837062200bbd91e Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 11:48:30 +0100 Subject: [PATCH 02/13] Using ourselves as dev install + added pip-tools as dev install --- requirements.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.in b/requirements.in index 386f7289..1f73dd82 100644 --- a/requirements.in +++ b/requirements.in @@ -1,7 +1,7 @@ -stdlib-list -cached-property -toml +# Ourselves, including our dependencies +-e file:.#z3c.dependencychecker[test] +# Development tools black codespell coveralls @@ -17,6 +17,7 @@ flake8-quotes flake8-todo importlib-metadata; python_version < '3.8' isort +pip-tools pytest pytest-cov pyupgrade From 2a9c6ea1148c039742b5ddf9963a6ce022449bdd Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 11:50:24 +0100 Subject: [PATCH 03/13] Re-ran pip-compile Note: some 3.7 dependencies aren't pinned now as I don't have a 3.7 python anymore. Homebrew doesn't want to install it on my arm64 mac. I don't think it can hurt, but it might need a re-running with 3.7. --- requirements.txt | 52 +++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/requirements.txt b/requirements.txt index b29d8c95..bfe029a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,29 @@ # -# This file is autogenerated by pip-compile with python 3.7 +# This file is autogenerated by pip-compile with python 3.8 # To update, run: # # pip-compile requirements.in # +-e file:.#z3c.dependencychecker + # via -r requirements.in attrs==22.1.0 # via # flake8-bugbear # pytest black==22.10.0 # via -r requirements.in +build==0.9.0 + # via pip-tools cached-property==1.5.2 - # via -r requirements.in + # via z3c-dependencychecker certifi==2022.9.24 # via requests charset-normalizer==2.1.1 # via requests click==8.1.3 - # via black + # via + # black + # pip-tools codespell==2.2.2 # via -r requirements.in coverage[toml]==6.5.0 @@ -62,14 +68,6 @@ flake8-todo==0.7 # via -r requirements.in idna==3.4 # via requests -importlib-metadata==4.2.0 ; python_version < "3.8" - # via - # -r requirements.in - # click - # flake8 - # flake8-comprehensions - # pluggy - # pytest iniconfig==1.1.1 # via pytest isort==5.10.1 @@ -81,9 +79,15 @@ mccabe==0.7.0 mypy-extensions==0.4.3 # via black packaging==21.3 - # via pytest + # via + # build + # pytest pathspec==0.10.1 # via black +pep517==0.13.0 + # via build +pip-tools==6.10.0 + # via -r requirements.in platformdirs==2.5.2 # via black pluggy==1.0.0 @@ -101,6 +105,7 @@ pytest==7.2.0 # via # -r requirements.in # pytest-cov + # z3c-dependencychecker pytest-cov==4.0.0 # via -r requirements.in pyupgrade==3.1.0 @@ -108,27 +113,24 @@ pyupgrade==3.1.0 requests==2.28.1 # via coveralls stdlib-list==0.8.0 - # via -r requirements.in + # via z3c-dependencychecker tokenize-rt==5.0.0 # via pyupgrade toml==0.10.2 - # via -r requirements.in + # via z3c-dependencychecker tomli==2.0.1 # via # black + # build # coverage # pytest -typed-ast==1.5.4 ; python_version < "3.8" - # via - # -r requirements.in - # black typing-extensions==4.4.0 - # via - # black - # importlib-metadata + # via black urllib3==1.26.12 # via requests -zipp==3.10.0 ; python_version < "3.8" - # via - # -r requirements.in - # importlib-metadata +wheel==0.38.4 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools From fb1c9d9c579af1fb34c0637c2ebf3ca80e2acf96 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 11:59:16 +0100 Subject: [PATCH 04/13] Added pytest configuration --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index 56ee5c20..4203c5cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,6 +5,9 @@ extra-message = [ci skip] [isort] profile = black +[tool:pytest] +addopts = --cov --cache-clear z3c/ + [flake8] ignore = E501, # black takes care of line length W503, # black takes care of where to break lines From b47dc678bcc60d0043b80fa529c288d3d6e507a0 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 12:00:27 +0100 Subject: [PATCH 05/13] Documenting local development --- README.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.rst b/README.rst index c4585d9c..a4e0e67c 100644 --- a/README.rst +++ b/README.rst @@ -123,3 +123,21 @@ requests in the github issue tracker. Every time you commit something, ``bin/code-analysis`` is automatically run. Pay attention to the output and fix the problems that are reported. Or fix the setup so that inappropriate reports are filtered out. + + +Local development setup +----------------------- + +Create a virtualenv and install the requirements:: + + $ python3 -m venv . + $ bin/pip install -r requirements.txt + +If you changed the actual requirements in ``setup.py`` or the development +requirements in ``requirements.in``, re-generate ``requirements.txt``:: + + $ bin/pip-compile requirements.in + +To run the tests (there's some pytest configuration in ``setup.cfg``):: + + $ bin/pytest From 2bb46503bf7bc9d8d07eab3440dc144b638d0b59 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:00:01 +0100 Subject: [PATCH 06/13] Fixed osx-only test error --- z3c/dependencychecker/tests/test_main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/z3c/dependencychecker/tests/test_main.py b/z3c/dependencychecker/tests/test_main.py index eaeca06b..9730a699 100644 --- a/z3c/dependencychecker/tests/test_main.py +++ b/z3c/dependencychecker/tests/test_main.py @@ -1,4 +1,5 @@ import logging +import os import sys import tempfile from unittest import mock @@ -71,7 +72,10 @@ def test_get_path_no_path_given(): with change_dir(folder): path = get_path(arguments) - assert path == folder + # realpath() below is used to work around a small mac tempdir naming + # issue. /var/folders/xyz is the tempdir, but after cd'ing you're in + # /private/var/folders/xyz... + assert os.path.realpath(path) == os.path.realpath(folder) def test_get_path_path_given(): From f0e3b8307869d861ab11b85c72e534d7cbab5361 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:06:37 +0100 Subject: [PATCH 07/13] self-install isn't needed anymore, we're using our own requirements --- .github/workflows/testing.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c5a3653d..ea013be4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -30,8 +30,6 @@ jobs: run: pip --version - name: Install dependencies run: python -m pip install -r requirements.txt - - name: Install itself - run: python -m pip install -e . # formatters - name: Run pyupgrade if: matrix.python-version == '3.9' From d3c1f8a71e8b6551250c540fac116d2a0ec78c9c Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:07:03 +0100 Subject: [PATCH 08/13] Pytest is configured in setup.cfg now --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ea013be4..71507dfc 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -49,6 +49,6 @@ jobs: run: flake8 setup.py z3c/ --count --max-complexity=18 --max-line-length=88 --show-source --statistics # tests and coverage - name: Test - run: pytest z3c --cov --cov-report term-missing + run: pytest - name: Coverage run: coveralls --service=github From 6e6d6e2a2b7590a217d96e43aec1d6e70d423c1b Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:07:15 +0100 Subject: [PATCH 09/13] Added the "--cov-report term-missing" from the github workflow --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 4203c5cf..97fe6906 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ extra-message = [ci skip] profile = black [tool:pytest] -addopts = --cov --cache-clear z3c/ +addopts = --cov --cov-report term-missing --cache-clear z3c/ [flake8] ignore = E501, # black takes care of line length From 6c6f9fd82fbef5e815fc6e1ec80fa49a12513572 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:16:10 +0100 Subject: [PATCH 10/13] Moved some options to setup.cfg --- .github/workflows/testing.yml | 2 +- setup.cfg | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 71507dfc..c7a30dcf 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -46,7 +46,7 @@ jobs: run: codespell *.rst setup.py z3c/ - name: Lint with flake8 if: matrix.python-version == '3.9' - run: flake8 setup.py z3c/ --count --max-complexity=18 --max-line-length=88 --show-source --statistics + run: flake8 setup.py z3c/ --count --show-source --statistics # tests and coverage - name: Test run: pytest diff --git a/setup.cfg b/setup.cfg index 97fe6906..03f90afe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,8 @@ profile = black addopts = --cov --cov-report term-missing --cache-clear z3c/ [flake8] +max-line-length = 88 +max-complexity = 18 ignore = E501, # black takes care of line length W503, # black takes care of where to break lines D202, # black takes care of blank lines From d1d4c7a9c5aea106eaefbaf94a3fc180b5a47959 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:22:37 +0100 Subject: [PATCH 11/13] Documenting the checks --- README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.rst b/README.rst index a4e0e67c..88380c7d 100644 --- a/README.rst +++ b/README.rst @@ -141,3 +141,12 @@ requirements in ``requirements.in``, re-generate ``requirements.txt``:: To run the tests (there's some pytest configuration in ``setup.cfg``):: $ bin/pytest + +Some checks that are run by github actions:: + + $ bin/black --skip-string-normalization + $ bin/codespell setup.py z3c/ + $ bin/flake8 setup.py z3c/ + +Note that the string quoting style is currently not black-standard, so you'll +have to manage it yourself. From 9b58f9e2795e2ba1580d4243c07af463366aee93 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 14:23:10 +0100 Subject: [PATCH 12/13] Updated changelog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index e88a81f0..5b9fe8d1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,10 @@ Changelog of z3c.dependencychecker - Test against python 3.7-3.9 and pypy3. [gforcada] +- Updated developer documentation. + [reinout] + + 2.7 (2018-08-08) ---------------- From 1128e6d5b9a567bff92243e427c8b00aa1163512 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Mon, 28 Nov 2022 17:30:03 +0100 Subject: [PATCH 13/13] Added test to crank up the test coverage a little bit. Not totally sure if the test is totally correct. I couldn't get the 'False' result to fire. --- .../tests/test_user_mappings.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/z3c/dependencychecker/tests/test_user_mappings.py b/z3c/dependencychecker/tests/test_user_mappings.py index 95ecaf01..9785d97f 100644 --- a/z3c/dependencychecker/tests/test_user_mappings.py +++ b/z3c/dependencychecker/tests/test_user_mappings.py @@ -132,6 +132,30 @@ def test_one_user_mapping(minimal_structure): } == mappings +def test_filter_out_mappings_on_test(minimal_structure): + path, package_name = minimal_structure + _write_user_config(path, ONE_MAPPING) + _update_requires_txt( + path, + package_name, + ['plone.reload', '[test]', 'Zope2'], + ) + package = Package(path) + package.inspect() + five_dotted_name = DottedName('Products.Five') + plone_reload_dotted_name = DottedName('plone.reload') + zope_dotted_name = DottedName('Zope2') + + assert len(package.imports.user_mappings) == 1 + assert zope_dotted_name in package.imports.user_mappings + + # The next two aren'd in the mapping, so they shouldn't be filtered out: + assert package.imports._filter_out_mappings_on_test(plone_reload_dotted_name) + assert package.imports._filter_out_mappings_on_test(five_dotted_name) + # This one is in the mapping, but shouldn't be filtered out as it is a test-only import. + assert package.imports._filter_out_mappings_on_test(zope_dotted_name) + + def test_more_user_mappings(minimal_structure): path, package_name = minimal_structure _write_user_config(path, MORE_MAPPINGS)