From a872d4febb43a7e9f3cd59a409be4b9eab45a9c8 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:14:37 +0100 Subject: [PATCH] FIX: do not update Conda environment if not package (#261) * FIX: do not update Conda environment if not package * FIX: do not update Jupyter if not package --- src/repoma/check_dev_files/conda.py | 8 +++++++- src/repoma/check_dev_files/jupyter.py | 4 +++- src/repoma/utilities/project_info.py | 24 ++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/repoma/check_dev_files/conda.py b/src/repoma/check_dev_files/conda.py index e5e10c71..a76f7e22 100644 --- a/src/repoma/check_dev_files/conda.py +++ b/src/repoma/check_dev_files/conda.py @@ -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: @@ -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", []) diff --git a/src/repoma/check_dev_files/jupyter.py b/src/repoma/check_dev_files/jupyter.py index 9061165a..cd10b370 100644 --- a/src/repoma/check_dev_files/jupyter.py +++ b/src/repoma/check_dev_files/jupyter.py @@ -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 @@ -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"] diff --git a/src/repoma/utilities/project_info.py b/src/repoma/utilities/project_info.py index d85bf4f0..5520a130 100644 --- a/src/repoma/utilities/project_info.py +++ b/src/repoma/utilities/project_info.py @@ -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: @@ -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()