Skip to content

Commit

Permalink
Merge pull request #57 from openscm/conda-install-tests
Browse files Browse the repository at this point in the history
Add test conda install
  • Loading branch information
znicholls authored Oct 17, 2024
2 parents e0441a7 + ecc299e commit e6f8bd3
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 66 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/install-conda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Test installation of the latest version from conda/mamba works.
# We make sure that we run the tests that apply to the version we installed,
# rather than the latest tests in main.
# The reason we do this, is that we want this workflow to test
# that installing from PyPI/conda leads to a correct installation.
# If we tested against main, the tests could fail
# because the tests from main require the new features in main to pass.
name: Test installation conda

on:
workflow_dispatch:
schedule:
# * is a special character in YAML so you have to quote this string
# This means At 03:00 on Wednesday.
# see https://crontab.guru/#0_0_*_*_3
- cron: '0 3 * * 3'

jobs:
test-micromamba-installation:
name: Test (micro)mamba install ${{ matrix.install-target }} (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: "${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
# # There is an issue on windows, one for another day
# os: ["ubuntu-latest", "macos-latest", "windows-latest"]
os: ["ubuntu-latest", "macos-latest"]
python-version: [ "3.9", "3.10", "3.11" ]
# Check both the 'library' and the 'application' (i.e. locked package)
install-target: ["openscm-units", "openscm-units-locked"]

steps:
# While we wait for conda-forge release
# (https://github.com/conda-forge/staged-recipes/pull/26986)
# specify pins by hand
- name: Setup (micro)mamba and install package
uses: mamba-org/setup-micromamba@v1
with:
environment-name: test-mamba-install
create-args: >-
python=${{ matrix.python-version }}
-c conda-forge
${{ matrix.install-target }}
init-shell: bash
- name: Get version
shell: bash -leo pipefail {0}
run: |
INSTALLED_VERSION=`python -c 'import openscm_units; print(f"v{openscm_units.__version__}")'`
echo $INSTALLED_VERSION
echo "INSTALLED_VERSION=$INSTALLED_VERSION" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.INSTALLED_VERSION }}
- name: Test installation
shell: bash -leo pipefail {0}
run: |
which python
python scripts/test-install.py
- name: Install pytest and other test dependencies
shell: bash -leo pipefail {0}
run: |
micromamba install pytest pytest-regressions
- name: Run tests
shell: bash -leo pipefail {0}
run: |
pytest tests -r a -vv -s
60 changes: 0 additions & 60 deletions .github/workflows/install.yaml

This file was deleted.

1 change: 1 addition & 0 deletions changelog/57.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add test of installation from conda
53 changes: 48 additions & 5 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ dependencies = [
]
readme = "README.md"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

[build-system]
Expand Down Expand Up @@ -47,6 +53,8 @@ dev = [
"setuptools>=74.1.2",
"pip>=24.2",
"pandas-stubs>=2.2.2.240807",
"tomli>=2.0.2",
"typer>=0.12.5",
]
docs = [
"attrs>=24.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements-docs-locked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
tinycss2==1.3.0
tomli==2.0.2; python_version < "3.11"
tomli==2.0.2
tornado==6.4.1
traitlets==5.14.3
types-python-dateutil==2.9.0.20241003
Expand Down
83 changes: 83 additions & 0 deletions scripts/print-conda-recipe-pins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
Write out the pins for our conda recipe
These can be copy-pasted into the locked info at
https://github.com/conda-forge/openscm-units-feedstock/blob/main/recipe/meta.yaml
"""

from __future__ import annotations

import tomli
import typer
from attrs import define
from packaging.version import Version


@define
class VersionInfoHere:
"""Version info class for use in this script"""

name: str
min_pin: str
max_pin: str


def main() -> None:
"""
Write our docs environment file for Read the Docs
"""
PYPROJECT_TOML_FILE = "pyproject.toml"
REQUIREMENTS_LOCK_FILE = "requirements-locked.txt"

with open(PYPROJECT_TOML_FILE, "rb") as fh:
pyproject_toml = tomli.load(fh)

with open(REQUIREMENTS_LOCK_FILE) as fh:
requirements_info = fh.read().splitlines()

pypi_to_conda_name_map = {
"scitools-iris": "iris",
"cf-xarray": "cf_xarray",
"typing-extensions": "typing_extensions",
}
version_info_l = []
for dependency in pyproject_toml["project"]["dependencies"]:
package_name = (
dependency.split(">")[0].split("<")[0].split(">=")[0].split("<=")[0]
)

for line in requirements_info:
if line.startswith(package_name):
package_version_line = line
break
else:
msg = f"Didn't find pin information for {package_name}"
raise AssertionError(msg)

version = package_version_line.split("==")[-1]
vv = Version(version)
max_pin = f"{vv.major}.{vv.minor}.{vv.micro + 1}"

if package_name in pypi_to_conda_name_map:
conda_name = pypi_to_conda_name_map[package_name]
else:
conda_name = package_name

version_info_l.append(
VersionInfoHere(name=conda_name, min_pin=version, max_pin=max_pin)
)

print("Pins for library")
for vi in version_info_l:
print(f"- {vi.name}")

print("")
print("Pins for application")
for vi in version_info_l:
print(
f"- {{{{ pin_compatible('{vi.name}', min_pin='{vi.min_pin}', max_pin='{vi.max_pin}') }}}}" # noqa: E501
)


if __name__ == "__main__":
typer.run(main)

0 comments on commit e6f8bd3

Please sign in to comment.