Skip to content

Commit

Permalink
Use poetry (#293)
Browse files Browse the repository at this point in the history
* Add pyproject.toml

* Remove setup.cfg and setup.py

* Update version lookup

* Update workfows to use poetry

* Update .readthedocs.yaml for poetry

* Update DEVELOPING.rst for poetry

* Update pyproject and poetry.lock

* Remove url from pyproject.toml

* Use poetry for tests

* Add default shell for fixing Windows

* Remove ixmp4 developing instructions
  • Loading branch information
phackstock committed Dec 18, 2023
1 parent 44bc04e commit 662a0eb
Show file tree
Hide file tree
Showing 12 changed files with 2,822 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: psf/black@stable
18 changes: 15 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.10'

#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install poetry dynamic versioning plugin
run: poetry self add "poetry-dynamic-versioning[plugin]"
- name: Install Pandoc
uses: r-lib/actions/setup-pandoc@v1

- name: Install dependencies and package for building the docs
run: pip install -e .[docs]
run: poetry install --no-interaction --with docs

- name: Build the docs
run: make --directory=docs html
run: |
source .venv/bin/activate
make --directory=docs html
38 changes: 33 additions & 5 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,43 @@ jobs:
name: py${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install the package
run: pip install --editable .[tests]
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install poetry dynamic versioning plugin
run: poetry self add "poetry-dynamic-versioning[plugin]"
# ----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with dev
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction

- name: Test with pytest
run: pytest tests
run: poerty run pytest tests
59 changes: 31 additions & 28 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,34 @@ jobs:
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- if: github.event_name != 'release'
name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Only run for testing
with:
repository-url: https://test.pypi.org/legacy/
- if: github.event_name == 'release'
name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Only run for actual release
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.11"
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install poetry dynamic versioning plugin
run: poetry self add "poetry-dynamic-versioning[plugin]"
- name: Build package
run: poetry build
- if: github.event_name == 'release'
name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- if: github.event_name != 'release'
name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
49 changes: 36 additions & 13 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,56 @@ on:
branches: [ '**' ]
jobs:
pytest:

defaults:
run:
shell: bash
strategy:
matrix:
os:
- macos
- ubuntu
- windows
python-version:
os: ["macos", "ubuntu", "windows"]
# keep consistent with py-version badge in README.md and docs/index.rst
- '3.10'
- '3.11'

python-version: ["3.10", "3.11"]
fail-fast: false

runs-on: ${{ matrix.os }}-latest
name: ${{ matrix.os }} py${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install the package
run: pip install --editable .[tests]
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with dev
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction

- name: Test with pytest
run: pytest tests
run: poetry run pytest tests
19 changes: 11 additions & 8 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ build:
os: ubuntu-22.04
tools:
python: "3.10"

jobs:
post_create_environment:
# Install poetry
# https://python-poetry.org/docs/#installing-manually
- curl -sSL https://install.python-poetry.org | python -
# Tell poetry to not use a virtual environment
- poetry config virtualenvs.create false
post_install:
# Install dependencies with 'docs' dependency group
# https://python-poetry.org/docs/managing-dependencies/#dependency-groups
- poetry install --with docs
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Declare the Python requirements
python:
install:
- method: pip
path: .
extra_requirements: [docs]
53 changes: 42 additions & 11 deletions DEVELOPING.rst
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
Local development
*****************

Nomenclature uses poetry for local development. Follow these steps to get setup:


```bash
# clone the nomenclature repository
git clone git@github.com:IAMconsortium/nomenclature.git
cd nomenclature
# Install Poetry, minimum version >=1.2 required
curl -sSL https://install.python-poetry.org | python -
# You may have to reinitialize your shell at this point.
source ~/.bashrc
# Activate in-project virtualenvs
poetry config virtualenvs.in-project true
# Add dynamic versioning plugin
poetry self add "poetry-dynamic-versioning[plugin]"
# Install dependencies
# (using "--with dev,docs,server" if dev and docs dependencies should be installed as well)
poetry install --with dev,docs
# Activate virtual environment
poetry shell
```

Release procedure
*****************

0. Before releasing, check that the "pytest" GitHub action on the current "main" branch
1. Before releasing, check that the "pytest" GitHub action on the current "main" branch
passes. Address any failures before releasing.

1. Test on your local machine if the build runs by running ``python -m build --sdist
2. Test on your local machine if the build runs by running ``python -m build --sdist
--wheel --outdir dist/``. Fix any packaging issues or errors by creating a PR.

2. Tag the release candidate (RC) version on the main branch as ``v<release
3. Tag the release candidate (RC) version on the main branch as ``v<release
version>rc<N>`` and push to upstream::

$ git tag v<release version>rc<N>>
$ git push upstream v<release version>rc<N>

3. Check that the GitHub action "Publish to PyPI and TestPyPI" was executed correctly
4. Check that the GitHub action "Publish to PyPI and TestPyPI" was executed correctly
and that the release candidate was successfully uploaded to TestPyPI. The address
will be https://test.pypi.org/project/nomenclature-iamc/<release version>rc<N>/.
E.g.: https://test.pypi.org/project/nomenclature-iamc/0.5rc1/

4. (Optional) Create a fresh virtual environment, download the release from TestPyPi and
5. (Optional) Create a fresh virtual environment, download the release from TestPyPi and
check that the install of package has worked correctly::

$ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple nomenclature-iamc==v<release version>rc<N>

5. Visit https://github.com/IAMconsortium/nomenclature/releases and mark the new release
6. Visit https://github.com/IAMconsortium/nomenclature/releases and mark the new release
by creating the tag and release simultaneously. The name of the tag is v<release
version> (without the rc<N>).
version> (without the rc<N>).

6. Check that the "Publish to PyPI and TestPyPI" GitHub action passed and that the
7. Check that the "Publish to PyPI and TestPyPI" GitHub action passed and that the
distributions are published on https://pypi.org/project/nomenclature-iamc/ .

7. Confirm that the doc pages are updated on
8. Confirm that the doc pages are updated on
https://nomenclature-iamc.readthedocs.io/en/stable/:

- Both the latest and the stable versions point to the new release
- The new release has been added to the list of available versions

8. Confirm that the zenodo entry is updated on https://doi.org/10.5281/zenodo.5930653.
9. Confirm that the zenodo entry is updated on https://doi.org/10.5281/zenodo.5930653.
7 changes: 1 addition & 6 deletions nomenclature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path

import yaml
from setuptools_scm import get_version

from nomenclature.cli import cli # noqa
from nomenclature.codelist import CodeList # noqa
Expand All @@ -22,11 +21,7 @@

logger = logging.getLogger(__name__)

# get version number either from git (preferred) or metadata
try:
__version__ = get_version(Path(__file__).parents[1])
except LookupError:
__version__ = version("nomenclature-iamc")
__version__ = version("nomenclature-iamc")


def create_yaml_from_xlsx(source, target, sheet_name, col, attrs=None):
Expand Down
Loading

0 comments on commit 662a0eb

Please sign in to comment.