From 8c746a2a2283799a4cb112e8d32e96ffd6eb4ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Castel=C3=A3o?= Date: Wed, 20 Mar 2024 20:08:45 -0600 Subject: [PATCH] Migrating to pyproject.toml (#194) * Initiating pyproject.toml * Moving some metadata to pyproject.toml * Checking TOML with pre-commit * Optional requirements [dev] * Moving dependencies into pyproject.toml * Version already moved * Keywords * zip_safe is considered obsolete Some info: https://setuptools.pypa.io/en/latest/deprecated/zip_safe.html#understanding-the-zip-safe-flag * fix: Requirements moved into dependencies * Fixing documentation URL * Moving include_package_data to pyproject.toml * Deginign package_dir with pyproject.toml * Defining optional dependency group 'test' * Moving to dynamic versioning * Build package with `build` and check it with twine * fix: fetch-depth to 0 due to bug with fetch-tags It looks like fetch-tags is currently not working, so we will need to fetch-depth for now. * fix: Explicit dependency on numpy and scipy * fix: Restricting TensorFlow to < 2.16 --- .github/workflows/publish_to_pypi.yml | 8 ++- .github/workflows/pull_request_tests.yml | 6 +- .gitignore | 1 + .pre-commit-config.yaml | 1 + pyproject.toml | 71 ++++++++++++++++++++++++ requirements.txt | 16 ------ setup.py | 44 +-------------- sup3r/__init__.py | 3 +- sup3r/bias/bias_calc_cli.py | 2 +- sup3r/cli.py | 2 +- sup3r/pipeline/forward_pass_cli.py | 2 +- sup3r/postprocessing/data_collect_cli.py | 2 +- sup3r/postprocessing/file_handling.py | 2 +- sup3r/preprocessing/data_extract_cli.py | 2 +- sup3r/qa/qa_cli.py | 2 +- sup3r/qa/stats_cli.py | 2 +- sup3r/qa/visual_qa_cli.py | 2 +- sup3r/solar/solar_cli.py | 2 +- sup3r/utilities/__init__.py | 2 +- sup3r/utilities/regridder_cli.py | 2 +- sup3r/version.py | 3 - 21 files changed, 97 insertions(+), 80 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 sup3r/version.py diff --git a/.github/workflows/publish_to_pypi.yml b/.github/workflows/publish_to_pypi.yml index 0cd249180..d0b445ac2 100644 --- a/.github/workflows/publish_to_pypi.yml +++ b/.github/workflows/publish_to_pypi.yml @@ -20,7 +20,11 @@ jobs: - name: Install dependencies and Build run: | python -m pip install --upgrade pip - pip install setuptools wheel twine - python setup.py sdist bdist_wheel + pip install setuptools build + python -m build --sdist --wheel --outdir dist/ . + - name: Check distribution files + run: | + pip install twine + twine check dist/* - name: Publish uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/pull_request_tests.yml b/.github/workflows/pull_request_tests.yml index db08edc14..951bcb04b 100644 --- a/.github/workflows/pull_request_tests.yml +++ b/.github/workflows/pull_request_tests.yml @@ -20,7 +20,8 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: 1 + fetch-depth: 0 + fetch-tags: true - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -29,8 +30,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install pytest - python -m pip install . + python -m pip install .[test] - name: Run pytest run: | python -m pytest -v --disable-warnings diff --git a/.gitignore b/.gitignore index af6cd09a0..b835a55f7 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ wheels/ *.egg-info/ .installed.cfg *.egg +_version.py # PyInstaller # Usually these files are written by a python script from a template diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28febf3c5..8f48253b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: - id: check-json - id: check-merge-conflict - id: check-symlinks + - id: check-toml - id: flake8 - id: mixed-line-ending - repo: https://github.com/PyCQA/pylint diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..a9493f4a0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,71 @@ +[build-system] +requires = [ + "setuptools >= 61.0", + "setuptools_scm[toml] >= 8", +] +build-backend = "setuptools.build_meta" + +[project] +name = "NREL-sup3r" +dynamic = ["version"] +description = "Super Resolving Renewable Resource Data (sup3r)" +keywords = ["sup3r", "NREL"] +readme = "README.rst" +authors = [ + {name = "Brandon Benton", email = "brandon.benton@nrel.gov"}, +] +license = {text = "BSD-3-Clause"} +requires-python = ">= 3.8" +classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", +] +dependencies = [ + "NREL-rex>=0.2.84", + "NREL-phygnn>=0.0.23", + "NREL-gaps>=0.6.0", + "NREL-farms>=1.0.4", + "dask>=2022.0", + "google-auth-oauthlib==0.5.3", + "matplotlib>=3.1", + "numpy>=1.7.0", + "netCDF4==1.5.8", + "pandas>=2.0", + "pillow>=10.0", + "pytest>=5.2", + "scipy>=1.0.0", + "sphinx>=7.0", + "tensorflow>2.4,<2.16", + "xarray>=2023.0", +] + +[project.optional-dependencies] +dev = [ + "build>=0.5", + "flake8", + "pre-commit", + "pylint", +] +doc = [ + "sphinx>=7.0", +] +test = [ + "pytest>=5.2", +] + +[project.urls] +homepage = "https://github.com/NREL/sup3r" +documentation = "https://nrel.github.io/sup3r/" +repository = "https://github.com/NREL/sup3r" + +[tool.setuptools] +include-package-data = true +packages = ["sup3r"] + +[tool.setuptools_scm] +version_file = "sup3r/_version.py" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0f83724a3..000000000 --- a/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ -matplotlib>=3.1 -NREL-rex>=0.2.84 -NREL-phygnn>=0.0.23 -NREL-gaps>=0.6.0 -NREL-farms>=1.0.4 -google-auth-oauthlib==0.5.3 -pytest>=5.2 -pillow>=10.0 -tensorflow>2.4,<2.16 -xarray>=2023.0 -netCDF4==1.5.8 -numpy>=1.7.0 -dask>=2022.0 -sphinx>=7.0 -scipy>=1.0.0 -pandas>=2.0 diff --git a/setup.py b/setup.py index 8e4c8bfc1..984578650 100644 --- a/setup.py +++ b/setup.py @@ -1,27 +1,12 @@ """ setup.py """ -import os -from codecs import open -from setuptools import setup, find_packages +from setuptools import setup from setuptools.command.develop import develop from subprocess import check_call import shlex from warnings import warn -here = os.path.abspath(os.path.dirname(__file__)) - -with open(os.path.join(here, "README.rst"), encoding="utf-8") as f: - readme = f.read() - -with open(os.path.join(here, "requirements.txt")) as f: - install_requires = f.readlines() - -with open(os.path.join(here, "sup3r", "version.py"), encoding="utf-8") as f: - version = f.read() - -version = version.split('=')[-1].strip().strip('"').strip("'") - class PostDevelopCommand(develop): """ @@ -42,12 +27,6 @@ def run(self): setup( - name="NREL-sup3r", - version=version, - description="Super Resolving Renewable Resource Data (sup3r)", - long_description=readme, - author="Brandon Benton", - author_email="brandon.benton@nrel.gov", entry_points={ "console_scripts": ["sup3r=sup3r.cli:main", "sup3r-pipeline=sup3r.pipeline.pipeline_cli:main", @@ -66,27 +45,6 @@ def run(self): "data_collect_cli:main"), ], }, - url="https://github.com/NREL/sup3r", - packages=find_packages(), - package_dir={"sup3r": "sup3r"}, - include_package_data=True, - license="BSD 3-Clause", - zip_safe=False, - keywords="sup3r", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Natural Language :: English", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], test_suite="tests", - python_requires='>=3.8', - install_requires=install_requires, - extras_require={ - "dev": ["flake8", "pre-commit", "pylint"], - }, cmdclass={"develop": PostDevelopCommand}, ) diff --git a/sup3r/__init__.py b/sup3r/__init__.py index 8e37520df..628a78c73 100644 --- a/sup3r/__init__.py +++ b/sup3r/__init__.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- """Super Resolving Renewable Energy Resource Data (SUP3R)""" import os -from sup3r.version import __version__ + +from ._version import __version__ # Next import sets up CLI commands # This line could be "import sup3r.cli" but that breaks sphinx as of 12/11/2023 from sup3r.cli import main diff --git a/sup3r/bias/bias_calc_cli.py b/sup3r/bias/bias_calc_cli.py index 13288f277..ee5cb977d 100644 --- a/sup3r/bias/bias_calc_cli.py +++ b/sup3r/bias/bias_calc_cli.py @@ -8,10 +8,10 @@ import click +from sup3r import __version__ import sup3r.bias.bias_calc from sup3r.utilities import ModuleName from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI -from sup3r.version import __version__ logger = logging.getLogger(__name__) diff --git a/sup3r/cli.py b/sup3r/cli.py index f548990e4..69a49aac2 100644 --- a/sup3r/cli.py +++ b/sup3r/cli.py @@ -7,7 +7,7 @@ from gaps import Pipeline -from sup3r.version import __version__ +from sup3r import __version__ from sup3r.utilities import ModuleName from sup3r.pipeline.forward_pass_cli import from_config as fwp_cli from sup3r.solar.solar_cli import from_config as solar_cli diff --git a/sup3r/pipeline/forward_pass_cli.py b/sup3r/pipeline/forward_pass_cli.py index 3cb33b3b2..d614502b4 100644 --- a/sup3r/pipeline/forward_pass_cli.py +++ b/sup3r/pipeline/forward_pass_cli.py @@ -9,7 +9,7 @@ import os from sup3r.utilities import ModuleName -from sup3r.version import __version__ +from sup3r import __version__ from sup3r.pipeline.forward_pass import ForwardPassStrategy, ForwardPass from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI diff --git a/sup3r/postprocessing/data_collect_cli.py b/sup3r/postprocessing/data_collect_cli.py index c15089b4a..2edf23042 100644 --- a/sup3r/postprocessing/data_collect_cli.py +++ b/sup3r/postprocessing/data_collect_cli.py @@ -5,11 +5,11 @@ import click +from sup3r import __version__ from sup3r.postprocessing.collection import CollectorH5, CollectorNC from sup3r.utilities import ModuleName from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI from sup3r.utilities.utilities import get_source_type -from sup3r.version import __version__ logger = logging.getLogger(__name__) diff --git a/sup3r/postprocessing/file_handling.py b/sup3r/postprocessing/file_handling.py index 445cf866f..7b6ce9c1e 100644 --- a/sup3r/postprocessing/file_handling.py +++ b/sup3r/postprocessing/file_handling.py @@ -25,7 +25,7 @@ invert_uv, pd_date_range, ) -from sup3r.version import __version__ +from sup3r import __version__ logger = logging.getLogger(__name__) diff --git a/sup3r/preprocessing/data_extract_cli.py b/sup3r/preprocessing/data_extract_cli.py index d7103ae60..6cf2cda5b 100644 --- a/sup3r/preprocessing/data_extract_cli.py +++ b/sup3r/preprocessing/data_extract_cli.py @@ -5,9 +5,9 @@ import click import sup3r +from sup3r import __version__ from sup3r.utilities import ModuleName from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI -from sup3r.version import __version__ logger = logging.getLogger(__name__) diff --git a/sup3r/qa/qa_cli.py b/sup3r/qa/qa_cli.py index 8713a42b9..45e3e0d55 100644 --- a/sup3r/qa/qa_cli.py +++ b/sup3r/qa/qa_cli.py @@ -5,8 +5,8 @@ import click import logging +from sup3r import __version__ from sup3r.utilities import ModuleName -from sup3r.version import __version__ from sup3r.qa.qa import Sup3rQa from sup3r.utilities.cli import BaseCLI diff --git a/sup3r/qa/stats_cli.py b/sup3r/qa/stats_cli.py index 793b15039..823bf24b5 100644 --- a/sup3r/qa/stats_cli.py +++ b/sup3r/qa/stats_cli.py @@ -5,8 +5,8 @@ import click import logging +from sup3r import __version__ from sup3r.utilities import ModuleName -from sup3r.version import __version__ from sup3r.qa.stats import Sup3rStatsMulti from sup3r.utilities.cli import BaseCLI diff --git a/sup3r/qa/visual_qa_cli.py b/sup3r/qa/visual_qa_cli.py index ae38db9e6..e630024c4 100644 --- a/sup3r/qa/visual_qa_cli.py +++ b/sup3r/qa/visual_qa_cli.py @@ -5,8 +5,8 @@ import click import logging +from sup3r import __version__ from sup3r.utilities import ModuleName -from sup3r.version import __version__ from sup3r.qa.visual_qa import Sup3rVisualQa from sup3r.utilities.cli import BaseCLI diff --git a/sup3r/solar/solar_cli.py b/sup3r/solar/solar_cli.py index 25c6c216d..833b6635b 100644 --- a/sup3r/solar/solar_cli.py +++ b/sup3r/solar/solar_cli.py @@ -7,9 +7,9 @@ import logging import os +from sup3r import __version__ from sup3r.solar import Solar from sup3r.utilities import ModuleName -from sup3r.version import __version__ from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI diff --git a/sup3r/utilities/__init__.py b/sup3r/utilities/__init__.py index 95a54ccd2..5ed90b511 100644 --- a/sup3r/utilities/__init__.py +++ b/sup3r/utilities/__init__.py @@ -12,7 +12,7 @@ import phygnn import rex -from sup3r.version import __version__ +from sup3r import __version__ VERSION_RECORD = {'sup3r': __version__, diff --git a/sup3r/utilities/regridder_cli.py b/sup3r/utilities/regridder_cli.py index 5b1c623a0..9be8147b2 100644 --- a/sup3r/utilities/regridder_cli.py +++ b/sup3r/utilities/regridder_cli.py @@ -8,8 +8,8 @@ from inspect import signature import os +from sup3r import __version__ from sup3r.utilities import ModuleName -from sup3r.version import __version__ from sup3r.utilities.regridder import RegridOutput from sup3r.utilities.cli import AVAILABLE_HARDWARE_OPTIONS, BaseCLI diff --git a/sup3r/version.py b/sup3r/version.py deleted file mode 100644 index d50352360..000000000 --- a/sup3r/version.py +++ /dev/null @@ -1,3 +0,0 @@ -"""SUP3R Version""" - -__version__ = '0.1.2'