Skip to content

Commit 5438b95

Browse files
Copilotilaflott
andauthored
Fix create_test_conda_env: isolate version, add submodules, fix tests
- Move __version__ to _version.py to avoid importing cmor during pip build - Update pyproject.toml to read version from fremorizer._version - Add submodules: recursive to checkout step in workflow - Add nccmp to environment.yaml (needed by tests) - Fix test_find_statics_file_success to use tmp_path (avoid test pollution) - Fix test_setup_fre_cmor_run_subtool to create output directory Agent-Logs-Url: https://github.com/ilaflott/fremorizer/sessions/9d29eafc-3795-4808-ba85-95ab00fa460f Co-authored-by: ilaflott <6273252+ilaflott@users.noreply.github.com>
1 parent 1a34a0a commit 5438b95

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

.github/workflows/create_test_conda_env.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout Files
2222
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
2325

2426
- name: Setup Conda
2527
uses: conda-incubator/setup-miniconda@v3

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dependencies:
1313
- conda-forge::pytest
1414
- conda-forge::pytest-cov
1515
- conda-forge::pylint
16+
- conda-forge::nccmp

fremorizer/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"""
44

55
import logging
6-
import os
7-
version = os.getenv("GIT_DESCRIBE_TAG", "2026.01.alpha1")
8-
__version__ = version
6+
7+
from ._version import __version__, version
98

109
fre_logger = logging.getLogger(__name__)
1110

fremorizer/_version.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
version info for fremorizer, isolated to avoid importing heavy dependencies at build time
3+
"""
4+
5+
import os
6+
version = os.getenv("GIT_DESCRIBE_TAG", "2026.01.alpha1")
7+
__version__ = version

fremorizer/tests/test_cmor_helpers.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@ def test_iso_to_bronx_chunk():
2121
match='problem with converting to bronx chunk from the cmor chunk. check cmor_yamler.py'):
2222
iso_to_bronx_chunk('foo')
2323

24-
def test_find_statics_file_success():
24+
def test_find_statics_file_success(tmp_path):
2525
''' what happens when no statics file is found given a bronx directory structure '''
26-
target_file = 'fremorizer/tests/test_files/ascii_files/mock_archive/' + \
27-
'USER/CMIP7/ESM4/DEV/ESM4.5v01_om5b04_piC/' + \
28-
'gfdl.ncrc5-intel23-prod-openmp/pp/ocean_monthly/ts/monthly/5yr/ocean_monthly.000101-000102.sos.nc'
29-
if not Path(target_file).exists():
30-
Path(target_file).touch()
31-
assert Path(target_file).exists()
32-
33-
expected_answer_statics_file = 'fremorizer/tests/test_files/ascii_files/mock_archive/' + \
34-
'USER/CMIP7/ESM4/DEV/ESM4.5v01_om5b04_piC/' + \
35-
'gfdl.ncrc5-intel23-prod-openmp/pp/ocean_monthly/ocean_monthly.static.nc'
36-
if not Path(expected_answer_statics_file).exists():
37-
Path(expected_answer_statics_file).touch()
38-
assert Path(expected_answer_statics_file).exists
39-
40-
statics_file = find_statics_file( bronx_file_path = target_file
41-
)
26+
mock_root = tmp_path / 'mock_archive'
27+
bronx_subpath = ('USER/CMIP7/ESM4/DEV/ESM4.5v01_om5b04_piC/'
28+
'gfdl.ncrc5-intel23-prod-openmp/pp/ocean_monthly')
29+
30+
target_file = mock_root / bronx_subpath / 'ts/monthly/5yr/ocean_monthly.000101-000102.sos.nc'
31+
target_file.parent.mkdir(parents=True, exist_ok=True)
32+
target_file.touch()
33+
assert target_file.exists()
34+
35+
expected_answer_statics_file = mock_root / bronx_subpath / 'ocean_monthly.static.nc'
36+
expected_answer_statics_file.parent.mkdir(parents=True, exist_ok=True)
37+
expected_answer_statics_file.touch()
38+
assert expected_answer_statics_file.exists()
39+
40+
statics_file = find_statics_file( bronx_file_path = str(target_file) )
4241
assert Path(statics_file).exists()
43-
assert statics_file == expected_answer_statics_file
42+
assert statics_file == str(expected_answer_statics_file)
4443

4544

4645
def test_find_statics_file_nothing_found():

fremorizer/tests/test_cmor_run_subtool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def test_setup_fre_cmor_run_subtool(capfd):
6868
ncgen_input = f"{ROOTDIR}/reduced_ascii_files/{FILENAME}.cdl"
6969
ncgen_output = f"{ROOTDIR}/ocean_sos_var_file/{FILENAME}.nc"
7070

71+
Path(ncgen_output).parent.mkdir(parents=True, exist_ok=True)
7172
if Path(ncgen_output).exists():
7273
Path(ncgen_output).unlink()
7374
assert Path(ncgen_input).exists()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dynamic = [
4141

4242

4343
[tool.setuptools.dynamic]
44-
version = {attr = "fremorizer.__version__"}
44+
version = {attr = "fremorizer._version.__version__"}
4545

4646

4747
[project.scripts]

0 commit comments

Comments
 (0)