From db0ffdb1fe02528bf2b9ab4985c4e1ad5d762697 Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Mon, 30 Mar 2026 14:26:21 -0400 Subject: [PATCH] AI Code: implement create() for conda-project spec --- src/projspec/proj/base.py | 3 +++ src/projspec/proj/conda_project.py | 18 ++++++++++++++++++ tests/test_roundtrips.py | 1 + 3 files changed, 22 insertions(+) diff --git a/src/projspec/proj/base.py b/src/projspec/proj/base.py index 972cb7e..740cb11 100644 --- a/src/projspec/proj/base.py +++ b/src/projspec/proj/base.py @@ -77,6 +77,9 @@ def __init__( else: storage_options = fs.storage_options self.storage_options = storage_options or {} + assert ( + fs is not None + ) # guaranteed by the if/else above; url_to_fs lacks return annotation self.fs = fs self.url = path # this is the FS-specific variant self.specs = AttrDict() diff --git a/src/projspec/proj/conda_project.py b/src/projspec/proj/conda_project.py index 3d21290..0560e2c 100644 --- a/src/projspec/proj/conda_project.py +++ b/src/projspec/proj/conda_project.py @@ -1,3 +1,5 @@ +import os + import yaml from projspec.proj import ProjectSpec @@ -13,6 +15,22 @@ class CondaProject(ProjectSpec): # not a spec, but a howto: spec_doc = "https://conda-incubator.github.io/conda-project/tutorial.html" + @staticmethod + def _create(path: str) -> None: + name = os.path.basename(path) + env_file = "environment.yml" + with open(f"{path}/{env_file}", "wt") as f: + f.write("channels:\n - conda-forge\ndependencies:\n - python >=3.10\n") + with open(f"{path}/conda-project.yml", "wt") as f: + f.write( + f"name: {name}\n" + "environments:\n" + f" default:\n" + f" - {env_file}\n" + "variables: {}\n" + "commands: {}\n" + ) + def match(self) -> bool: # TODO: a .condarc or environment.yml file is actually enough, e.g., # https://github.com/conda-incubator/conda-project/tree/main/examples/condarc-settings diff --git a/tests/test_roundtrips.py b/tests/test_roundtrips.py index 38cc8e2..d485c49 100644 --- a/tests/test_roundtrips.py +++ b/tests/test_roundtrips.py @@ -30,6 +30,7 @@ "pixi", "uv", "briefcase", + "conda_project", ], ) def test_compliant(tmpdir, cls_name):