Skip to content

Commit

Permalink
shrink doc dep environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jun 13, 2024
1 parent f333534 commit add95bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/doc-dep-constraints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- pytorch-cpu
- nomkl
4 changes: 3 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ dependencies:
- sphinxcontrib-bibtex >=2.0
- sphinx_rtd_theme >=0.5
- myst-nb >=0.13
- pandas <3,>=1.5
- pytorch-cpu
- nomkl
- pandas >=1.5,<3
- numpy >=1.23
- scipy >=1.9.0
- pytorch >=2.1,<3
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ preview-docs:
# update the environment file used to install documentation
update-doc-env:
pipx run ./utils/conda-tool.py --env -o docs/environment.yml \
-e all requirements-doc.txt \
-e all requirements-doc.txt docs/doc-dep-constraints.yml \
{{ append('/pyproject.toml', PACKAGES) }}


Expand Down
19 changes: 16 additions & 3 deletions utils/conda-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
class ParsedReq(NamedTuple):
source: Path
name: str
requirement: Optional[Requirement]
conda: Optional[tuple[str, Optional[str]]]
force_pip: bool
requirement: Optional[Requirement] = None
conda: Optional[tuple[str, Optional[str]]] = None
force_pip: bool = False

def conda_spec(self) -> str | None:
name = None
Expand Down Expand Up @@ -144,6 +144,8 @@ def load_reqfiles(files: Iterable[Path | str]) -> Iterator[ParsedReq]:
def load_requirements(file: Path) -> list[ParsedReq]:
if file.name == "pyproject.toml":
return load_req_toml(file)
elif re.match(r".*\.ya?ml$", file.name):
return load_conda_yml(file)
else:
return load_req_txt(file)

Expand Down Expand Up @@ -186,6 +188,17 @@ def array_lines(tbl: tomlkit.items.Array):
yield text


def load_conda_yml(file: Path) -> list[ParsedReq]:
_log.info("loading Conda environment file %s", file)
with file.open("rt") as yf:
data = yaml.safe_load(yf)
deps: list[ParsedReq] = []
for dep in data["dependencies"]:
name, ver = parse_conda_spec(dep)
deps.append(ParsedReq(file, name, conda=(name, ver)))
return deps


def load_req_txt(file: Path) -> list[ParsedReq]:
_log.info("loading requirements file %s", file)
text = file.read_text()
Expand Down

0 comments on commit add95bd

Please sign in to comment.