Skip to content

Commit

Permalink
support lock to yaml (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle authored Jan 29, 2024
1 parent 486361a commit 98166d6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-locks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ jobs:
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
with:
token: ${{ steps.generate-token.outputs.token }}
add-paths: ${{ github.workspace }}/requirements/locks/*.txt
add-paths: |
${{ github.workspace }}/requirements/locks/*.txt
${{ github.workspace }}/requirements/locks/*.yml
commit-message: "updated conda lock files"
branch: conda-lock-auto-update
delete-branch: true
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ prune .github
prune .tox
prune docs
prune requirements
recursive-include requirements pypi-*.txt
recursive-include requirements *
recursive-include src *.md *.py *.pyi *.rst *.txt
prune tests

Expand Down
4 changes: 3 additions & 1 deletion requirements/locks/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ⚠️

This directory contains auto-generated `conda-lock` environment files for each `python` distribution supported by `geovista`.
This directory contains auto-generated `conda-lock` (`*.txt`) environment files for each `python` distribution supported by `geovista`.

An equivalent explicit YAML (`*.yml`) file is also generated for each `python` distribution.

Please **do not** manually edit these files as they will be overwritten by the `ci-locks` GHA CI workflow.
34 changes: 34 additions & 0 deletions requirements/locks/lock2yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# Copyright (c) 2021, GeoVista Contributors.
#
# This file is part of GeoVista and is distributed under the 3-Clause BSD license.
# See the LICENSE file in the package root directory for licensing details.

"""Convert a lock file to a YAML file."""
from __future__ import annotations

from pathlib import Path
import sys

from jinja2 import Environment, FileSystemLoader, select_autoescape

if (nargv := (len(sys.argv) - 1)) != 1:
emsg = f"Expect 'environment-name' as a single argument to '{sys.argv[0]}' script."
raise ValueError(emsg)

environment = Environment(
autoescape=select_autoescape(), loader=FileSystemLoader("templates/")
)
template = environment.get_template("lock2yaml.txt")

# default to linux-64 only
env = sys.argv[1]
lock = f"{env}-linux-64.txt"
name = f"geovista-{env}"
yaml = f"{env}-linux-64.yml"

with Path.open(lock) as fin:
content = template.render(file=fin, name=name)

with Path.open(yaml, mode="w", encoding="utf-8") as fout:
fout.write(content)
9 changes: 9 additions & 0 deletions requirements/locks/templates/lock2yaml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: {{ name }}

channels:
- conda-forge

dependencies:
{%- for line in file if not (line.startswith("#") or line.startswith("@")) %}
- {{ line|trim }}
{%- endfor %}
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ conda_create_args =
--override-channels
conda_deps =
conda-lock
jinja2
mamba
pip
description =
Expand All @@ -33,7 +34,8 @@ commands =
python -c 'from sys import version_info as v; open("{env:WORK}", "a").write(f"\n - python =\{v.major\}.\{v.minor\}\n{env:VTK_BUILD:}")'
# resolve the dependencies
conda-lock --mamba --channel conda-forge --kind explicit --file {env:WORK} --platform linux-64 --filename-template "{envname}-\{platform\}.txt"

# convert lock to explicit yaml
python lock2yaml.py {envname}

[testenv:py{310,311,312}-env]
conda_spec =
Expand Down

0 comments on commit 98166d6

Please sign in to comment.