From 52e9e373442a0f5b226702858db2eebd8eff176a Mon Sep 17 00:00:00 2001 From: Bryn Lloyd Date: Thu, 19 Sep 2024 13:45:44 +0200 Subject: [PATCH] Modernize (#151) * Move metadata from setup.py to pyproject.toml * Extract package version dynamically from nrrd.__version__ * Upgrade pre-commit hooks * Replace flake8 hook by https://github.com/PyCQA/flake8, which is "standard" (running the old hook was asking me for a gitlab password) * Add typos hook (only found one typo, but doesn't cost much to run it) --------- Co-authored-by: Bryn Lloyd <12702862+dyollb@users.noreply.github.com> Co-authored-by: Addison Elliott --- .github/workflows/lint.yml | 2 +- .gitignore | 3 +++ .pre-commit-config.yaml | 15 ++++++++----- nrrd/tests/test_writing.py | 2 +- pyproject.toml | 39 ++++++++++++++++++++++++++++++++ setup.cfg | 6 ----- setup.py | 46 +++----------------------------------- 7 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4121b1..f44eed6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v3 with: - python-version: 3.7 + python-version: 3.9 - name: Install Python dependencies run: pip install pre-commit diff --git a/.gitignore b/.gitignore index dd6df2b..d140e7a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ docs/build/ # coverage.py files .coverage + +# Virtual environments +.venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c96b9b5..e51e504 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,24 +2,29 @@ exclude: "docs" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/asottile/pyupgrade - rev: v2.34.0 + rev: v3.17.0 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/timothycrosley/isort - rev: 5.10.1 + rev: 5.13.2 hooks: - id: isort - - repo: https://gitlab.com/pycqa/flake8 - rev: 5.0.4 + - repo: https://github.com/PyCQA/flake8 + rev: 7.1.1 hooks: - id: flake8 args: ["--config=setup.cfg"] + + - repo: https://github.com/crate-ci/typos + rev: v1.24.5 + hooks: + - id: typos diff --git a/nrrd/tests/test_writing.py b/nrrd/tests/test_writing.py index 03a29f2..9b3e842 100644 --- a/nrrd/tests/test_writing.py +++ b/nrrd/tests/test_writing.py @@ -329,7 +329,7 @@ def test_quoted_string_list_header(self): # Strip newline from end of line lines = [line.rstrip() for line in lines] - # Note the order of the lines dont matter, we just want to verify theyre outputted correctly + # Note the order of the lines dont matter, we just want to verify they are outputted correctly self.assertTrue('units: "mm" "cm" "in"' in lines) self.assertTrue('space units: "mm" "cm" "in"' in lines) self.assertTrue('labels: "X" "Y" "f(log(X, 10), Y)"' in lines) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..318f3eb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "pynrrd" +dynamic = ["version"] +description = "Pure python module for reading and writing NRRD files." +readme = { file = "README.txt", content-type = "text/x-rst" } +requires-python = ">=3.7" +license = { text = "MIT License" } +authors = [{ name = "Maarten Everts", email = "me@nn8.nl" }] +keywords = ["nrrd", "teem", "image", "processing", "file", "format"] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Topic :: Scientific/Engineering", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] + +dependencies = ["numpy >=1.11.1", "nptyping", "typing_extensions"] + +[project.optional-dependencies] +dev = ["build", "pre-commit", "pytest"] + +[project.urls] +Homepage = "https://github.com/mhe/pynrrd" +Documentation = "https://pynrrd.readthedocs.io/en/stable" +Tracker = "https://github.com/mhe/pynrrd/issues" + +[tool.setuptools.dynamic] +version = { attr = "nrrd._version.__version__" } + +[tool.setuptools.packages] +find = { exclude = ["*.tests", "*.tests.*", "tests.*", "tests"] } diff --git a/setup.cfg b/setup.cfg index a2c7e81..d2210e4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,3 @@ -[bdist_wheel] -# This flag says that the code is written to work on both Python 2 and Python -# 3. If at all possible, it is good practice to do this. If you cannot, you -# will need to generate wheels for each Python version that you support. -universal=1 - [flake8] max-line-length = 120 ignore = diff --git a/setup.py b/setup.py index a0cb24a..7f1a176 100644 --- a/setup.py +++ b/setup.py @@ -1,44 +1,4 @@ -import os +from setuptools import setup -from setuptools import find_packages, setup - -currentPath = os.path.abspath(os.path.dirname(__file__)) - -# Get __version__ from _version.py -__version__ = None -with open(os.path.join(currentPath, 'nrrd/_version.py')) as fh: - exec(fh.read()) - -# Get the long description from the README file -with open(os.path.join(currentPath, 'README.rst')) as fh: - longDescription = fh.read() - -longDescription = '\n' + longDescription - -setup(name='pynrrd', - python_requires='>=3.7', - version=__version__, - description='Pure python module for reading and writing NRRD files.', - long_description=longDescription, - long_description_content_type='text/x-rst', - author='Maarten Everts', - author_email='me@nn8.nl', - url='https://github.com/mhe/pynrrd', - license='MIT License', - install_requires=['numpy>=1.11.1', 'nptyping', 'typing_extensions'], - packages=find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']), - keywords='nrrd teem image processing file format', - classifiers=[ - 'License :: OSI Approved :: MIT License', - 'Topic :: Scientific/Engineering', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - ], - project_urls={ - 'Tracker': 'https://github.com/mhe/pynrrd/issues', - } - ) +if __name__ == "__main__": + setup()