-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from openscm/conda-install-tests
Add test conda install
- Loading branch information
Showing
7 changed files
with
208 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add test of installation from conda |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |