Skip to content

Commit 22488d8

Browse files
authored
Merge pull request #306 from Climate-REF/pypi-check
2 parents b8d3872 + efdd069 commit 22488d8

File tree

6 files changed

+147
-6
lines changed

6 files changed

+147
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
fail-fast: false
6161
matrix:
6262
os: [ "ubuntu-latest" ]
63-
python-version: [ "3.11", "3.12", "3.13" ]
63+
python-version: [ "3.11", "3.13" ]
6464
runs-on: "${{ matrix.os }}"
6565
steps:
6666
- name: Check out repository
@@ -69,7 +69,13 @@ jobs:
6969
with:
7070
python-version: ${{ matrix.python-version }}
7171
- name: Check importable without extras
72-
run: uv run --package climate_ref_core python scripts/test-install.py
72+
run: |
73+
uv run --package climate_ref scripts/test-install.py climate_ref
74+
uv run --package climate_ref_core scripts/test-install.py climate_ref_core
75+
uv run --package climate_ref_celery scripts/test-install.py climate_ref_celery
76+
uv run --package climate_ref_ilamb scripts/test-install.py climate_ref_ilamb
77+
uv run --package climate_ref_esmvaltool scripts/test-install.py climate_ref_esmvaltool
78+
uv run --package climate_ref_pmp python scripts/test-install.py climate_ref_pmp
7379
7480
check-build:
7581
runs-on: ubuntu-latest

.github/workflows/install-pypi.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Test installation of the latest version from PyPI works.
2+
# We make sure that we run the tests that apply to the version we installed,
3+
# rather than the latest tests in main.
4+
# The reason we do this, is that we want this workflow to test
5+
# that installing from PyPI leads to a correct installation.
6+
# If we tested against main, the tests could fail
7+
# because the tests from main require the new features in main to pass.
8+
name: Test installation PyPI
9+
10+
on:
11+
workflow_dispatch:
12+
schedule:
13+
# * is a special character in YAML so you have to quote this string
14+
# This means At 03:00 on Wednesday.
15+
# see https://crontab.guru/#0_0_*_*_3
16+
- cron: '0 3 * * 3'
17+
18+
jobs:
19+
test-pypi-install:
20+
name: Test PyPI install ${{ matrix.install-target }} (${{ matrix.python-version }}, ${{ matrix.os }})
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
25+
# Test SPEC0 supported python versions https://scientific-python.org/specs/spec-0000/
26+
python-version: [ "3.11", "3.12", "3.13" ]
27+
install-target: [ "climate-ref", "climate-ref[aft-providers]"]
28+
runs-on: "${{ matrix.os }}"
29+
steps:
30+
- name: Set up Python "${{ matrix.python-version }}"
31+
id: setup-python
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: "${{ matrix.python-version }}"
35+
- name: Install
36+
run: |
37+
pip install --upgrade pip wheel
38+
pip install "${{ matrix.install-target }}" 2>stderr.txt
39+
- name: Check no warnings
40+
if: matrix.os != 'windows-latest'
41+
run: |
42+
if grep -q "WARN" stderr.txt; then echo "Warnings in pip install output" && cat stderr.txt && exit 1; else exit 0; fi
43+
- name: Get version non-windows
44+
if: matrix.os != 'windows-latest'
45+
run: |
46+
INSTALLED_VERSION=`python -c 'import climate_ref; print(f"v{climate_ref.__version__}")'`
47+
echo $INSTALLED_VERSION
48+
echo "INSTALLED_VERSION=$INSTALLED_VERSION" >> $GITHUB_ENV
49+
- name: Get version windows
50+
if: matrix.os == 'windows-latest'
51+
run: |
52+
chcp 65001 # use utf-8
53+
python -c 'import climate_ref; f = open("version.txt", "w"); f.write(f"INSTALLED_VERSION=v{climate_ref.__version__}"); f.close()'
54+
echo "Showing version.txt"
55+
type version.txt
56+
type version.txt >> $env:GITHUB_ENV
57+
- name: Check installed version environment variable
58+
run: |
59+
echo "${{ env.INSTALLED_VERSION }}"
60+
- name: Checkout repository
61+
uses: actions/checkout@v4
62+
with:
63+
ref: ${{ env.INSTALLED_VERSION }}
64+
- name: Test installation
65+
run: |
66+
which python
67+
python scripts/test-install.py climate_ref
68+
test-pypi-install-core:
69+
name: Test PyPI install ${{ matrix.install-target }} (${{ matrix.python-version }}, ${{ matrix.os }})
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
74+
# Test against all security and bugfix versions: https://devguide.python.org/versions/
75+
python-version: [ "3.11", "3.12", "3.13" ]
76+
install-target: [ "climate-ref-core"]
77+
runs-on: "${{ matrix.os }}"
78+
steps:
79+
- name: Set up Python "${{ matrix.python-version }}"
80+
id: setup-python
81+
uses: actions/setup-python@v4
82+
with:
83+
python-version: "${{ matrix.python-version }}"
84+
- name: Install
85+
run: |
86+
pip install --upgrade pip wheel
87+
pip install "${{ matrix.install-target }}" 2>stderr.txt
88+
- name: Check no warnings
89+
if: matrix.os != 'windows-latest'
90+
run: |
91+
if grep -q "WARN" stderr.txt; then echo "Warnings in pip install output" && cat stderr.txt && exit 1; else exit 0; fi
92+
- name: Get version non-windows
93+
if: matrix.os != 'windows-latest'
94+
run: |
95+
INSTALLED_VERSION=`python -c 'import climate_ref_core; print(f"v{climate_ref_core.__version__}")'`
96+
echo $INSTALLED_VERSION
97+
echo "INSTALLED_VERSION=$INSTALLED_VERSION" >> $GITHUB_ENV
98+
- name: Get version windows
99+
if: matrix.os == 'windows-latest'
100+
run: |
101+
chcp 65001 # use utf-8
102+
python -c 'import climate_ref_core; f = open("version.txt", "w"); f.write(f"INSTALLED_VERSION=v{climate_ref_core.__version__}"); f.close()'
103+
echo "Showing version.txt"
104+
type version.txt
105+
type version.txt >> $env:GITHUB_ENV
106+
- name: Check installed version environment variable
107+
run: |
108+
echo "${{ env.INSTALLED_VERSION }}"
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
with:
112+
ref: ${{ env.INSTALLED_VERSION }}
113+
- name: Test installation
114+
run: |
115+
which python
116+
python scripts/test-install.py climate_ref_core

