From 9ada618d0dcb5c8e4e102b9b0ad786329691f363 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Thu, 16 May 2024 18:00:39 +0200 Subject: [PATCH] migrate from `setup.cfg` to `pyproject.toml` (#118) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * switch to `pyproject.tom` * use `build` command in pipeline as well * fix `pytest.ini` * fix `.coveragerc` * fix `isort.cfg` * fix `.flake8` * run pre-commit * use `build` command in release-pipeline as well * fix release-pipeline dependencies * release-pipline:: fix sed inserting wrong string * increment version after release * add email of author Miguel Ángel García * release-pipline:: fix double equals sign beeing inserted --------- Co-authored-by: Jan Wille Co-authored-by: Cube707 --- .coveragerc | 2 + .flake8 | 13 +++++ .github/workflows/publish.yaml | 12 ++--- .github/workflows/run-tests.yaml | 4 +- .isort.cfg | 4 ++ .pre-commit-config.yaml | 7 --- .pytest.ini | 3 ++ Makefile | 2 +- pyproject.toml | 43 +++++++++++++++++ readchar/__init__.py | 7 ++- requirements.txt | 3 +- setup.cfg | 81 -------------------------------- setup.py | 10 ---- 13 files changed, 81 insertions(+), 110 deletions(-) create mode 100644 .coveragerc create mode 100644 .flake8 create mode 100644 .isort.cfg create mode 100644 .pytest.ini create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..c712d25 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = tests/* diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..feb0f84 --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +max-complexity = 12 +max-line-length = 88 +exclude = + __pycache__/ + .git/ + .venv/ + .pytest_cache/ +show-source = true +statistics = true +count = true +per-file-ignores = + readchar/*_key.py:F403,F405 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 95e3d8f..4932ed4 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -35,7 +35,7 @@ jobs: cache: pip - name: Install dependencies run: | - pip install setuptools wheel twine + pip install build twine - name: get infos from Tag run: | echo "RELEASE_TAG=${RELEASE_TAG}" @@ -55,12 +55,12 @@ jobs: with: script: core.setFailed('Invalid Tag name used with this release!') - - name: Write Version to __init__ + - name: Write Version to pyproject.toml run: | - sed -i "s/__version__ = .*/__version__ = '$VERSION'/" readchar/__init__.py + sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml - name: Build sdist and bdist_wheel run: | - python setup.py sdist bdist_wheel + python -m build - name: publish to PyPi env: TWINE_USERNAME: __token__ @@ -72,12 +72,12 @@ jobs: if: ${{ env.VERSION_DEV }} run: | v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1)) - sed -i "s/__version__ = .*/__version__ = \"$v\"/" readchar/__init__.py + sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - name: increment patch version if: ${{ !env.VERSION_DEV }} run: | v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0 - sed -i "s/__version__ = .*/__version__ = \"$v\"/" readchar/__init__.py + sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - name: commit new version-number uses: stefanzweifel/git-auto-commit-action@v4 with: diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 86d0598..cd12034 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -42,9 +42,9 @@ jobs: python-version: '3.x' cache: pip - run: | - pip install setuptools wheel + pip install build - run: | - python setup.py sdist bdist_wheel + python -m build pytest: runs-on: ${{ matrix.os }} diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..5def95d --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,4 @@ +[settings] +profile = black +src_paths = readchar,tests +lines_after_imports = 2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7dcef56..0535190 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,13 +30,6 @@ repos: - name: check python syntax id: flake8 - - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.5.0 - hooks: - - name: format setup.cfg - id: setup-cfg-fmt - args: [--include-version-classifiers] - - repo: https://github.com/executablebooks/mdformat rev: 0.7.16 hooks: diff --git a/.pytest.ini b/.pytest.ini new file mode 100644 index 0000000..f43c620 --- /dev/null +++ b/.pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = tests +addopts = -r fEsxwX -s --cov=readchar diff --git a/Makefile b/Makefile index b964dd0..77e8a58 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,4 @@ pre-commit precommit: @pre-commit run -a build pack readchar: - @python setup.py sdist bdist_wheel + @python -m build diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4624d13 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "readchar" +version = "4.1.0-dev3" +requires-python = ">= 3.8" +dependencies = [] +authors = [ + { name = "Miguel Ángel García", email="miguelangel.garcia@gmail.com" }, + { name = "Jan Wille", email = "mail@janwille.de" }, +] +maintainers = [{ name = "Jan Wille", email = "mail@janwille.de" }] +keywords = ["characters", "keystrokes", "stdin", "command line"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: MIT License", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", + "Environment :: Console", + "Intended Audience :: Developers", + "Topic :: Software Development", + "Topic :: Software Development :: User Interfaces", +] +description = "Library to easily read single chars and key strokes" +readme = { file = "README.md", content-type = "text/markdown" } +license = { file = "LICENCE" } + +[project.urls] +Homepage = "https://pypi.org/project/readchar" +#Documentation = "https://readthedocs.org" +Repository = "https://github.com/magmax/python-readchar" +Issues = "https://github.com/magmax/python-readchar/issues" +Changelog = "https://github.com/magmax/python-readchar/releases" diff --git a/readchar/__init__.py b/readchar/__init__.py index f902f6e..d7d4165 100644 --- a/readchar/__init__.py +++ b/readchar/__init__.py @@ -1,6 +1,9 @@ -"""Library to easily read single chars and key strokes""" +import importlib.metadata -__version__ = "4.0.7-dev0" + +__doc__ = """Library to easily read single chars and key strokes""" + +__version__ = importlib.metadata.version(__package__) __all__ = ["readchar", "readkey", "key", "config"] from sys import platform diff --git a/requirements.txt b/requirements.txt index 19134b3..f49cc3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -e . +build pre-commit -pytest +pytest>=6.0 pytest-cov wheel diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 52295ed..0000000 --- a/setup.cfg +++ /dev/null @@ -1,81 +0,0 @@ -[metadata] -name = readchar -version = attr: readchar.__version__ -description = Library to easily read single chars and key strokes -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/magmax/python-readchar -author_email = miguelangel.garcia@gmail.com -license = MIT -license_files = LICENCE -classifiers = - Development Status :: 5 - Production/Stable - Environment :: Console - Intended Audience :: Developers - License :: OSI Approved :: MIT License - Operating System :: Microsoft :: Windows - Operating System :: POSIX :: Linux - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Programming Language :: Python :: Implementation :: CPython - Topic :: Software Development - Topic :: Software Development :: User Interfaces -keywords = - characters - keystrokes - stdin - command line -project_urls = - Download = https://pypi.org/project/readchar/#files - Bug Tracker = https://github.com/magmax/python-readchar/issues - Source Code = https://github.com/magmax/python-readchar - -[options] -packages = find: -install_requires = - setuptools>=41.0 -python_requires = >=3.8 -include_package_data = True -zip_safe = false - -[options.packages.find] -exclude = - .git/ - .github/ - .venv/ - tests/ - -[options.package_data] -readchar = - py.typed - -[tool:pytest] -testpaths = tests -addopts = -r fEsxwX -s --cov=readchar - -[flake8] -max-complexity = 12 -max-line-length = 88 -exclude = - __pycache__/ - .git/ - .venv/ - .pytest_cache/ -show-source = true -statistics = true -count = true -per-file-ignores = - readchar/*_key.py:F403,F405 - -[tool.coverage.run] -omit = tests/* - -[isort] -profile = black -src_paths = readchar,tests -lines_after_imports = 2 diff --git a/setup.py b/setup.py deleted file mode 100644 index 64becd1..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from setuptools import setup - - -setup( - # The following is only here to make GitHubs dependency detection happy: - name="readchar", - # Author can not be read from setup.cfg as it causes encoding problems during - # windows installs - author="Miguel Ángel García", -)