From 7fd308c13ad15bba6bf228d5941207b5675612e6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Mon, 13 Jan 2025 20:20:21 +0100 Subject: [PATCH] Update build system to use pyproject.toml --- .github/workflows/check.yaml | 6 ++-- .github/workflows/codecov.yaml | 5 ++- .github/workflows/publish.yaml | 6 ++-- pyproject.toml | 42 +++++++++++++++++++++++++ setup.cfg | 11 ------- setup.py | 50 ------------------------------ src/flake8_requirements/checker.py | 2 +- test/test_checker.py | 6 ++-- tox.ini | 35 +++++++++++++++++++++ 9 files changed, 87 insertions(+), 76 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py create mode 100644 tox.ini diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 36914bc..024f40f 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -22,11 +22,9 @@ jobs: with: python-version: '3.x' - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools + run: pip install tox - name: Run Tests - run: python setup.py pytest + run: tox -e py3 code-ql: strategy: diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index b165be7..820190f 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -14,9 +14,8 @@ jobs: python-version: '3.x' - name: Generate Coverage Report run: | - python -m pip install --upgrade pip - pip install coverage setuptools - coverage run --include=src/* setup.py pytest + pip install tox + tox -e coverage - name: Upload Coverage to Codecov uses: codecov/codecov-action@v5 with: diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 59d56bd..8ce1ea6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -18,10 +18,8 @@ jobs: with: python-version: '3.x' - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine + run: pip install build - name: Build - run: python setup.py bdist_wheel + run: python -m build - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a80295e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,42 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel", "build"] +build-backend = "setuptools.build_meta" + +[project] +name = "flake8-requirements" +# NOTE: Keep in sync with src/flake8_requirements/checker.py file. +version = "2.2.1" +description = "Package requirements checker, plugin for flake8" +readme = "README.rst" +authors = [ { name = "Arkadiusz Bokowy", email = "arkadiusz.bokowy@gmail.com" } ] +requires-python = ">=3.6" +classifiers = [ + "Framework :: Flake8", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Quality Assurance", +] +dependencies = [ + "flake8 >= 4.0.0", + "setuptools >= 10.0.0", + "tomli>=1.2.1; python_version < '3.11'", +] + +[project.optional-dependencies] +pyproject = ["Flake8-pyproject"] + +[project.urls] +Homepage = "https://github.com/arkq/flake8-requirements" + +[project.entry-points."flake8.extension"] +I90 = "flake8_requirements:Flake8Checker" + +[tool.doc8] +max-line-length = 99 + +[tool.isort] +force_single_line = true diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2d76c1e..0000000 --- a/setup.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[bdist_wheel] -python-tag = py3 - -[doc8] -max-line-length = 99 - -[flake8] -extend-exclude = venv - -[isort] -force_single_line = true diff --git a/setup.py b/setup.py deleted file mode 100644 index 5c33bab..0000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -import re -from os import path - -from setuptools import setup - - -def get_abs_path(pathname): - return path.join(path.dirname(__file__), pathname) - - -with open(get_abs_path("src/flake8_requirements/checker.py")) as f: - version = re.match(r'.*__version__ = "(.*?)"', f.read(), re.S).group(1) -with open(get_abs_path("README.rst")) as f: - long_description = f.read() - -setup( - name="flake8-requirements", - version=version, - author="Arkadiusz Bokowy", - author_email="arkadiusz.bokowy@gmail.com", - url="https://github.com/Arkq/flake8-requirements", - description="Package requirements checker, plugin for flake8", - long_description=long_description, - license="MIT", - package_dir={'': "src"}, - packages=["flake8_requirements"], - install_requires=[ - "flake8 >= 4.0.0", - "setuptools >= 10.0.0", - "tomli>=1.2.1; python_version < '3.11'", - ], - extras_require={"pyproject": ["Flake8-pyproject"]}, - setup_requires=["pytest-runner"], - tests_require=["mock", "pytest"], - entry_points={ - 'flake8.extension': [ - 'I90 = flake8_requirements:Flake8Checker', - ], - }, - classifiers=[ - "Framework :: Flake8", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Software Development :: Quality Assurance", - ], -) diff --git a/src/flake8_requirements/checker.py b/src/flake8_requirements/checker.py index 27587c4..92ee581 100644 --- a/src/flake8_requirements/checker.py +++ b/src/flake8_requirements/checker.py @@ -19,7 +19,7 @@ from .modules import KNOWN_3RD_PARTIES from .modules import STDLIB_PY3 -# NOTE: Changing this number will alter package version as well. +# NOTE: Keep in sync with pyproject.toml file. __version__ = "2.2.1" __license__ = "MIT" diff --git a/test/test_checker.py b/test/test_checker.py index fb7d10b..cf83324 100644 --- a/test/test_checker.py +++ b/test/test_checker.py @@ -28,9 +28,9 @@ class Flake8Checker(checker.Flake8Checker): def get_setup_py(cls): return SetupVisitorMock() - @property - def processing_setup_py(self): - return self.filename == "setup.py" + @staticmethod + def is_project_setup_py(project_root_dir, filename): + return filename == "setup.py" class Flake8OptionManagerMock(dict): diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..00304f2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,35 @@ +[tox] +envlist = + coverage + py3 +isolated_build = true + +[testenv] +description = Run the tests with pytest under {basepython}. +setenv = + COVERAGE_FILE = {toxworkdir}/.coverage.{envname} +commands = + pytest \ + --cov="{envsitepackagesdir}/flake8_requirements" \ + --cov-config="{toxinidir}/tox.ini" \ + test +deps = + pytest + pytest-cov + +[testenv:coverage] +description = Combine coverage data and create final XML report. +setenv = + COVERAGE_FILE = {toxworkdir}/.coverage +commands = + coverage combine + coverage report + coverage xml -o "{toxworkdir}/coverage.xml" +skip_install = true +deps = coverage +depends = py3 + +[coverage:paths] +source = src/flake8_requirements + */.tox/*/lib/python*/site-packages/flake8_requirements + */src/flake8_requirements