changelog/306.improvement.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tests that the pypi releases are installable

packages/climate-ref-core/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies = [
3131
"typing_extensions",
3232
"requests",
3333
"rich",
34+
"loguru>=0.7.0",
35+
"pooch>=1.8.0,<2",
3436

3537
# SPEC 0000 constraints
3638
# We follow [SPEC-0000](https://scientific-python.org/specs/spec-0000/)

scripts/test-install.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import importlib
1010
import pkgutil
1111

12-
import climate_ref_core
12+
import typer
13+
from loguru import logger
1314

1415

1516
def import_submodules(package_name):
@@ -20,11 +21,22 @@ def import_submodules(package_name):
2021

2122
for _, name, is_pkg in pkgutil.walk_packages(package.__path__):
2223
full_name = package.__name__ + "." + name
24+
logger.info(f"Importing {full_name}")
2325
importlib.import_module(full_name)
2426
if is_pkg:
2527
import_submodules(full_name)
2628

2729

28-
# TODO: Make this agnostic to the package name
29-
import_submodules("climate_ref_core")
30-
print(climate_ref_core.__version__)
30+
def main(package: str = typer.Argument(..., help="List of package names to test import for")):
31+
try:
32+
import_submodules(package)
33+
pkg = importlib.import_module(package)
34+
version = getattr(pkg, "__version__", "<no __version__>")
35+
print(f"{package} version: {version}")
36+
except Exception as e:
37+
print(f"Failed to import {package}: {e}")
38+
raise typer.Abort()
39+
40+
41+
if __name__ == "__main__":
42+
typer.run(main)

uv.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)