Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to poetry for inspection #827

Merged
merged 43 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
18fb610
Use ruff instead of black and flake8
glatterf42 Feb 29, 2024
7a2a5d2
Remove Python update from docs
glatterf42 Feb 29, 2024
a678649
Adapt test_feature_aggregate as suggested
glatterf42 Mar 1, 2024
bc43247
Migrate pyproject.toml to ruff.toml
glatterf42 Mar 1, 2024
dcf09dc
Update README badge for python3.12
glatterf42 Feb 29, 2024
d797c64
Add first version of pyproject.toml
glatterf42 Mar 1, 2024
2375460
Add dynamic-versioning plugin
glatterf42 Mar 1, 2024
0ee62a3
Migrate setup.py and setup.cfg completely
glatterf42 Mar 1, 2024
27672a9
Remove setup.cfg and setup.py
glatterf42 Mar 1, 2024
4f18232
Fix typos
glatterf42 Mar 1, 2024
98b0faa
Add poetry.lock
glatterf42 Mar 1, 2024
acc89b1
Remove print, clean up authors
glatterf42 Mar 4, 2024
c5c580b
Use poetry in CI
glatterf42 Mar 4, 2024
a81f42d
Add correct package folder path
glatterf42 Mar 4, 2024
fc4ca0c
Update dependencies in nightly workflow
glatterf42 Mar 4, 2024
a53bb6e
Use >= for all deps instead of ^
glatterf42 Mar 5, 2024
fcc6995
Use poetry-venv via poetry run
glatterf42 Mar 5, 2024
8f9e47b
Use poetry to build package
glatterf42 Mar 5, 2024
0f6e7fa
Use poetry to correctly install
glatterf42 Mar 5, 2024
091aa35
Bump minimum pandas version to fit ixmp4
glatterf42 Mar 5, 2024
7f49440
Set bash as default shell
glatterf42 Mar 5, 2024
e871c5d
Bump minimum numpy version to fit pandas and ixmp4
glatterf42 Mar 5, 2024
05f7a2b
Bump minimum numpy version to fit pandas and ixmp4
glatterf42 Mar 5, 2024
9608cde
Remove outdated comments
glatterf42 Mar 6, 2024
cede417
Fix step name for inferred cache name
glatterf42 Mar 6, 2024
0c4a580
Remove duplicate dependency install
glatterf42 Mar 6, 2024
a92cc51
Use poetry-dynamic-versioning build backend
glatterf42 Mar 6, 2024
b0724d6
Mark PR in release notes
glatterf42 Mar 6, 2024
0f092c8
Fix step name for inferred cache names
glatterf42 Mar 6, 2024
d24a34f
Include poetry setup guide
glatterf42 Mar 6, 2024
3c19f3b
Use blank lines to start code-blocks
glatterf42 Mar 6, 2024
c025388
Bump setup-pandoc version
glatterf42 Mar 6, 2024
24fa760
Use cache more logically
glatterf42 Mar 6, 2024
dbe1cc6
Spread updated cache usage
glatterf42 Mar 6, 2024
83ed0f0
Remove unused setuptools dependency
glatterf42 Mar 6, 2024
4491906
Fix typos
glatterf42 Mar 6, 2024
e6ad729
Harmonize CI workflow headings
glatterf42 Mar 6, 2024
ad7b46a
Migrate optional groups to extras
glatterf42 Mar 6, 2024
40b6165
Remove import from setuptools
glatterf42 Mar 6, 2024
9a38d44
Install library with --only-root
glatterf42 Mar 6, 2024
46baa6f
Specify extras for only-root install
glatterf42 Mar 6, 2024
2eb60a5
Remove erroneous --extras
glatterf42 Mar 7, 2024
c7821de
Migrate pandas-datareader to wbdata
glatterf42 Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,39 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Pandoc
uses: r-lib/actions/setup-pandoc@v1
uses: r-lib/actions/setup-pandoc@v2

