Skip to content

Commit

Permalink
use tomli for python<3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gboeing committed Feb 15, 2025
1 parent 0cfe2f4 commit edc6ad9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions environments/make-env-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from typing import Any

from packaging.requirements import Requirement
from tomllib import load as tomllib_load

try:
# for python >=3.11
from tomllib import load as toml_load
except ImportError:
# for python <3.11
from tomli import load as toml_load

# path to package's pyproject and the config json file
PYPROJECT_PATH = "./pyproject.toml"
Expand Down Expand Up @@ -60,14 +66,16 @@ def make_requirement(
return str(requirement)


def make_file(env: dict[str, Any]) -> None:
def make_file(env: dict[str, Any], pyproject: dict[str, Any]) -> None:
"""
Write a conda environment yaml file or pip requirements.txt file.
Parameters
----------
env
An environment configuration dictionary.
pyproject
A parsed pyproject.toml file's contents.
"""
depends_on = []
output_path = Path(env["output_path"])
Expand Down Expand Up @@ -117,10 +125,10 @@ def make_file(env: dict[str, Any]) -> None:
if __name__ == "__main__":
# load the pyproject.toml and the environments.json config files
with Path(PYPROJECT_PATH).open("rb") as f:
pyproject = tomllib_load(f)
pyproject = toml_load(f)
with Path(ENVS_CONFIG_PATH).open("rb") as f:
envs = json_load(f)

# make each environment/requirements file as configured
for env in envs:
make_file(env)
make_file(env, pyproject)
1 change: 1 addition & 0 deletions environments/requirements/requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ shapely>=2.0
sphinx-autodoc-typehints
sphinx>=7
statsmodels
tomli
twine
typeguard
validate-pyproject
1 change: 1 addition & 0 deletions environments/requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pre-commit
pytest
pytest-cov
typeguard
tomli
1 change: 1 addition & 0 deletions environments/tests/env-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
- shapely>=2.0
- sphinx-autodoc-typehints
- sphinx>=7
- tomli
- twine
- typeguard
- validate-pyproject
1 change: 1 addition & 0 deletions environments/tests/env-test-minimum-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dependencies:
- scikit-learn==0.23.*
- scipy==1.5.*
- shapely==2.0.*
- tomli
- typeguard
1 change: 1 addition & 0 deletions environments/tests/requirements-test-latest-deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ rio-vrt>=0.3
scikit-learn>=0.23
scipy>=1.5
shapely>=2.0
tomli
typeguard

0 comments on commit edc6ad9

Please sign in to comment.