Simplify relative path handling
@@ -46,20 +46,19 @@ def freeze(env_file, frozen_file):
Result will be stored in frozen_file
"""
frozen_dest = HERE / frozen_file
+
if frozen_dest.exists():
with frozen_dest.open('r') as f:
line = f.readline()
if 'GENERATED' not in line:
- print(f"{frozen_file} not autogenerated, not refreezing")
+ print(f"{frozen_file.relative_to(HERE)} not autogenerated, not refreezing")
return
print(f"Freezing {env_file} -> {frozen_file}")
with frozen_dest.open('w') as f:
- f.write(f"# AUTO GENERATED FROM {env_file}, DO NOT MANUALLY MODIFY\n")
+ f.write(f"# AUTO GENERATED FROM {env_file.relative_to(HERE)}, DO NOT MANUALLY MODIFY\n")
f.write(f"# Frozen on {datetime.utcnow():%Y-%m-%d %H:%M:%S UTC}\n")
- env_file_in_container = env_file.relative_to(HERE)
- frozen_file_in_container = frozen_file.relative_to(HERE)
check_call([
'docker',
'run',
@@ -73,11 +72,11 @@ def freeze(env_file, frozen_file):
f"conda install -yq conda={CONDA_VERSION}",
'conda config --add channels conda-forge',
'conda config --system --set auto_update_conda false',
- f"conda env create -v -f /r2d/{env_file_in_container} -n r2d",
+ f"conda env create -v -f /r2d/{env_file.relative_to(HERE)} -n r2d",
# add conda-forge broken channel as lowest priority in case
# any of our frozen packages are marked as broken after freezing
'conda config --append channels conda-forge/label/broken',
- f"conda env export -n r2d >> /r2d/{frozen_file_in_container}",
+ f"conda env export -n r2d >> /r2d/{frozen_file.relative_to(HERE)}",
])
])
@@ -102,7 +101,7 @@ def set_python(py_env_file, py):
raise ValueError(f"python dependency not found in {env['dependencies']}")
# update python dependency
with open(py_env_file, 'w') as f:
- f.write(f"# AUTO GENERATED FROM {ENV_FILE}, DO NOT MANUALLY MODIFY\n")
+ f.write(f"# AUTO GENERATED FROM {ENV_FILE.relative_to(HERE)}, DO NOT MANUALLY MODIFY\n")
f.write(f"# Generated on {datetime.utcnow():%Y-%m-%d %H:%M:%S UTC}\n")
yaml.dump(env, f)