- name: Install dependencies and package for building the docs
run: pip install -e .[tutorials,optional_plotting,docs]
#------------------------------
# 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@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

#------------------------
# install root project
#------------------------
- name: Install library
run: poetry install --no-interaction --extras "docs optional_plotting tutorials"

- name: Build the docs
run: make --directory=docs html
run: poetry run make --directory=docs html
52 changes: 41 additions & 11 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,49 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install Pandoc
uses: r-lib/actions/setup-pandoc@v1
uses: r-lib/actions/setup-pandoc@v2

- name: Install dependencies and package
run: |
python -m pip install --upgrade pip
pip install -e .[tests,optional_plotting,optional_io_formats,tutorials,docs]
#------------------------------
# install & configure poetry
#------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#------------------------------------------
# update dependencies to latest versions
#------------------------------------------
- name: Update dependencies
run: poetry update --lock

#------------------------------------
# load cached venv if cache exists
#------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ matrix.os }}-${{ matrix.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 --extras "docs optional_io_formats optional_plotting tests tutorials" --no-root

#------------------------
# install root project
#------------------------
- name: Install library
run: poetry install --no-interaction --extras "optional_io_formats optional_plotting tests tutorials" --only-root

- name: Test with pytest (including Matplotlib)
run: |
pytest tests --mpl
run: poetry run pytest tests --mpl

- name: Build the docs
run: |
cd docs
make html
cd ..
run: poetry run make --directory=docs html
23 changes: 12 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ jobs:

- uses: actions/setup-python@v5

- name: Cache Python packages
uses: actions/cache@v4
#------------------------------
# install & configure poetry
#------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
path: |
~/.cache/pip
key: publish-${{ runner.os }}

