Skip to content

Commit 4c43138

Browse files
authored
Merge pull request #77 from martindurant/conda-proj
AI Code: implement create() for conda-project spec
2 parents 912ebbf + db0ffdb commit 4c43138

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/projspec/proj/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def __init__(
7777
else:
7878
storage_options = fs.storage_options
7979
self.storage_options = storage_options or {}
80+
assert (
81+
fs is not None
82+
) # guaranteed by the if/else above; url_to_fs lacks return annotation
8083
self.fs = fs
8184
self.url = path # this is the FS-specific variant
8285
self.specs = AttrDict()

src/projspec/proj/conda_project.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import yaml
24

35
from projspec.proj import ProjectSpec
@@ -13,6 +15,22 @@ class CondaProject(ProjectSpec):
1315
# not a spec, but a howto:
1416
spec_doc = "https://conda-incubator.github.io/conda-project/tutorial.html"
1517

18+
@staticmethod
19+
def _create(path: str) -> None:
20+
name = os.path.basename(path)
21+
env_file = "environment.yml"
22+
with open(f"{path}/{env_file}", "wt") as f:
23+
f.write("channels:\n - conda-forge\ndependencies:\n - python >=3.10\n")
24+
with open(f"{path}/conda-project.yml", "wt") as f:
25+
f.write(
26+
f"name: {name}\n"
27+
"environments:\n"
28+
f" default:\n"
29+
f" - {env_file}\n"
30+
"variables: {}\n"
31+
"commands: {}\n"
32+
)
33+
1634
def match(self) -> bool:
1735
# TODO: a .condarc or environment.yml file is actually enough, e.g.,
1836
# https://github.com/conda-incubator/conda-project/tree/main/examples/condarc-settings

tests/test_roundtrips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"pixi",
3131
"uv",
3232
"briefcase",
33+
"conda_project",
3334
],
3435
)
3536
def test_compliant(tmpdir, cls_name):

0 commit comments

Comments
 (0)