Skip to content

Commit a9b2d0c

Browse files
committed
create a ci environment.yml with python script
1 parent bcc3dea commit a9b2d0c

File tree

4 files changed

+115
-16
lines changed

4 files changed

+115
-16
lines changed

.github/make_ci_environ.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import tomllib
2+
from pathlib import Path
3+
import yaml
4+
import os
5+
6+
def parse_pyproject(path: str, optional_sections_to_skip=None):
7+
with open(path, "rb") as f:
8+
data = tomllib.load(f)
9+
10+
deps = set()
11+
12+
# project.dependencies (PEP 621)
13+
for dep in data.get("project", {}).get("dependencies", []):
14+
if "numpy" in dep:
15+
# numpy is also listed in build requirements with a higher version number
16+
# so we skip it here to avoid conflicts.
17+
continue
18+
deps.add(dep)
19+
20+
# optional dependencies (PEP 621)
21+
if optional_sections_to_skip is None:
22+
optional_sections_to_skip = []
23+
for group, group_deps in data.get("project", {}).get("optional-dependencies", {}).items():
24+
if group in optional_sections_to_skip:
25+
print("Skipping optional dependency group:", group)
26+
continue
27+
deps.update(group_deps)
28+
29+
deps.discard("geoana[all]")
30+
deps.discard("geoana[doc,all]")
31+
deps.discard("geoana[plot,extras,jittable]")
32+
33+
if "matplotlib" in deps:
34+
deps.remove("matplotlib")
35+
deps.add("matplotlib-base")
36+
return deps
37+
38+
def create_env_yaml(deps, name="env", python_version=None, free_threaded=False):
39+
conda_pkgs = []
40+
pip_pkgs = []
41+
42+
for dep in deps:
43+
# crude split: try to detect conda vs pip-only packages
44+
if any(dep.startswith(pip_only) for pip_only in ["git+", "http:", "https:", "file:"]):
45+
pip_pkgs.append(dep)
46+
else:
47+
conda_pkgs.append(dep)
48+
49+
dependencies = conda_pkgs
50+
if pip_pkgs:
51+
dependencies.append({"pip": pip_pkgs})
52+
53+
if python_version:
54+
if free_threaded:
55+
dependencies.insert(0, f"python-freethreading={python_version}")
56+
else:
57+
dependencies.insert(0, f"python={python_version}")
58+
59+
return {
60+
"name": name,
61+
"channels": ["conda-forge"],
62+
"dependencies": dependencies,
63+
}
64+
65+
if __name__ == "__main__":
66+
pyproject_path = Path("pyproject.toml")
67+
68+
py_vers = os.environ.get("PYTHON_VERSION", "3.11")
69+
mkl_vers = os.environ.get("MKL_VERSION", "2024")
70+
is_free_threaded = os.environ.get("FREE_THREADED", "false").lower() == "true"
71+
is_coverage = os.environ.get("DO_COVERAGE", "false").lower() == "true"
72+
env_name = os.environ.get("ENV_NAME", "pydiso-ci")
73+
74+
optional_to_skip = []
75+
if not is_coverage:
76+
optional_to_skip.append("coverage")
77+
78+
deps = parse_pyproject(pyproject_path, optional_sections_to_skip=optional_to_skip)
79+
deps.add("mkl-devel")
80+
deps.add("pkg-config")
81+
deps.add(f"mkl={mkl_vers}")
82+
env_data = create_env_yaml(deps, name=env_name, python_version=py_vers, free_threaded=is_free_threaded)
83+
84+
out_name = "environment_ci.yml"
85+
with open(out_name, "w") as f:
86+
yaml.safe_dump(env_data, f, sort_keys=False)
87+
88+
print("✅ Generated environment_ci.yml with", len(deps), "dependencies")

.github/workflows/python-package-conda.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
include:
2323
- os: ubuntu-latest
2424
python-version: "3.12"
25-
coverage: ${{ true }}
25+
coverage: true
2626
- os: macos-15-intel
2727
python-version: "3.11"
2828
mkl-version: "2023"
@@ -36,27 +36,35 @@ jobs:
3636
free-threaded: true
3737
- python-version: "3.12"
3838
free-threaded: true
39+
- python-version: "3.14"
40+
free-threaded: true
41+
mkl-version: "2025"
3942

4043
steps:
4144
- uses: actions/checkout@v5
4245
with:
4346
fetch-depth: 0
4447

48+
- name: Set up Python
49+
uses: actions/setup-python@v2
50+
with:
51+
python-version: "3.13"
52+
53+
- name: Create Conda environment file
54+
run: |
55+
python -m pip install pyyaml
56+
python .github/make_ci_environ.py
57+
env:
58+
PYTHON_VERSION: ${{ matrix.python-version}}
59+
MKL_VERSION: ${{ matrix.mkl-version }}
60+
FREE_THREADED: ${{ matrix.free-threaded && 'true' || 'false' }}
61+
DO_COVERAGE: ${{ matrix.coverage && 'true' || 'false' }}
62+
ENV_NAME: pydiso-ci
63+
4564
- name: Setup Conda
4665
uses: conda-incubator/setup-miniconda@v3
4766
with:
48-
channels: conda-forge, defaults
49-
channel-priority: true
50-
activate-environment: dev
51-
52-
- name: Create environment
53-
run: |
54-
conda install --quiet --yes -c conda-forge \
55-
${{ matrix.free-threaded && 'python-freethreading' || 'python' }}=${{ matrix.python-version }} \
56-
pip numpy scipy cython mkl=${{ matrix.mkl-version }} pytest \
57-
mkl-devel pkg-config meson-python meson ninja setuptools_scm \
58-
${{ matrix.coverage && 'coverage' || ''}} \
59-
${{ matrix.os == 'windows-latest' && '"libblas=*=*mkl"' || ''}}
67+
activate-environment: pydiso-ci
6068

6169
- name: Conda information
6270
run: |
@@ -71,8 +79,6 @@ jobs:
7179
${{ matrix.coverage && '--config-settings=setup-args="-Db_coverage=true"' || ''}} \
7280
${{ matrix.os == 'windows-latest' && '--config-settings=setup-args="-Dvsenv=true"' || ''}}
7381
74-
conda list
75-
7682
- name: Run Tests
7783
run: |
7884
${{ matrix.coverage && 'coverage run -m' || '' }} pytest -s -v

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ coverage.xml
1212
.idea/
1313

1414
.vscode/
15+
16+
environment_ci.yml

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ file = 'LICENSE'
5353
[project.optional-dependencies]
5454
test = [
5555
"pytest",
56-
"pytest-cov",
56+
]
57+
58+
coverage = [
59+
"coverage",
5760
]
5861

5962
build = [

0 commit comments

Comments
 (0)