From 141425be65c25cbb6b78fb1ec0426593d6157948 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:36:41 -0800 Subject: [PATCH] Update PyPI workflow to build and upload intake-esm artifacts (#659) --- .github/workflows/pypi.yml | 71 ++++++++++++++++++++++++++++++------ .gitignore | 1 + MANIFEST.in | 2 ++ intake_esm/__init__.py | 15 ++++---- intake_esm/py.typed | 0 pyproject.toml | 73 +++++++++++++++++++++++++++++++++----- setup.py | 62 -------------------------------- 7 files changed, 133 insertions(+), 91 deletions(-) create mode 100644 intake_esm/py.typed delete mode 100644 setup.py diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 029a3fd0..bbca7a9c 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -1,35 +1,84 @@ -name: Publish intake-esm to PyPI +name: Build and Upload intake-esm to PyPI on: release: types: - published + push: jobs: - deploy: - if: github.repository == 'intake/intake-esm' + build-artifacts: runs-on: ubuntu-latest + if: github.repository == 'intake/intake-esm' steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 with: - python-version: "3.x" + fetch-depth: 0 + - uses: actions/setup-python@v5 + name: Install Python + with: + python-version: "3.11" + - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install setuptools setuptools-scm wheel twine check-manifest + - name: Build tarball and wheels run: | git clean -xdf git restore -SW . python -m build --sdist --wheel . - - name: Test the artifacts + + - name: Check built artifacts run: | python -m twine check dist/* + pwd + if [ -f dist/intake-esm-unknown.tar.gz ]; then + echo "❌ INVALID VERSION NUMBER" + exit 1 + else + echo "✅ Looks good" + fi + - uses: actions/upload-artifact@v4 + with: + name: releases + path: dist + + test-built-dist: + needs: build-artifacts + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + name: Install Python + with: + python-version: "3.11" + - uses: actions/download-artifact@v4 + with: + name: releases + path: dist + - name: List contents of built dist + run: | + ls -ltrh + ls -ltrh dist + + - name: Verify the built dist/wheel is valid + if: github.event_name == 'push' + run: | + python -m pip install --upgrade pip + python -m pip install dist/intake_esm*.whl + python -c "import intake_esm; print(intake_esm.__version__)" + + upload-to-pypi: + needs: test-built-dist + if: github.event_name == 'release' + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: releases + path: dist - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@v1.8.12 - with: - user: ${{ secrets.PYPI_USERNAME }} - password: ${{ secrets.PYPI_PASSWORD }} - verbose: true diff --git a/.gitignore b/.gitignore index ab70786a..a93e8d59 100644 --- a/.gitignore +++ b/.gitignore @@ -118,3 +118,4 @@ tests/test_collections/*.nc dask-worker-space/ CMIP6-MRI-ESM2-0* +intake_esm/_version.py diff --git a/MANIFEST.in b/MANIFEST.in index f1477e69..608892ac 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,8 @@ include LICENSE include README.md include requirements.txt include pyproject.toml +include intake_esm/py.typed +include intake_esm/_version.py recursive-include docs/source * include docs/Makefile docs/make.bat diff --git a/intake_esm/__init__.py b/intake_esm/__init__.py index 38c68f58..c6f2e8ae 100644 --- a/intake_esm/__init__.py +++ b/intake_esm/__init__.py @@ -3,14 +3,11 @@ """ Top-level module for intake_esm. """ # Import intake first to avoid circular imports during discovery. import intake -from pkg_resources import DistributionNotFound, get_distribution -from . import tutorial -from .core import esm_datastore -from .derived import DerivedVariableRegistry, default_registry -from .utils import set_options, show_versions -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover - __version__ = '0.0.0' # pragma: no cover +from intake_esm import tutorial +from intake_esm.core import esm_datastore +from intake_esm.derived import DerivedVariableRegistry, default_registry +from intake_esm.utils import set_options, show_versions + +from intake_esm._version import __version__ diff --git a/intake_esm/py.typed b/intake_esm/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/pyproject.toml b/pyproject.toml index f990f729..e2dd146c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,65 @@ -[tool.black] -line-length = 100 -target-version = ['py310'] -skip-string-normalization = true - [build-system] requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"] -[tool.pytest.ini_options] -console_output_style = "count" -addopts = "--cov=./ --cov-report=xml --verbose" -markers = "network: tests requiring a network connection" +[project] +name = "intake-esm" +description = "An intake plugin for parsing an Earth System Model (ESM) catalog and loading netCDF files and/or Zarr stores into Xarray datasets." +readme = "README.md" +license = {text="Apache Software License 2.0"} +requires-python = ">=3.10" +maintainers = [ + { name = "NCAR XDev Team", email = "xdev@ucar.edu" }, +] +keywords = [ + "catalog", + "intake", + "xarray", +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", +] + +dynamic = ["version", "dependencies"] + +[tool.setuptools.dynamic] + +dependencies = { file = ["requirements.txt"] } +optional-dependencies = { dev = { file = ["requirements-dev.txt"] } } + +[project.entry-points."intake.drivers"] +esm_datasource = "intake_esm.source:ESMDataSource" +esm_datastore = "intake_esm.core:esm_datastore" + +[project.urls] +Documentation = "https://intake-esm.readthedocs.io" +Homepage = "https://intake-esm.readthedocs.io" +Source = "https://github.com/intake/intake-esm" +Tracker = "https://github.com/intake/intake-esm/issues" + + +[tool.setuptools.packages.find] +include = ["intake_esm*"] + +[tool.setuptools.package-data] +intake_esm = ["py.typed"] + + + +[tool.setuptools_scm] +version_scheme = "post-release" +local_scheme = "node-and-date" +fallback_version = "999" +write_to = "intake_esm/_version.py" +write_to_template = '__version__ = "{version}"' @@ -82,3 +132,8 @@ docstring-code-format = true [tool.ruff.lint.pydocstyle] convention = "numpy" + +[tool.pytest.ini_options] +console_output_style = "count" +addopts = "--cov=./ --cov-report=xml --verbose" +markers = "network: tests requiring a network connection" diff --git a/setup.py b/setup.py deleted file mode 100644 index 97a0372c..00000000 --- a/setup.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -"""The setup script.""" - - -import pathlib -from os.path import exists - -from setuptools import find_packages, setup - -with open('requirements.txt') as f: - install_requires = f.read().strip().split('\n') - - -if exists('README.md'): - long_description = pathlib.Path('README.md').read_text() -else: - long_description = '' - -CLASSIFIERS = [ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Intended Audience :: Science/Research', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Topic :: Scientific/Engineering', -] - -setup( - name='intake-esm', - description='An intake plugin for parsing an Earth System Model (ESM) catalog and loading netCDF files and/or Zarr stores into Xarray datasets.', - long_description=long_description, - long_description_content_type='text/markdown', - python_requires='>=3.10', - maintainer='NCAR XDev Team', - maintainer_email='xdev@ucar.edu', - classifiers=CLASSIFIERS, - url='https://intake-esm.readthedocs.io', - project_urls={ - 'Documentation': 'https://intake-esm.readthedocs.io', - 'Source': 'https://github.com/intake/intake-esm', - 'Tracker': 'https://github.com/intake/intake-esm/issues', - }, - packages=find_packages(exclude=('tests',)), - package_dir={'intake-esm': 'intake-esm'}, - include_package_data=True, - install_requires=install_requires, - license='Apache 2.0', - zip_safe=False, - entry_points={ - 'intake.drivers': [ - 'esm_datastore = intake_esm.core:esm_datastore', - 'esm_datasource = intake_esm.source:ESMDataSource', - ] - }, - keywords='intake, xarray, catalog', - use_scm_version={'version_scheme': 'post-release', 'local_scheme': 'dirty-tag'}, -)