diff --git a/.git_archival.txt b/.git_archival.txt deleted file mode 100644 index 95cb3eea..00000000 --- a/.git_archival.txt +++ /dev/null @@ -1 +0,0 @@ -ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 00a7b00c..00000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -.git_archival.txt export-subst diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 97b3aa77..5a2c1eca 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,8 +22,6 @@ jobs: matrix: include: # Warning: Unless in quotations, numbers below are read as floats. 3.10 < 3.2 - - python-version: '3.7' - esmf-version: 8.1 - python-version: '3.8' esmf-version: 8.2 - python-version: '3.9' @@ -77,7 +75,7 @@ jobs: access_token: ${{ github.token }} - uses: actions/checkout@v3 - name: Create conda environment - uses: mamba-org/provision-with-micromamba@main + uses: mamba-org/provision-with-micromamba@v15 with: cache-downloads: true micromamba-version: 'latest' diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index f4d062b1..72a67bc7 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -1,48 +1,55 @@ -name: Upload xesmf to PyPI +name: Publish to PyPI on: + pull_request: + push: + branches: + - main release: types: - published +defaults: + run: + shell: bash + jobs: - deploy: + packages: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Get tags - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - shell: bash - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.x' - - name: Install dependencies + - name: Get tags + run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + + - name: Install build tools run: | - python -m pip install --upgrade pip - python -m pip install setuptools setuptools-scm wheel twine check-manifest + python -m pip install --upgrade build - - name: Build tarball and wheels + - name: Build binary wheel + run: python -m build --sdist --wheel . --outdir dist + + - name: CheckFiles run: | - python setup.py sdist - python -m pip wheel . -w dist --no-deps + ls dist + python -m pip install --upgrade check-manifest + check-manifest --verbose - - name: Test the artifacts + - name: Test wheels run: | - python -m check_manifest --verbose + # We cannot run this step b/c esmpy is not available on PyPI + # cd dist && python -m pip install *.whl && cd .. + python -m pip install --upgrade build twine python -m twine check dist/* - # FIXME: failing at the moment b/c we don't have PyPI ownership - # - name: Publish - # env: - # TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - # TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - # run: | - # python -m twine upload dist/* - - - name: upload artifacs - uses: actions/upload-artifact@v3 + - name: Publish a Python distribution to PyPI + if: success() && github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@release/v1 with: - path: dist/* + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7fcdfa17..e482ff00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: double-quote-string-fixer - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.3.0 hooks: - id: black @@ -37,7 +37,7 @@ repos: - id: isort - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.4 + rev: v3.0.0-alpha.6 hooks: - id: prettier @@ -52,3 +52,19 @@ repos: '--keep-execution-count', '--keep-empty', ] + + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 0.9.2 + hooks: + - id: pyproject-fmt + +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit.com hooks + + for more information, see https://pre-commit.ci + autofix_prs: false + autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' + autoupdate_schedule: monthly + skip: [] + submodules: false diff --git a/MANIFEST.in b/MANIFEST.in index 95bc37f8..65f4d324 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,14 +3,16 @@ include *.rst graft xesmf -prune doc -prune ci -prune binder +prune .github prune *.egg-info +prune binder +prune ci +prune doc -exclude *.yml exclude *.yaml -exclude .*.toml +exclude *.yml exclude .*.txt exclude .gitignore +exclude .pre-commit-config.yaml +exclude .prettierrc.toml exclude xesmf/_version.py diff --git a/pyproject.toml b/pyproject.toml index cdc72675..1da0b302 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,68 @@ [build-system] -requires = ["setuptools>=41.2", "setuptools_scm", "wheel", "setuptools_scm_git_archive"] build-backend = "setuptools.build_meta" +requires = [ + "setuptools>=41.2", + "setuptools_scm", + "wheel", +] + +[project] +name = "xesmf" +description = "Universal Regridder for Geospatial Data" +license = {text = "MIT"} +authors = [ + {name = "Jiawei Zhuang", email = "jiaweizhuang@g.harvard.edu"}, +] +requires-python = ">=3.8" +classifiers = [ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Intended Audience :: Science/Research', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Topic :: Scientific/Engineering', +] +dynamic = [ + "dependencies", + "readme", + "version", +] +[project.urls] +documentation = "https://xesmf.readthedocs.io/en/latest/" +homepage = "https://github.com/pangeo-data/xESMF" +repository = "https://github.com/pangeo-data/xESMF" + +[tool.setuptools] +packages = ["xesmf", "xesmf.tests"] +license-files = ["LICENSE"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +readme = {file = "README.rst", content-type = "text/x-rst"} + +[tool.setuptools_scm] +write_to = "xesmf/_version.py" +write_to_template = "__version__ = '{version}'" [tool.black] line-length = 100 target-version = ['py38'] skip-string-normalization = true + +[tool.isort] +known_first_party = "xesmf" +known_third_party = ["cf_xarray", "cftime", "dask", "numba", "numpy", "pytest", "shapely", "sparse", "xarray"] +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +combine_as_imports = true +line_length = 100 +skip = [ + "setup.py", + "doc/conf.py", +] diff --git a/readthedocs.yml b/readthedocs.yml index ca4f3124..e97791a2 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -1,8 +1,10 @@ -build: - image: latest - version: 2 +build: + os: ubuntu-22.04 + tools: + python: '3.8' + python: install: - requirements: doc/requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..c9e52bae --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +cf-xarray>=0.5.1 +# We cannot list this here b/c it is not on PyPI. +#esmpy>=8.0.0 +numba >=0.55.2 +numpy>=1.16 +shapely +sparse>=0.8.0 +xarray>=0.16.2 diff --git a/setup.cfg b/setup.cfg index 10212a70..e6774ae8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,15 +8,3 @@ max-line-length = 100 max-complexity = 18 select = B,C,E,F,W,T4,B9 extend-ignore = E203,E501,E402,W605 - -[isort] -known_first_party = xesmf -known_third_party = cf_xarray,cftime,dask,numba,numpy,pytest,setuptools,shapely,sparse,xarray -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -combine_as_imports = True -line_length = 100 -skip = - doc/conf.py - setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 5d3a9af4..00000000 --- a/setup.py +++ /dev/null @@ -1,66 +0,0 @@ -import os - -from setuptools import find_packages, setup - -DISTNAME = 'xesmf' -DESCRIPTION = 'Universal Regridder for Geospatial Data' -AUTHOR = 'Jiawei Zhuang' -AUTHOR_EMAIL = 'jiaweizhuang@g.harvard.edu' -URL = 'https://github.com/pangeo-data/xESMF' -LICENSE = 'MIT' -PYTHON_REQUIRES = '>=3.6' -USE_SCM_VERSION = { - 'write_to': 'xesmf/_version.py', - 'write_to_template': '__version__ = "{version}"', - 'tag_regex': r'^(?Pv)?(?P[^\+]+)(?P.*)?$', -} - -# https://github.com/rtfd/readthedocs.org/issues/5512#issuecomment-475024373 -on_rtd = os.environ.get('READTHEDOCS') == 'True' -if on_rtd: - INSTALL_REQUIRES = [] -else: - INSTALL_REQUIRES = [ - 'esmpy>=8.0.0', - 'xarray>=0.16.2', - 'numpy>=1.16', - 'shapely', - 'cf-xarray>=0.5.1', - 'sparse>=0.8.0', - 'numba >=0.55.2', - ] - -CLASSIFIERS = [ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Intended Audience :: Science/Research', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Scientific/Engineering', -] - - -def readme(): - with open('README.rst') as f: - return f.read() - - -setup( - name=DISTNAME, - license=LICENSE, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - classifiers=CLASSIFIERS, - description=DESCRIPTION, - long_description=readme(), - long_description_content_type='text/x-rst', - python_requires=PYTHON_REQUIRES, - install_requires=INSTALL_REQUIRES, - url=URL, - packages=find_packages(), - use_scm_version=USE_SCM_VERSION, -) diff --git a/xesmf/backend.py b/xesmf/backend.py index a21cbce3..db0a1995 100644 --- a/xesmf/backend.py +++ b/xesmf/backend.py @@ -439,7 +439,6 @@ def esmf_regrid_build( # conservative regridding needs cell corner information if method in ['conservative', 'conservative_normed']: - if not isinstance(sourcegrid, ESMF.Mesh) and not sourcegrid.has_corners: raise ValueError( 'source grid has no corner information. ' 'cannot use conservative regridding.' diff --git a/xesmf/frontend.py b/xesmf/frontend.py index 2e1caac2..b7699483 100644 --- a/xesmf/frontend.py +++ b/xesmf/frontend.py @@ -29,7 +29,6 @@ def as_2d_mesh(lon, lat): - if (lon.ndim, lat.ndim) == (2, 2): assert lon.shape == lat.shape, 'lon and lat should have same shape' elif (lon.ndim, lat.ndim) == (1, 1): diff --git a/xesmf/tests/test_backend.py b/xesmf/tests/test_backend.py index 4c82bd4e..9ce2b3f5 100644 --- a/xesmf/tests/test_backend.py +++ b/xesmf/tests/test_backend.py @@ -72,7 +72,6 @@ def test_warn_lat_range(): def test_esmf_grid_with_corner(): - # only center coordinate, no corners # remember to pass transpose (F-ordered) to backend grid = Grid.from_xarray(lon.T, lat.T) @@ -106,7 +105,6 @@ def test_esmf_grid_with_corner(): def test_esmf_build_bilinear(): - grid_in = Grid.from_xarray(lon_in.T, lat_in.T) grid_out = Grid.from_xarray(lon_out.T, lat_out.T) @@ -122,7 +120,6 @@ def test_esmf_build_bilinear(): def test_esmf_extrapolation(): - grid_in = Grid.from_xarray(lon_in.T, lat_in.T) grid_out = Grid.from_xarray(lon_out.T, lat_out.T) @@ -145,7 +142,6 @@ def test_esmf_extrapolation(): def test_regrid(): - # use conservative regridding as an example, # since it is the most well-tested studied one in papers @@ -200,7 +196,6 @@ def test_regrid(): def test_regrid_periodic_wrong(): - # not using periodic grid grid_in = Grid.from_xarray(lon_in.T, lat_in.T) grid_out = Grid.from_xarray(lon_out.T, lat_out.T) @@ -219,7 +214,6 @@ def test_regrid_periodic_wrong(): def test_regrid_periodic_correct(): - # only need to specific periodic for input grid grid_in = Grid.from_xarray(lon_in.T, lat_in.T, periodic=True) grid_out = Grid.from_xarray(lon_out.T, lat_out.T) diff --git a/xesmf/tests/test_frontend.py b/xesmf/tests/test_frontend.py index 73304e0e..51dfcdac 100644 --- a/xesmf/tests/test_frontend.py +++ b/xesmf/tests/test_frontend.py @@ -821,7 +821,6 @@ def test_non_cf_latlon(): ], ) def test_locstream_dim_name(var_renamer, dim_out): - ds_locs_renamed = ds_locs.copy() for var, renamer in var_renamer.items(): ds_locs_renamed[var] = ds_locs_renamed[var].rename(renamer) diff --git a/xesmf/tests/test_util.py b/xesmf/tests/test_util.py index 234d02dc..b2d7c2d5 100644 --- a/xesmf/tests/test_util.py +++ b/xesmf/tests/test_util.py @@ -4,7 +4,6 @@ def test_grid_global(): - ds = xe.util.grid_global(1.5, 1.5) refshape = (120, 240) refshape_b = (121, 241) @@ -36,7 +35,6 @@ def test_grid_global_bad_resolution(): def test_simple_tripolar_grid(): - lon, lat = xe.util.simple_tripolar_grid(360, 180, lat_cap=60, lon_cut=-300.0) assert lon.min() >= -300.0 diff --git a/xesmf/util.py b/xesmf/util.py index cd8f0ce1..4790b112 100644 --- a/xesmf/util.py +++ b/xesmf/util.py @@ -203,7 +203,7 @@ def split_polygons_and_holes(polys): holes = [] i_ext = [] i_hol = [] - for (i, poly) in _flatten_poly_list(polys): + for i, poly in _flatten_poly_list(polys): exteriors.append(Polygon(poly.exterior)) i_ext.append(i) holes.extend(map(Polygon, poly.interiors))