diff --git a/.github/workflows/process.yml b/.github/workflows/process.yml index 97e8785560..f509069a83 100644 --- a/.github/workflows/process.yml +++ b/.github/workflows/process.yml @@ -21,8 +21,7 @@ jobs: - name: Install PROCESS # Editable install to match default install run: | - pip install -e '.[test, examples]' - pip install -r requirements_dev.txt + pip install -e '.[test]' - name: Run unit tests run: | pytest --cov=process tests/unit -v \ @@ -45,7 +44,6 @@ jobs: # Editable install to match default install run: | pip install -e '.[test]' - pip install -r requirements_dev.txt - name: Install poppler run: | sudo apt update @@ -64,7 +62,6 @@ jobs: # Editable install to match default install run: | pip install -e '.[test, examples]' - pip install -r requirements_dev.txt - name: Install poppler run: | sudo apt update @@ -92,7 +89,6 @@ jobs: # Editable install to match default install run: | pip install -e '.[test]' - pip install -r requirements_dev.txt - name: Allow git commands to be run run: git config --global --add safe.directory '*' - name: Run regression tests @@ -107,9 +103,7 @@ jobs: with: python-version: '3.10' - name: Install PROCESS - run: pip install -e . - - name: Install dev dependencies - run: pip install -r requirements_dev.txt + run: pip install -e '.[lint, docs, test]' - name: Run regression input files run: python tracking/run_tracking_inputs.py run tests/regression/input_files - name: Move other files @@ -133,7 +127,7 @@ jobs: with: python-version: '3.10' - name: Install dev dependencies - run: pip install -r requirements_dev.txt + run: pip install '.[lint]' - name: Run pre-commit run: pre-commit run --all-files @@ -152,9 +146,7 @@ jobs: with: python-version: '3.10' - name: Install PROCESS - run: pip install -e . - - name: Install dev dependencies - run: pip install -r requirements_dev.txt + run: pip install -e '.[test, docs, lint]' - name: Setup SSH identity uses: webfactory/ssh-agent@v0.7.0 with: @@ -205,9 +197,7 @@ jobs: with: python-version: '3.10' - name: Install PROCESS - run: pip install -e . - - name: Install dev dependencies - run: pip install -r requirements_dev.txt + run: pip install -e '.[test, lint, docs]' - run: python scripts/vardes.py - run: git config --global --add safe.directory '*' - name: Download STF_TF.json files diff --git a/.gitignore b/.gitignore index 51e6de487d..fcb3136114 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ env-fork !tests/integration/data/large_tokamak_SIG_TF.json *.html !documentation/**/*.html +process/_version.py diff --git a/documentation/development/pre-commit.md b/documentation/development/pre-commit.md index 9a5d78d3f0..bb677bc027 100755 --- a/documentation/development/pre-commit.md +++ b/documentation/development/pre-commit.md @@ -43,7 +43,7 @@ pre-commit -h If pre-commit is not installed, then it can be installed by running: ```bash -pip install -r requirements_dev.txt +pip install '.[lint]' ``` in your environment, which will install all development dependencies including pre-commit. diff --git a/documentation/development/testing.md b/documentation/development/testing.md index 056287eb93..9eb2a91f8e 100644 --- a/documentation/development/testing.md +++ b/documentation/development/testing.md @@ -98,7 +98,7 @@ For a guide on contributing code to PROCESS, see `CONTRIBUTING.md`. Running the entire test suite can be time consuming, as by default it runs on a single core. `pytest-xdist` allows `pytest` tests to be distributed across multiple cores to speed up testing. -`pytest-xdist` should be installed already (included in `requirements.txt`), but if not it can be installed manually with: +`pytest-xdist` should be installed already (included in `test` extras; `pip install ".[test]"`), but if not it can be installed manually with: ```bash pip install pytest-xdist diff --git a/process/data_structure/__init__.py b/process/data_structure/__init__.py index 034764b200..b84550ac61 100644 --- a/process/data_structure/__init__.py +++ b/process/data_structure/__init__.py @@ -1,4 +1,4 @@ -from . import ( +from process.data_structure import ( blanket_library, build_variables, buildings_variables, diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..a492082fce --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,220 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[tool.hatch.version] +source = "vcs" +fallback-version = "0.0.0" + +[tool.hatch.build.hooks.vcs] +version-file = "process/_version.py" + +[project] +name = "process" +authors = [{ name = "UKAEA" }] +description = "Power Reactor Optimisation Code for Environmental and Safety Studies" +readme = "README.md" +requires-python = ">=3.10" +license = "MIT" +dynamic = ["version"] +dependencies = [ + "numpy>=1.23", + "scipy>=1.10", + "cvxpy~=1.7.3", + "osqp>=1.0", + "pandas>=2.0", + "numba>=0.57", + "PyVMCON>=2.4.0,<2.5.0", + "CoolProp>=6.4", + "matplotlib>=2.1.1", + "seaborn>=0.12.2", + "tabulate", + ] +keywords = ['fusion', 'optimisation'] +classifiers = [ + "Programming Language :: Python", + "Development Status :: 4 - Beta", + "Natural Language :: English", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Scientific/Engineering :: Physics", +] + +[project.urls] +Homepage = "https://www.ukaea.org/service/process/" +Source = "https://github.com/ukaea/process" +Documentation = "https://ukaea.github.io/PROCESS" +Issues = "https://github.com/ukaea/process/issues" + +[project.optional-dependencies] +test = [ + "pytest>=5.4.1", + "requests>=2.30", + "testbook>=0.4", + "pytest-cov>=3.0.0", + "pytest-xdist>=2.5.0" +] +examples = ["jupyter==1.0.0"] +plotly = ["plotly>=5.15.0,<6"] +docs = [ + "mkdocs>=1.1", + "mkdocs-material>=4.6.3", + "mkdocs-git-revision-date-localized-plugin >= 1.2", + "mkdocs-glightbox >= 0.3.4", + "pymdown-extensions>=6.3", + "bokeh>=3.4.0,<4", + "mkdocstrings==0.18.0", + "Jinja2>=3.0", + "mkdocs-jupyter>=0.24", +] +lint = ["pre-commit>=2.16.0", "ruff==0.9.3", "ty"] +all = ["process[test,docs,lint,examples,plotly]"] + +[project.scripts] +process = "process.main:main" + +[tool.hatch.build.targets.wheel] +artifacts = [ + "process/data/lz_non_corona_14_elements/*.dat", + "process/io/*.png" +] + +[tool.hatch.envs.default] +features = ["dev", "test", "docs", "lint"] + +[tool.hatch.envs.test] +features = ["test"] +[[tool.hatch.envs.test.matrix]] +python = ["3.10", "3.11", "3.12", "3.13"] +[tool.hatch.envs.test.scripts] +tests = "pytest {args:tests}" +tests-cov = "pytest --cov process --cov-report html:htmlcov --cov-report xml {args:tests}" +tests-cov-private = "pytest --private --cov process --cov-report html:htmlcov --cov-report xml {args:tests}" + +[tool.hatch.envs.docs] +features = ["docs"] +[tool.hatch.envs.docs.scripts] +build = "mkdocs build" +serve = "mkdocs serve" +deploy = "mkdocs gh-deploy" + +[tool.hatch.envs.lint] +detached = true # Don't inherit from default (does not download project dependencies) +dependencies = ["pre-commit", "ruff", "ty"] + +[tool.hatch.envs.lint.scripts] +fmt = ["pre-commit run --all-files --hook-stage manual"] + +[tool.coverage.report] +exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] +"omit" = ["process/_version.py"] + +[tool.pytest.ini_options] +addopts = "--strict-markers -r fEX" + +[tool.ty.terminal] +output-format = "concise" + +[tool.ruff] +target-version = "py310" +line-length = 88 +output-format = "concise" +extend-exclude = ["env", ".env"] + +[tool.ruff.format] +preview = true + +[tool.ruff.lint.per-file-ignores] +# Tests can use magic values, assertions, and relative imports +"tests/**" = ["ARG"] + +[tool.ruff.lint.isort] +known-first-party = ["process"] + +[tool.ruff.lint.flake8-tidy-imports] +ban-relative-imports = "all" + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.flake8-copyright] +notice-rgx = "(?i)# SPDX-FileCopyrightText:\\s\\d{4}(-(\\d{4}|present))*" + +[tool.ruff.lint.mccabe] +max-complexity = 12 + +[tool.ruff.lint.pylint] +# These should be made stricter +max-args = 17 +max-locals = 17 + +[tool.ruff.lint] +preview = false +extend-select = [ + "A", + "ARG", + "ASYNC", + "B", + "BLE", + "C4", + "COM", + "DTZ", + "EXE", + "F", + "FA", + "FLY", + "FURB", + "G", + "I", + "ICN", + "INT", + "ISC", + "LOG", + "N", + "NPY", + "PD", + "PERF", + "PGH", + "PIE", + "PYI", + "Q", + "RET", + "RSE", + "RUF", + "SIM", + "SLF", + "SLOT", + "T10", + "TID", + "UP", + "W", + "YTT", +] +ignore = ["COM812", "FBT", "G004", "PD901"] + +[tool.ruff.lint.pep8-naming] +ignore-names = [ + "*PROCESS*", + "*Bt*", + "*Bp*", + "*keV*", + "*MPa*", + "*H*", + "*T*", + "*D*", + "*He*", + "*Be*", + "C", + "N", + "O", + "Ne", + "Si", + "Ar", + "Fe", + "Ni", + "Kr", + "Xe", + "W", +] diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index 4864998084..0000000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,15 +0,0 @@ -# requirements_dev.txt includes the dependencies for running scripts on the CI -# e.g. documentation building and quality assurance (pre-commit). - -pre-commit>=2.16.0 -pytest-cov>=3.0.0 -pytest-xdist>=2.5.0 -mkdocs>=1.1 -mkdocs-material>=4.6.3 -mkdocs-git-revision-date-localized-plugin >= 1.2 -mkdocs-glightbox >= 0.3.4 -pymdown-extensions>=6.3 -bokeh>=3.4.0,<4 -mkdocstrings==0.18.0 -Jinja2>=3.0 -mkdocs-jupyter>=0.24 diff --git a/ruff.toml b/ruff.toml deleted file mode 100644 index 9db7a11a87..0000000000 --- a/ruff.toml +++ /dev/null @@ -1,78 +0,0 @@ -extend-exclude = ["env", ".env"] -target-version = "py310" - -[lint] -extend-select = [ - "A", - "ARG", - "ASYNC", - "B", - "BLE", - "C4", - "COM", - "DTZ", - "EXE", - "F", - "FA", - "FLY", - "FURB", - "G", - "I", - "ICN", - "INT", - "ISC", - "LOG", - "N", - "NPY", - "PD", - "PERF", - "PGH", - "PIE", - "PYI", - "Q", - "RET", - "RSE", - "RUF", - "SIM", - "SLF", - "SLOT", - "T10", - "TID", - "UP", - "W", - "YTT", -] - -ignore = ["COM812", "FBT", "G004", "PD901"] - -[lint.per-file-ignores] -"tests/*" = ["ARG"] - -[lint.pep8-naming] -ignore-names = [ - "*PROCESS*", - "*Bt*", - "*Bp*", - "*keV*", - "*MPa*", - "*H*", - "*T*", - "*D*", - "*He*", - "*Be*", - "C", - "N", - "O", - "Ne", - "Si", - "Ar", - "Fe", - "Ni", - "Kr", - "Xe", - "W", -] - - -[format] -preview = true diff --git a/setup.py b/setup.py deleted file mode 100644 index 0b055beb71..0000000000 --- a/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -import os -import platform -import site - -from setuptools import find_packages, setup - -MODULE_NAME = "process" -_install_loc = os.path.join(site.getsitepackages()[0], MODULE_NAME) -EXTRA_ARGS = [] -if platform.system() == "Darwin": - EXTRA_ARGS = ["-Wl,-rpath," + os.path.join(_install_loc, "lib")] - -setup_kwargs = { - "name": MODULE_NAME, - "version": "3.2.1", - "description": ( - "Power Reactor Optimisation Code for Environmental and Safety Studies" - ), - "url": "https://ccfe.ukaea.uk/resources/process/", - "author": "UKAEA", - "packages": find_packages(), - "package_dir": {"process": "process"}, - "package_data": { - "process": ["data/lz_non_corona_14_elements/*"], - "process.data.impuritydata": ["*"], - "process.io": ["*.png"], - }, - "test_suite": "pytest", - "python_requires": ">=3.10", - "install_requires": [ - "numpy>=1.23", - "scipy>=1.10", - "cvxpy~=1.7.3", - "osqp>=1.0", - "pandas>=2.0", - "numba>=0.57", - "PyVMCON>=2.4.0,<2.5.0", - "CoolProp>=6.4", - "matplotlib>=2.1.1", - "seaborn>=0.12.2", - "tabulate", - ], - "extras_require": { - "test": ["pytest>=5.4.1", "requests>=2.30", "testbook>=0.4"], - "examples": ["jupyter==1.0.0"], - "plotly": ["plotly>=5.15.0,<6"], - }, - "entry_points": {"console_scripts": ["process=process.main:main"]}, - "extra_link_args": EXTRA_ARGS, -} - -if __name__ == "__main__": - setup(**setup_kwargs)