Skip to content

Commit

Permalink
FIX: do not update Conda environment if not package (#261)
Browse files Browse the repository at this point in the history
* FIX: do not update Conda environment if not package
* FIX: do not update Jupyter if not package
  • Loading branch information
redeboer authored Jan 8, 2024
1 parent 60890a4 commit a872d4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/repoma/check_dev_files/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH
from repoma.utilities.project_info import PythonVersion, get_constraints_file
from repoma.utilities.project_info import (
PythonVersion,
get_constraints_file,
is_package,
)
from repoma.utilities.yaml import create_prettier_round_trip_yaml

if TYPE_CHECKING:
Expand All @@ -18,6 +22,8 @@
def main(python_version: PythonVersion) -> None:
if not CONFIG_PATH.conda.exists():
return
if not is_package():
return
yaml = create_prettier_round_trip_yaml()
conda_env: CommentedMap = yaml.load(CONFIG_PATH.conda)
conda_deps: CommentedSeq = conda_env.get("dependencies", [])
Expand Down
4 changes: 3 additions & 1 deletion src/repoma/check_dev_files/jupyter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Update the developer setup when using Jupyter notebooks."""

from repoma.utilities.executor import Executor
from repoma.utilities.project_info import get_supported_python_versions
from repoma.utilities.project_info import get_supported_python_versions, is_package
from repoma.utilities.pyproject import add_dependency


Expand All @@ -10,6 +10,8 @@ def main() -> None:


def _update_dev_requirements() -> None:
if not is_package():
return
if "3.6" in get_supported_python_versions():
return
hierarchy = ["jupyter", "dev"]
Expand Down
24 changes: 16 additions & 8 deletions src/repoma/utilities/project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,22 @@ def from_setup_cfg(cfg: ConfigParser) -> ProjectInfo:


def get_project_info(pyproject: TOMLDocument | None = None) -> ProjectInfo:
project_info = _load_project_info(pyproject)
if project_info is None or project_info.is_empty():
msg = f"No valid {CONFIG_PATH.setup_cfg} or {CONFIG_PATH.pyproject} found"
raise PrecommitError(msg)
return project_info


def _load_project_info(pyproject: TOMLDocument | None = None) -> ProjectInfo | None:
if pyproject is not None or os.path.exists(CONFIG_PATH.pyproject):
if pyproject is None:
pyproject = load_pyproject()
project_info = ProjectInfo.from_pyproject_toml(pyproject)
if not project_info.is_empty():
return project_info
return ProjectInfo.from_pyproject_toml(pyproject)
if os.path.exists(CONFIG_PATH.setup_cfg):
cfg = open_config(CONFIG_PATH.setup_cfg)
project_info = ProjectInfo.from_setup_cfg(cfg)
if not project_info.is_empty():
return project_info
msg = f"No valid {CONFIG_PATH.setup_cfg} or {CONFIG_PATH.pyproject} found"
raise PrecommitError(msg)
return ProjectInfo.from_setup_cfg(cfg)
return None


def _extract_python_versions(classifiers: list[str]) -> list[PythonVersion] | None:
Expand Down Expand Up @@ -167,3 +170,8 @@ def get_constraints_file(python_version: PythonVersion) -> Path | None:
if path.exists():
return path
return None


def is_package() -> bool:
project_info = _load_project_info()
return project_info is not None and not project_info.is_empty()

0 comments on commit a872d4f

Please sign in to comment.