- name: Upgrade pip, wheel, setuptools-scm
run: python -m pip install --upgrade pip wheel setuptools-scm twine
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: |
python3 setup.py bdist_wheel sdist
twine check dist/*
run: poetry build

- name: Publish to TestPyPI
uses: pypa/[email protected]
Expand Down
48 changes: 43 additions & 5 deletions .github/workflows/pytest-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,55 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install specific out-dated version of dependencies
#------------------------------
# install & configure poetry
#------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Enforce usage of specific out-dated versions of dependencies
# Update the package requirements when changing minimum dependency versions
# Please also add a section "Dependency changes" to the release notes
run: pip install pandas==2.0.0 numpy==1.23.0 matplotlib==3.6.0 iam-units==2020.4.21 xlrd==2.0.1 pint==0.13
# Don't install packages, just update lock file to see if a cache exists
run: |
poetry add [email protected] --lock
poetry add [email protected] --lock
poetry add [email protected] --lock
poetry add [email protected] --lock
poetry add [email protected] --lock
poetry add [email protected] --optional --lock

#------------------------------------
# load cached venv if cache exists
#------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
glatterf42 marked this conversation as resolved.
Show resolved Hide resolved

#------------------------------------------------
# install dependencies if cache does not exist
#------------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --extras "optional_io_formats optional_plotting tests tutorials" --no-root

- name: Install other dependencies and package
run: pip install .[tests,optional_plotting,optional_io_formats,tutorials]
#------------------------
# install root project
#------------------------
- name: Install library
run: poetry install --no-interaction --extras "optional_io_formats optional_plotting tests tutorials" --only-root

- name: Test with pytest
run: pytest tests
run: poetry run pytest tests
37 changes: 32 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- '3.12'

fail-fast: false

defaults:
run:
shell: bash

runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} py${{ matrix.python-version }}
Expand All @@ -31,26 +35,49 @@ jobs:
- uses: actions/checkout@v4

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

- name: Install dependencies and package
run: pip install .[tests,optional_plotting,optional_io_formats,tutorials]
#------------------------------
# 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@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#------------------------
# install your project
#------------------------
- name: Install library
run: poetry install --no-interaction --extras "optional_io_formats optional_plotting tests tutorials"

# run tests without Matplotlib & CodeCode tests on earlier Python versions
- name: Test with pytest
if: ${{ matrix.python-version != '3.12' }}
run: pytest tests
run: poetry run pytest tests

# run tests with Matplotlib & CodeCov on latest Python version
- name: Test with pytest including Matplotlib & Codecov
if: ${{ matrix.python-version == '3.12' }}
run: pytest tests --mpl --cov=./ --cov-report=xml
run: poetry run pytest tests --mpl --cov=./ --cov-report=xml

- name: Upload coverage report to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
env_vars: ${{ matrix.os }} py${{ matrix.python-version }}
90 changes: 90 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,96 @@ believe that when posting ideas or submitting code to an open-source project,
it should be obvious and self-evident that any such contributions
are made in the spirit of open collaborative development.

Setup
-----

.. code-block:: bash

# 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 docs" if docs dependencies should be installed as well)
poetry install --with docs,server,dev

# Activate virtual environment
poetry shell


Update poetry
^^^^^^^^^^^^^

Developing pyam requires poetry ``>= 1.2``.

If you already have a previous version of poetry installed you will need to update. The
first step is removing the old poetry version:

.. code-block:: bash

curl -sSL https://install.python-poetry.org | python3 - --uninstall


after that, the latest poetry version can be installed using:

.. code-block:: bash

curl -sSL https://install.python-poetry.org | python3 -


details can be found here in the poetry docs:
https://python-poetry.org/docs/#installation.

Resolve conflicts in poetry.lock
--------------------------------

When updating dependencies it can happen that a conflict between the current and the
target poetry.lock file occurs. In this case the following steps should be taken to
resolve the conflict.

#. Do not attempt to manually resolve in the GitHub web interface.
#. Instead checkout the target branch locally and merge into your branch:

.. code-block:: bash

git checkout main
git pull origin main
git checkout my-branch
git merge main


#. After the last step you'll have a merge conflict in poetry.lock.
#. Instead of resolving the conflict, directly checkout the one from main and rewrite
it:

.. code-block:: bash

# Get poetry.lock to look like it does in master
git checkout main poetry.lock
# Rewrite the lock file
poetry lock --no-update

#. After that simply add poetry.lock to mark the conflict as resolved and commit to
finalize the merge:

.. code-block:: bash

git add poetry.lock
git commit

# and most likely needed
poetry install

(Taken from https://www.peterbe.com/plog/how-to-resolve-a-git-conflict-in-poetry.lock)

.. _`pep8`: https://www.python.org/dev/peps/pep-0008/

.. _`numpydoc docstring guide`: https://numpydoc.readthedocs.io/en/latest/format.html
Expand Down
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Next release

## Dependency changes

Bumped minimum version of pandas and numpy to fit **ixmp4**'s requirement.

## Individual updates

- [#827](https://github.com/IAMconsortium/pyam/pull/827) Migrate to poetry for project management
- [#830](https://github.com/IAMconsortium/pyam/pull/830) Implement more consistent logging behavior with **ixmp4**
- [#829](https://github.com/IAMconsortium/pyam/pull/829) Add a `pyam.iiasa.platforms()` function for a list of available platforms
- [#826](https://github.com/IAMconsortium/pyam/pull/826) Add `read_ixmp4()` function and extend integration test
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@
"pint": ("https://pint.readthedocs.io/en/stable", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"plotly": ("https://plotly.com/python-api-reference/", None),
"pandas_datareader": ("https://pandas-datareader.readthedocs.io/en/stable", None),
"unfccc_di_api": ("https://unfccc-di-api.readthedocs.io/en/stable", None),
"nomenclature": ("https://nomenclature-iamc.readthedocs.io/en/stable", None),
"ixmp4": ("https://docs.ece.iiasa.ac.at/projects/ixmp4/en/stable", None),
"wbdata": ("https://wbdata.readthedocs.io/en/stable/", None),
}

# Set up the plotting gallery with plotly scraper
Expand Down
Loading