Skip to content

Commit e6f8bd3

Browse files
authored
Merge pull request #57 from openscm/conda-install-tests
Add test conda install
2 parents e0441a7 + ecc299e commit e6f8bd3

File tree

7 files changed

+208
-66
lines changed

7 files changed

+208
-66
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Test installation of the latest version from conda/mamba 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/conda 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 conda
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-micromamba-installation:
20+
name: Test (micro)mamba install ${{ matrix.install-target }} (${{ matrix.python-version }}, ${{ matrix.os }})
21+
runs-on: "${{ matrix.os }}"
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
# # There is an issue on windows, one for another day
26+
# os: ["ubuntu-latest", "macos-latest", "windows-latest"]
27+
os: ["ubuntu-latest", "macos-latest"]
28+
python-version: [ "3.9", "3.10", "3.11" ]
29+
# Check both the 'library' and the 'application' (i.e. locked package)
30+
install-target: ["openscm-units", "openscm-units-locked"]
31+
32+
steps:
33+
# While we wait for conda-forge release
34+
# (https://github.com/conda-forge/staged-recipes/pull/26986)
35+
# specify pins by hand
36+
- name: Setup (micro)mamba and install package
37+
uses: mamba-org/setup-micromamba@v1
38+
with:
39+
environment-name: test-mamba-install
40+
create-args: >-
41+
python=${{ matrix.python-version }}
42+
-c conda-forge
43+
${{ matrix.install-target }}
44+
init-shell: bash
45+
- name: Get version
46+
shell: bash -leo pipefail {0}
47+
run: |
48+
INSTALLED_VERSION=`python -c 'import openscm_units; print(f"v{openscm_units.__version__}")'`
49+
echo $INSTALLED_VERSION
50+
echo "INSTALLED_VERSION=$INSTALLED_VERSION" >> $GITHUB_ENV
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
ref: ${{ env.INSTALLED_VERSION }}
55+
- name: Test installation
56+
shell: bash -leo pipefail {0}
57+
run: |
58+
which python
59+
python scripts/test-install.py
60+
- name: Install pytest and other test dependencies
61+
shell: bash -leo pipefail {0}
62+
run: |
63+
micromamba install pytest pytest-regressions
64+
- name: Run tests
65+
shell: bash -leo pipefail {0}
66+
run: |
67+
pytest tests -r a -vv -s

.github/workflows/install.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.

changelog/57.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add test of installation from conda

pdm.lock

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

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ dependencies = [
1919
]
2020
readme = "README.md"
2121
classifiers = [
22+
"Development Status :: 5 - Production/Stable",
23+
"Intended Audience :: Developers",
2224
"License :: OSI Approved :: BSD License",
25+
"Operating System :: OS Independent",
26+
"Programming Language :: Python :: 3.9",
27+
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
2329
]
2430

2531
[build-system]
@@ -47,6 +53,8 @@ dev = [
4753
"setuptools>=74.1.2",
4854
"pip>=24.2",
4955
"pandas-stubs>=2.2.2.240807",
56+
"tomli>=2.0.2",
57+
"typer>=0.12.5",
5058
]
5159
docs = [
5260
"attrs>=24.0.0",

requirements-docs-locked.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ soupsieve==2.6
122122
stack-data==0.6.3
123123
terminado==0.18.1
124124
tinycss2==1.3.0
125-
tomli==2.0.2; python_version < "3.11"
125+
tomli==2.0.2
126126
tornado==6.4.1
127127
traitlets==5.14.3
128128
types-python-dateutil==2.9.0.20241003

scripts/print-conda-recipe-pins.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""
2+
Write out the pins for our conda recipe
3+
4+
These can be copy-pasted into the locked info at
5+
https://github.com/conda-forge/openscm-units-feedstock/blob/main/recipe/meta.yaml
6+
"""
7+
8+
from __future__ import annotations
9+
10+
import tomli
11+
import typer
12+
from attrs import define
13+
from packaging.version import Version
14+
15+
16+
@define
17+
class VersionInfoHere:
18+
"""Version info class for use in this script"""
19+
20+
name: str
21+
min_pin: str
22+
max_pin: str
23+
24+
25+
def main() -> None:
26+
"""
27+
Write our docs environment file for Read the Docs
28+
"""
29+
PYPROJECT_TOML_FILE = "pyproject.toml"
30+
REQUIREMENTS_LOCK_FILE = "requirements-locked.txt"
31+
32+
with open(PYPROJECT_TOML_FILE, "rb") as fh:
33+
pyproject_toml = tomli.load(fh)
34+
35+
with open(REQUIREMENTS_LOCK_FILE) as fh:
36+
requirements_info = fh.read().splitlines()
37+
38+
pypi_to_conda_name_map = {
39+
"scitools-iris": "iris",
40+
"cf-xarray": "cf_xarray",
41+
"typing-extensions": "typing_extensions",
42+
}
43+
version_info_l = []
44+
for dependency in pyproject_toml["project"]["dependencies"]:
45+
package_name = (
46+
dependency.split(">")[0].split("<")[0].split(">=")[0].split("<=")[0]
47+
)
48+
49+
for line in requirements_info:
50+
if line.startswith(package_name):
51+
package_version_line = line
52+
break
53+
else:
54+
msg = f"Didn't find pin information for {package_name}"
55+
raise AssertionError(msg)
56+
57+
version = package_version_line.split("==")[-1]
58+
vv = Version(version)
59+
max_pin = f"{vv.major}.{vv.minor}.{vv.micro + 1}"
60+
61+
if package_name in pypi_to_conda_name_map:
62+
conda_name = pypi_to_conda_name_map[package_name]
63+
else:
64+
conda_name = package_name
65+
66+
version_info_l.append(
67+
VersionInfoHere(name=conda_name, min_pin=version, max_pin=max_pin)
68+
)
69+
70+
print("Pins for library")
71+
for vi in version_info_l:
72+
print(f"- {vi.name}")
73+
74+
print("")
75+
print("Pins for application")
76+
for vi in version_info_l:
77+
print(
78+
f"- {{{{ pin_compatible('{vi.name}', min_pin='{vi.min_pin}', max_pin='{vi.max_pin}') }}}}" # noqa: E501
79+
)
80+
81+
82+
if __name__ == "__main__":
83+
typer.run(main)

0 commit comments

Comments
 (0)