From 22d82ef31c24d4d1a12ed6ec6514df860d53daa2 Mon Sep 17 00:00:00 2001 From: Alif Be <11570927+alifbe@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:20:33 +0100 Subject: [PATCH] Replace setup.py with pyproject.toml (#420) --- .flake8 | 5 ++ .github/workflows/pyscal.yml | 8 ++- .pre-commit-config.yaml | 34 ----------- bandit.yml | 1 - ci/testkomodo.sh | 2 +- mypy.ini | 23 ------- pyproject.toml | 113 +++++++++++++++++++++++++++++++++++ pyscal/utils/string.py | 5 +- setup.cfg | 29 --------- setup.py | 65 -------------------- test_requirements.txt | 15 ----- 11 files changed, 125 insertions(+), 175 deletions(-) create mode 100644 .flake8 delete mode 100644 .pre-commit-config.yaml delete mode 100644 bandit.yml delete mode 100644 mypy.ini create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 test_requirements.txt diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..a56b478e --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +exclude = docs, pyscal/__init__.py, pyscal/version.py +max-line-length = 88 +ignore = E741, W503, E203 +# E203: "whitespace before ':'", added due to conflict with black diff --git a/.github/workflows/pyscal.yml b/.github/workflows/pyscal.yml index 3d3f85eb..9aded5c9 100644 --- a/.github/workflows/pyscal.yml +++ b/.github/workflows/pyscal.yml @@ -50,7 +50,7 @@ jobs: if: ${{ always() }} run: | pip install --upgrade pip - pip install .[tests] + pip install .[tests,docs] - name: List all installed packages if: ${{ always() }} @@ -59,7 +59,7 @@ jobs: - name: Lint with black if: ${{ always() }} run: | - black --check --force-exclude="pyscal/version.py" pyscal/*py tests/test_*py setup.py docs/conf.py + black --check --force-exclude="pyscal/version.py" pyscal tests docs - name: Lint with flake8 if: ${{ always() }} @@ -77,11 +77,13 @@ jobs: mypy pyscal - name: Run tests + if: ${{ always() }} run: | python -c "import pyscal" - pytest --strict-markers --hypothesis-profile ci tests/ + pytest -n auto --strict-markers --hypothesis-profile ci tests/ - name: Syntax check documentation + if: ${{ always() }} run: | rstcheck -r docs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index a7b5a1ef..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,34 +0,0 @@ -repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 - hooks: - - id: no-commit-to-branch - args: ['--branch', 'master'] - - id: check-yaml - - id: debug-statements - - id: end-of-file-fixer - - id: fix-encoding-pragma - args: [--remove] - - id: mixed-line-ending - - id: trailing-whitespace - -- repo: https://github.com/ambv/black - rev: 22.3.0 - hooks: - - id: black - -- repo: https://gitlab.com/pycqa/flake8.git - rev: 4.0.1 - hooks: - - id: flake8 - -- repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.960' # Use the sha / tag you want to point at - hooks: - - id: mypy - -- repo: https://github.com/pycqa/isort - rev: 5.10.1 - hooks: - - id: isort - name: isort diff --git a/bandit.yml b/bandit.yml deleted file mode 100644 index d233ed69..00000000 --- a/bandit.yml +++ /dev/null @@ -1 +0,0 @@ -skips: ['B101', 'B311'] diff --git a/ci/testkomodo.sh b/ci/testkomodo.sh index 4e14a9fb..8af1c6fb 100644 --- a/ci/testkomodo.sh +++ b/ci/testkomodo.sh @@ -1,5 +1,5 @@ install_test_dependencies () { - pip install -r test_requirements.txt + pip install ".[tests]" } start_tests () { diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 9eb7fe2f..00000000 --- a/mypy.ini +++ /dev/null @@ -1,23 +0,0 @@ -[mypy] - -[mypy-numpy.*] -# Applies to Python 3.6: -ignore_missing_imports = True - -[mypy-pyscal.version] -ignore_missing_imports = True - -[mypy-pandas.*] -ignore_missing_imports = True - -[mypy-matplotlib.*] -ignore_missing_imports = True - -[mypy-scipy.*] -ignore_missing_imports = True - -[mypy-xlrd.*] -ignore_missing_imports = True - -[mypy-openpyxl.*] -ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..8b473efd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,113 @@ +[build-system] + +requires = [ + "setuptools>=45.0", + "setuptools_scm[toml]>=6.2", +] + +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["pyscal"] + +[tool.setuptools_scm] +write_to = "pyscal/version.py" + +[project] +name = "pyscal" +description = "Generate relative permeability include files for Eclipse reservoir simulator" +readme = "README.md" +requires-python = ">=3.8" +license = { file = "LICENSE" } +authors = [ + { name = "Håvard Berland", email = "havb@equinor.com" }, +] +keywords = ["relative permeability", "capillary pressure", "reservoir simulation"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research/Developers", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Software Development :: Libraries", + "Topic :: Utilities", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Natural Language :: English", + "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", +] +dynamic = ["version"] + +dependencies = [ + "matplotlib", + "numpy<2", + "openpyxl", + "pandas", + "scipy", + "urllib3<2", + "xlrd", +] + +[project.optional-dependencies] +tests = [ + "black", + "flake8", + "hypothesis", + "isort", + "mypy", + "pytest", + "pytest-cov", + "pytest-mock", + "pytest-xdist", + "rstcheck", +] + +docs = [ + "autoapi", + "sphinx<7", + "sphinx-argparse", + "sphinx-autodoc-typehints", + "sphinx_rtd_theme", +] + +[project.urls] +Homepage = "https://github.com/equinor/pyscal" +Documentation = "https://equinor.github.io/pyscal/" +Repository = "https://github.com/equinor/pyscal" + +[project.scripts] +pyscal = "pyscal.pyscalcli:main" + +[tool.black] +line-length = 88 + +[tool.isort] +profile = "black" +skip = "pyscal/__init__.py" + +[[tool.mypy.overrides]] +module = ["numpy.*", "pyscal.version", "pandas.*", "matplotlib.*", "scipy.*", "xlrd.*", "openpyxl.*" +] +ignore_missing_imports = true + +[tool.pylint] +# Module docstrings are not required, there are other means of documenting at +# that level in subscript +disable = "missing-module-docstring" + +[tool.pytest.ini_options] +norecursedirs = [ + ".git", +] +xfail_strict = "True" + +addopts = "-ra --strict-markers --ignore=docs/conf.py --ignore=.eggs" + +markers = [ + "integration: marks a test as an integration test", + "plot: marks a test as interactive, plots will flash to the screen", + "slow: a test that is expected to take up to a second or so to execute", +] + +[tool.rstcheck] +ignore_directives = ["argparse", "automodule"] diff --git a/pyscal/utils/string.py b/pyscal/utils/string.py index 0b608327..7b0b3436 100644 --- a/pyscal/utils/string.py +++ b/pyscal/utils/string.py @@ -48,10 +48,7 @@ def df2str( dframe = modify_dframe_monotonicity(dframe, monotonicity, digits) return dframe.round(roundlevel).to_csv( - sep=" ", - float_format=float_format, - header=header, - index=False + sep=" ", float_format=float_format, header=header, index=False ) diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 6b09e7e7..00000000 --- a/setup.cfg +++ /dev/null @@ -1,29 +0,0 @@ -[bdist_wheel] -universal = 1 - -[aliases] -test=pytest - -[flake8] -exclude = docs, pyscal/__init__.py, pyscal/version.py -max-line-length = 88 -ignore = E741, W503, E203 -# E203: "whitespace before ':'", added due to conflict with black - -[tool:pytest] -markers = - integration: marks a test as an integration test - plot: marks a test as interactive, plots will flash to the screen - slow: a test that is expected to take up to a second or so to execute -xfail_strict=True - -[build_sphinx] -all-files = 1 -warning-is-error = 1 - -[rstcheck] -ignore_directives=argparse,automodule - -[isort] -profile=black -skip=pyscal/__init__.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 35c0d1da..00000000 --- a/setup.py +++ /dev/null @@ -1,65 +0,0 @@ -from pathlib import Path - -from setuptools import find_packages, setup - -try: - from sphinx.setup_command import BuildDoc - - cmdclass = {"build_sphinx": BuildDoc} -except ImportError: - # sphinx not installed - do not provide build_sphinx cmd - cmdclass = {} - -# Read the contents of README.md, for PyPI -LONG_DESCRIPTION = (Path(__file__).parent / "README.md").read_text() - -REQUIREMENTS = [ - "matplotlib", - "numpy<2", - "openpyxl", - "pandas", - "scipy", - "xlrd", -] - -TEST_REQUIREMENTS = Path("test_requirements.txt").read_text().splitlines() - -SETUP_REQUIREMENTS = ["pytest-runner", "setuptools >=28", "setuptools_scm"] -EXTRAS_REQUIRE = {"tests": TEST_REQUIREMENTS} - -setup( - name="pyscal", - use_scm_version={"write_to": "pyscal/version.py"}, - cmdclass=cmdclass, - description=( - "Generate relative permeability include files for " - "Eclipse reservoir simulator" - ), - entry_points={"console_scripts": ["pyscal = pyscal.pyscalcli:main"]}, - long_description=LONG_DESCRIPTION, - long_description_content_type="text/markdown", - url="http://github.com/equinor/pyscal", - author="Håvard Berland", - author_email="havb@equinor.com", - license="LGPLv3", - keywords="relative permeability, capillary pressure, reservoir simulation", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - ( - "License :: OSI Approved :: " - "GNU Lesser General Public License v3 or later (LGPLv3+)" - ), - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - ], - packages=find_packages(), - package_data={"pyscal": ["py.typed"]}, - zip_safe=False, - test_suite="tests", - install_requires=REQUIREMENTS, - setup_requires=SETUP_REQUIREMENTS, - extras_require=EXTRAS_REQUIRE, -) diff --git a/test_requirements.txt b/test_requirements.txt deleted file mode 100644 index 5287659c..00000000 --- a/test_requirements.txt +++ /dev/null @@ -1,15 +0,0 @@ -autoapi -black -flake8 -hypothesis -isort -mypy -pre-commit -pytest -pytest-cov -pytest-mock -rstcheck -sphinx<7 -sphinx-argparse -sphinx-autodoc-typehints -sphinx_rtd_theme