diff --git a/.github/workflows/configure-testpypi-version.py b/.github/workflows/configure-testpypi-version.py new file mode 100644 index 00000000000..d22ba94bd96 --- /dev/null +++ b/.github/workflows/configure-testpypi-version.py @@ -0,0 +1,47 @@ +import argparse +import copy +import pathlib + +import tomli +import tomli_w + + +def split_path(path, sep="/"): + if isinstance(path, str): + return [part for part in path.split(sep) if part] + else: + return path + + +def extract(mapping, path, sep="/"): + parts = split_path(path, sep=sep) + cur = mapping + for part in parts: + cur = cur[part] + + return cur + + +def update(mapping, path, value, sep="/"): + new = copy.deepcopy(mapping) + + parts = split_path(path, sep=sep) + 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", sep="." +) + +new_content = tomli_w.dumps(updated) + +args.path.write_text(new_content) 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 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 ------- diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 54a273fbdc3..3bd46392f71 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 ~~~~~~~~~~~~~~~~