Skip to content

Commit

Permalink
Merge pull request #297 from bollwyvl/gh-296-optional-gitpython
Browse files Browse the repository at this point in the history
make gitpython dependency optional
  • Loading branch information
mariusvniekerk committed Dec 15, 2022
2 parents 90b370a + 43b4947 commit dd529b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
20 changes: 16 additions & 4 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import datetime
import importlib.util
import logging
import os
import pathlib
Expand Down Expand Up @@ -823,10 +824,21 @@ def create_lockfile_from_spec(
else:
time_metadata = None

git_metadata = GitMeta.create(
metadata_choices=metadata_choices,
src_files=spec.sources,
)
if metadata_choices & {
MetadataOption.GitUserEmail,
MetadataOption.GitUserName,
MetadataOption.GitSha,
}:
if not importlib.util.find_spec("git"):
raise RuntimeError(
"The GitPython package is required to read Git metadata."
)
git_metadata = GitMeta.create(
metadata_choices=metadata_choices,
src_files=spec.sources,
)
else:
git_metadata = None

if metadata_choices & {MetadataOption.InputSha, MetadataOption.InputMd5}:
inputs_metadata: Optional[Dict[str, InputMeta]] = {
Expand Down
5 changes: 4 additions & 1 deletion conda_lock/src_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ def create(
metadata_choices: AbstractSet[MetadataOption],
src_files: List[pathlib.Path],
) -> "GitMeta | None":
import git
try:
import git
except ImportError:
return None

git_sha: "str | None" = None
git_user_name: "str | None" = None
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ mkdocs-click
mkdocs-include-markdown-plugin
flaky
docker
gitpython
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pyyaml >= 5.1
ruamel.yaml
tomli; python_version<"3.11"
typing-extensions
gitpython
toolz >=0.12.0,<1.0.0
# poetry:
cachecontrol[filecache] >=0.12.9
Expand Down Expand Up @@ -35,4 +34,4 @@ requests >=2.18
# poetry:
tomlkit >=0.7.0
# poetry:
virtualenv >=20.0.26
virtualenv >=20.0.26

0 comments on commit dd529b4

Please sign in to comment.