From d2d6a0d3267e12ef67eefe72073cdcbe115f9156 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 3 Jun 2022 13:43:55 +0200 Subject: [PATCH 1/6] add a script to customize `setuptools_scm.local_scheme` in `pyproject.toml` --- .../workflows/configure-testpypi-version.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/configure-testpypi-version.py diff --git a/.github/workflows/configure-testpypi-version.py b/.github/workflows/configure-testpypi-version.py new file mode 100644 index 00000000000..7c16c14200d --- /dev/null +++ b/.github/workflows/configure-testpypi-version.py @@ -0,0 +1,45 @@ +import argparse +import copy +import pathlib + +import tomli +import tomli_w + + +def split_path(path): + if isinstance(path, str): + return [part for part in path.split("/") if part] + else: + return path + + +def extract(mapping, path): + parts = split_path(path) + cur = mapping + for part in parts: + cur = cur[part] + + return cur + + +def update(mapping, path, value): + new = copy.deepcopy(mapping) + + parts = split_path(path) + parent = extract(new, parts[:-1]) + parent[parts[-1]] = value + + return new + + +parser = argparse.ArgumentParser() +parser.add_argument("path", type=pathlib.Path) +args = parser.parse_args() + +content = args.path.read_text() +decoded = tomli.loads(content) +updated = update(decoded, "tool/setuptools_scm/local_scheme", "no-local-version") + +new_content = tomli_w.dumps(updated) + +args.path.write_text(new_content) From bdf8768d0f045eec129b8aaa2e8886cd3dbe94a9 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 3 Jun 2022 13:46:43 +0200 Subject: [PATCH 2/6] use `"."` as path separator --- .github/workflows/configure-testpypi-version.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/configure-testpypi-version.py b/.github/workflows/configure-testpypi-version.py index 7c16c14200d..d22ba94bd96 100644 --- a/.github/workflows/configure-testpypi-version.py +++ b/.github/workflows/configure-testpypi-version.py @@ -6,15 +6,15 @@ import tomli_w -def split_path(path): +def split_path(path, sep="/"): if isinstance(path, str): - return [part for part in path.split("/") if part] + return [part for part in path.split(sep) if part] else: return path -def extract(mapping, path): - parts = split_path(path) +def extract(mapping, path, sep="/"): + parts = split_path(path, sep=sep) cur = mapping for part in parts: cur = cur[part] @@ -22,10 +22,10 @@ def extract(mapping, path): return cur -def update(mapping, path, value): +def update(mapping, path, value, sep="/"): new = copy.deepcopy(mapping) - parts = split_path(path) + parts = split_path(path, sep=sep) parent = extract(new, parts[:-1]) parent[parts[-1]] = value @@ -38,7 +38,9 @@ def update(mapping, path, value): content = args.path.read_text() decoded = tomli.loads(content) -updated = update(decoded, "tool/setuptools_scm/local_scheme", "no-local-version") +updated = update( + decoded, "tool.setuptools_scm.local_scheme", "no-local-version", sep="." +) new_content = tomli_w.dumps(updated) From 118f1383f60df4e5dbffc4a548cdea92652c3dab Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 3 Jun 2022 13:54:04 +0200 Subject: [PATCH 3/6] add a new release workflow that triggers on push to main --- .github/workflows/testpypi-release.yaml | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/testpypi-release.yaml diff --git a/.github/workflows/testpypi-release.yaml b/.github/workflows/testpypi-release.yaml new file mode 100644 index 00000000000..0b17f86db43 --- /dev/null +++ b/.github/workflows/testpypi-release.yaml @@ -0,0 +1,87 @@ +name: Build and Upload xarray to PyPI +on: + push: + branches: + - 'main' + +# no need for concurrency limits + +jobs: + build-artifacts: + runs-on: ubuntu-latest + if: github.repository == 'pydata/xarray' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v3 + name: Install Python + with: + python-version: 3.10 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install setuptools setuptools-scm wheel twine check-manifest + python -m pip install tomli tomli_w + + - name: Disable local versions + run: | + python .github/workflows/configure-testpypi-version.py pyproject.toml + git update-index --assume-unchanged pyproject.toml + + - name: Build tarball and wheels + run: | + git clean -xdf + git restore -SW . + python -m build --sdist --wheel . + + - name: Check built artifacts + run: | + python -m twine check dist/* + pwd + if [ -f dist/xarray-0.0.0.tar.gz ]; then + echo "❌ INVALID VERSION NUMBER" + exit 1 + else + echo "✅ Looks good" + fi + + - uses: actions/upload-artifact@v3 + with: + name: releases + path: dist + + test-built-dist: + needs: build-artifacts + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v3 + name: Install Python + with: + python-version: 3.10 + - uses: actions/download-artifact@v3 + 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/xarray*.whl + python -m xarray.util.print_versions + + - name: Publish package to TestPyPI + if: github.event_name == 'push' + uses: pypa/gh-action-pypi-publish@v1.5.0 + with: + user: __token__ + password: ${{ secrets.TESTPYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + verbose: true From b1842cdad0393e08827bf30da1aa02f081418904 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 3 Jun 2022 14:00:28 +0200 Subject: [PATCH 4/6] [skip-ci] From bd9204ec24a11da0ccf4f9faf47f5f4caf51b1f8 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 5 Jun 2022 13:54:19 +0200 Subject: [PATCH 5/6] document the development versions on testpypi [skip-ci] --- doc/getting-started-guide/installing.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/getting-started-guide/installing.rst b/doc/getting-started-guide/installing.rst index faa0fba5dd3..6c7c82dec72 100644 --- a/doc/getting-started-guide/installing.rst +++ b/doc/getting-started-guide/installing.rst @@ -147,6 +147,15 @@ installed, take a look at the ``[options.extras_require]`` section in :start-at: [options.extras_require] :end-before: [options.package_data] +Development versions +-------------------- +To install the most recent development version, install from github:: + + $ python -m pip install git+https://github.com/pydata/xarray.git + +or from TestPyPI:: + + $ python -m pip install --index-url https://test.pypi.org/simple --extra-index-url https://pypi.org/simple xarray Testing ------- From f9f2c3ee9c07c025618a02d89797d8618a669fb8 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 5 Jun 2022 14:28:49 +0200 Subject: [PATCH 6/6] update whats-new.rst [skip-ci] --- doc/whats-new.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index b922e7f3949..d779a536a55 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -50,7 +50,9 @@ New Features - Improved overall typing. - :py:meth:`Dataset.to_dict` and :py:meth:`DataArray.to_dict` may now optionally include encoding attributes. (:pull:`6635`) - By Joe Hamman `_. + By `Joe Hamman `_. +- Upload development versions to `TestPyPI `_. + By `Justus Magin `_. Breaking changes ~~~~~~~~~~~~~~~~