From 7f4d3d8130203d62cbb2d2c4da3b23c3d15633b7 Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 13:21:12 -0700 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20universal=20locks=20across=20en?= =?UTF-8?q?vironments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hatch_pip_compile/exceptions.py | 15 ++ hatch_pip_compile/header.py | 83 +++++++++++ hatch_pip_compile/plugin.py | 136 +++++++++++------- pyproject.toml | 1 - requirements.txt | 42 +++--- requirements/requirements-docs.txt | 221 +++++++++++++++++++++++++++-- 6 files changed, 418 insertions(+), 80 deletions(-) create mode 100644 hatch_pip_compile/exceptions.py create mode 100644 hatch_pip_compile/header.py diff --git a/hatch_pip_compile/exceptions.py b/hatch_pip_compile/exceptions.py new file mode 100644 index 0000000..6f58fb6 --- /dev/null +++ b/hatch_pip_compile/exceptions.py @@ -0,0 +1,15 @@ +""" +hatch-pip-compile exceptions +""" + + +class HatchPipCompileError(Exception): + """ + Base exception for hatch-pip-compile + """ + + +class LockFileNotFoundError(HatchPipCompileError, FileNotFoundError): + """ + A lock file was not found + """ diff --git a/hatch_pip_compile/header.py b/hatch_pip_compile/header.py new file mode 100644 index 0000000..01bf332 --- /dev/null +++ b/hatch_pip_compile/header.py @@ -0,0 +1,83 @@ +""" +hatch-pip-compile header operations +""" + +import pathlib +import re +from dataclasses import dataclass +from textwrap import dedent +from typing import List, Optional + +from hatch.env.virtual import VirtualEnv +from packaging.version import Version + + +@dataclass +class PipCompileHeader: + """ + Header Metadata + """ + + lock_file: pathlib.Path + dependencies: List[str] + project_root: pathlib.Path + constraints_file: Optional[pathlib.Path] + env_name: str + project_name: str + virtualenv: Optional[VirtualEnv] = None + + def write_header(self) -> None: + """ + Post process lockfile + """ + version = f"{self.python_version.major}.{self.python_version.minor}" + raw_prefix = f""" + # + # This file is autogenerated by hatch-pip-compile with Python {version} + # + """ + prefix = dedent(raw_prefix).strip() + joined_dependencies = "\n".join([f"# - {dep}" for dep in self.dependencies]) + lockfile_text = self.lock_file.read_text() + cleaned_input_file = re.sub( + rf"-r \S*/{self.env_name}\.in", + f"hatch.envs.{self.env_name}", + lockfile_text, + ) + if self.constraints_file is not None: + constraints_path = self.constraints_file.relative_to(self.project_root) + constraints_line = f"# [constraints] {constraints_path}" + joined_dependencies = "\n".join([constraints_line, "#", joined_dependencies]) + cleaned_input_file = re.sub( + r"-c \S*", + f"-c {constraints_path}", + cleaned_input_file, + ) + prefix += "\n" + joined_dependencies + "\n#" + new_text = prefix + "\n\n" + cleaned_input_file + self.lock_file.write_text(new_text) + + def read_requirements(self) -> List[str]: + """ + Read requirements from lock file + """ + lock_file_text = self.lock_file.read_text() + parsed_requirements = [] + for line in lock_file_text.splitlines(): + if line.startswith("# - "): + rest_of_line = line[4:] + parsed_requirements.append(rest_of_line) + elif not line.startswith("#"): + break + return parsed_requirements + + @property + def python_version(self) -> Version: + """ + Get python version + """ + if self.virtualenv is not None: + return Version(self.virtualenv.environment["python_version"]) + else: + msg = "VirtualEnv is not set" + raise NotImplementedError(msg) diff --git a/hatch_pip_compile/plugin.py b/hatch_pip_compile/plugin.py index 466a613..bfdc4f3 100644 --- a/hatch_pip_compile/plugin.py +++ b/hatch_pip_compile/plugin.py @@ -6,12 +6,14 @@ import pathlib import re import tempfile -from textwrap import dedent -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional from hatch.env.virtual import VirtualEnvironment from packaging.version import Version +from hatch_pip_compile.exceptions import HatchPipCompileError, LockFileNotFoundError +from hatch_pip_compile.header import PipCompileHeader + logger = logging.getLogger(__name__) @@ -22,6 +24,8 @@ class PipCompileEnvironment(VirtualEnvironment): PLUGIN_NAME = "pip-compile" + _default_env_name = "default" + def __init__(self, *args, **kwargs): """ Initialize PipCompileEnvironment with extra attributes @@ -29,14 +33,26 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) lock_filename_config = self.config.get("lock-filename") if lock_filename_config is None: - if self.name == "default": + if self.name == self._default_env_name: lock_filename = "requirements.txt" else: lock_filename = f"requirements/requirements-{self.name}.txt" else: with self.metadata.context.apply_context(self.context): lock_filename = self.metadata.context.format(lock_filename_config) + self._piptools_detached_mode: bool = ( + self.metadata.hatch.config.get("envs", {}).get(self.name, {}).get("detached", False) + ) self._piptools_lock_file = self.root / lock_filename + self._piptools_header = PipCompileHeader( + lock_file=self._piptools_lock_file, + dependencies=self.dependencies, + virtualenv=self.virtual_env, + constraints_file=self._piptools_constraints_file, + project_root=self.root, + env_name=self.name, + project_name=self.metadata.name, + ) @staticmethod def get_option_types() -> Dict[str, Any]: @@ -77,6 +93,8 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa """ if self._piptools_lock_file.exists() is True: correct_environment = self._lock_file_compare() + if correct_environment is True and self._piptools_constraints_file is not None: + correct_environment = self._piptools_default_environment._lock_file_compare() if correct_environment is True: return cmd = [ @@ -97,10 +115,13 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa ] if self.config.get("pip-compile-hashes", True) is True: cmd.append("--generate-hashes") + + if self._piptools_constraints_file is not None: + cmd.extend(["--constraint", str(self._piptools_constraints_file)]) cmd.extend(self.config.get("pip-compile-args", [])) cmd.append(str(input_file)) self.virtual_env.platform.check_command(cmd) - self._post_process_lockfile() + self._piptools_header.write_header() def _pip_compile_cli(self) -> None: """ @@ -121,7 +142,7 @@ def _pip_sync_cli(self) -> None: """ Run pip-sync """ - _ = self._compare_python_versions() + self._compare_python_versions() cmd = [ self.virtual_env.python_info.executable, "-m", @@ -170,62 +191,20 @@ def sync_dependencies(self): """ self._hatch_pip_compile_install() - def _post_process_lockfile(self) -> None: - """ - Post process lockfile - """ - python_version = self._get_python_version() - version = f"{python_version.major}.{python_version.minor}" - joined_dependencies = "\n # - ".join(self.dependencies) - prefix = f""" - # - # This file is autogenerated by hatch-pip-compile with Python {version} - # - # - {joined_dependencies} - # - """ - lockfile_text = self._piptools_lock_file.read_text() - new_data = re.sub( - rf"-r \S*/{self.name}\.in", - f"hatch.envs.{self.name}", - lockfile_text, - ) - new_text = dedent(prefix).strip() + "\n\n" + new_data - self._piptools_lock_file.write_text(new_text) - def _lock_file_compare(self) -> bool: """ Compare lock file """ - lock_file_text = self._piptools_lock_file.read_text() - parsed_requirements = [] - for line in lock_file_text.splitlines(): - if line.startswith("# - "): - rest_of_line = line[4:] - parsed_requirements.append(rest_of_line) - elif not line.startswith("#"): - break + parsed_requirements = self._piptools_header.read_requirements() expected_output = "\n".join([*parsed_requirements, ""]) new_output = "\n".join([*self.dependencies, ""]) return expected_output == new_output - def _get_python_version(self) -> Version: - """ - Get python version - """ - python_version_output = self.virtual_env.platform.check_command( - [self.virtual_env.python_info.executable, "--version"], - capture_output=True, - ) - version_str = python_version_output.stdout.decode("utf-8").strip() - version_number = version_str.split(" ")[1] - return Version(version_number) - def _compare_python_versions(self) -> bool: """ Compare python versions """ - current_version = self._get_python_version() + current_version = Version(self.virtual_env.environment["python_version"]) lock_file_text = self._piptools_lock_file.read_text() match = re.search( r"# This file is autogenerated by hatch-pip-compile with Python (.*)", lock_file_text @@ -247,3 +226,62 @@ def _compare_python_versions(self) -> bool: ) return False return True + + @property + def _piptools_constraints_file(self) -> Optional[pathlib.Path]: + """ + Get default lock file + """ + if self.name == self._default_env_name: + constraints_file = None + else: + default_config = self.metadata.hatch.config.get("envs", {}).get( + self._default_env_name, {} + ) + if default_config.get("type") != self.PLUGIN_NAME: + constraints_file = None + elif self._piptools_detached_mode is True: + constraints_file = None + else: + constraints_file = self._piptools_default_environment._piptools_lock_file + self._validate_default_lock(constraints_file=constraints_file) + return constraints_file + + @property + def _piptools_default_environment(self) -> "PipCompileEnvironment": + """ + Get default pip compile environment + """ + default_env = PipCompileEnvironment( + root=self.root, + metadata=self.metadata, + name=self._default_env_name, + config=self.metadata.hatch.config["envs"].get(self._default_env_name, {}), + matrix_variables=self.matrix_variables, + data_directory=self.data_directory, + isolated_data_directory=self.isolated_data_directory, + platform=self.platform, + verbosity=self.verbosity, + app=self.app, + ) + return default_env + + def _validate_default_lock(self, constraints_file: Optional[pathlib.Path]) -> None: + """ + Validate the default lock file + """ + if constraints_file is None: + return + elif not constraints_file.exists(): + error_message = ( + f"[hatch-pip-compile] The default lock file {constraints_file} does not exist." + ) + raise LockFileNotFoundError(error_message) + else: + up_to_date = self._piptools_default_environment._lock_file_compare() + if up_to_date is False: + error_message = ( + f"[hatch-pip-compile] The default lock file {constraints_file} is out of date. " + "Please update it." + ) + raise HatchPipCompileError(error_message) diff --git a/pyproject.toml b/pyproject.toml index df0dd22..f2c09ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,6 @@ dependencies = [ "mkdocstrings~=0.22.0", "markdown-exec[ansi]~=1.6.0" ] -detached = true type = "pip-compile" [tool.hatch.envs.docs.scripts] diff --git a/requirements.txt b/requirements.txt index 6b393eb..87ee779 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,9 +4,9 @@ # - hatch # -anyio==4.0.0 \ - --hash=sha256:cfdb2b588b9fc25ede96d8db56ed50848b0b649dca3dd1df0b11f683bb9e0b5f \ - --hash=sha256:f7ed51751b2c2add651e5747c891b47e26d2a21be5d32d9311dfe9692f3e5d7a +anyio==4.1.0 \ + --hash=sha256:56a415fbc462291813a94528a779597226619c8e78af7de0507333f700011e5f \ + --hash=sha256:5a0bec7085176715be77df87fc66d6c9d70626bd752fcc85f57cdbee5b3760da # via httpx certifi==2023.11.17 \ --hash=sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1 \ @@ -127,17 +127,17 @@ httpcore==1.0.2 \ --hash=sha256:096cc05bca73b8e459a1fc3dcf585148f63e534eae4339559c9b8a8d6399acc7 \ --hash=sha256:9fc092e4799b26174648e54b74ed5f683132a464e95643b226e00c2ed2fa6535 # via httpx -httpx==0.25.1 \ - --hash=sha256:fec7d6cc5c27c578a391f7e87b9aa7d3d8fbcd034f6399f9f79b45bcc12a866a \ - --hash=sha256:ffd96d5cf901e63863d9f1b4b6807861dbea4d301613415d9e6e57ead15fc5d0 +httpx==0.25.2 \ + --hash=sha256:8b8fcaa0c8ea7b05edd69a094e63a2094c4efcb48129fb757361bc423c0ad9e8 \ + --hash=sha256:a05d3d052d9b2dfce0e3896636467f8a5342fb2b902c819428e1ac65413ca118 # via hatch hyperlink==21.0.0 \ --hash=sha256:427af957daa58bc909471c6c40f74c5450fa123dd093fc53efd2e91d2705a56b \ --hash=sha256:e6b14c37ecb73e89c77d78cdb4c2cc8f3fb59a885c5b3f819ff4ed80f25af1b4 # via hatch -idna==3.4 \ - --hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \ - --hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2 +idna==3.5 \ + --hash=sha256:27009fe2735bf8723353582d48575b23c533cc2c2de7b5a68908d91b5eb18d08 \ + --hash=sha256:79b8f0ac92d2351be5f6122356c9a592c96d81c9a79e4b488bf2a6a15f88057a # via # anyio # httpx @@ -186,9 +186,9 @@ pexpect==4.8.0 \ --hash=sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937 \ --hash=sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c # via hatch -platformdirs==3.11.0 \ - --hash=sha256:cf8ee52a3afdb965072dcc652433e0c7e3e40cf5ea1477cd4b3b1d2eb75495b3 \ - --hash=sha256:e9d171d00af68be50e9202731309c4e658fd8bc76f55c11c7dd760d023bda68e +platformdirs==4.0.0 \ + --hash=sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b \ + --hash=sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731 # via # hatch # virtualenv @@ -204,9 +204,9 @@ pycparser==2.21 \ --hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \ --hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206 # via cffi -pygments==2.17.1 \ - --hash=sha256:1b37f1b1e1bff2af52ecaf28cc601e2ef7077000b227a0675da25aef85784bc4 \ - --hash=sha256:e45a0e74bf9c530f564ca81b8952343be986a29f6afe7f5ad95c5f06b7bdf5e8 +pygments==2.17.2 \ + --hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \ + --hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367 # via rich pyperclip==1.8.2 \ --hash=sha256:105254a8b04934f0bc84e9c24eb360a591aaf6535c9def5f29d92af107a9bf57 @@ -237,17 +237,17 @@ tomlkit==0.12.3 \ --hash=sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4 \ --hash=sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba # via hatch -trove-classifiers==2023.11.14 \ - --hash=sha256:2893a80cf3c48645462dea97c72c02a9fb1f7bd3c65f9908d3ffb1a7ef0b3833 \ - --hash=sha256:64b5e78305a5de347f2cd7ec8c12d704a3ef0cb85cc10c0ca5f73488d1c201f8 +trove-classifiers==2023.11.22 \ + --hash=sha256:533df77e284fd645d90deeafd3ef710d290884efafe4f5009aa1663f95aec992 \ + --hash=sha256:c31a7e92f965f060a244b57d8ed5ee6f53fcb413ee17ce790e00577cb369ad99 # via hatchling userpath==1.9.1 \ --hash=sha256:ce8176728d98c914b6401781bf3b23fccd968d1647539c8788c7010375e02796 \ --hash=sha256:e085053e5161f82558793c41d60375289efceb4b77d96033ea9c84fc0893f772 # via hatch -virtualenv==20.24.6 \ - --hash=sha256:02ece4f56fbf939dbbc33c0715159951d6bf14aaf5457b092e4548e1382455af \ - --hash=sha256:520d056652454c5098a00c0f073611ccbea4c79089331f60bf9d7ba247bb7381 +virtualenv==20.24.7 \ + --hash=sha256:69050ffb42419c91f6c1284a7b24e0475d793447e35929b488bf6a0aade39353 \ + --hash=sha256:a18b3fd0314ca59a2e9f4b556819ed07183b3e9a3702ecfe213f593d44f7b3fd # via hatch zipp==3.17.0 \ --hash=sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31 \ diff --git a/requirements/requirements-docs.txt b/requirements/requirements-docs.txt index f62e4ed..60abfc1 100644 --- a/requirements/requirements-docs.txt +++ b/requirements/requirements-docs.txt @@ -1,12 +1,21 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.11 # +# [constraints] requirements.txt +# # - mkdocs~=1.5.2 # - mkdocs-material~=9.2.3 # - mkdocstrings~=0.22.0 # - markdown-exec[ansi]~=1.6.0 +# - hatch # +anyio==4.1.0 \ + --hash=sha256:56a415fbc462291813a94528a779597226619c8e78af7de0507333f700011e5f \ + --hash=sha256:5a0bec7085176715be77df87fc66d6c9d70626bd752fcc85f57cdbee5b3760da + # via + # -c requirements.txt + # httpx babel==2.13.1 \ --hash=sha256:33e0952d7dd6374af8dbf6768cc4ddf3ccfefc244f9986d4074704f2fbd18900 \ --hash=sha256:7077a4984b02b6727ac10f1f7294484f737443d7e2e66c5e4380e41a3ae0b4ed @@ -14,7 +23,11 @@ babel==2.13.1 \ certifi==2023.11.17 \ --hash=sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1 \ --hash=sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474 - # via requests + # via + # -c requirements.txt + # httpcore + # httpx + # requests charset-normalizer==3.3.2 \ --hash=sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027 \ --hash=sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087 \ @@ -110,19 +123,94 @@ charset-normalizer==3.3.2 \ click==8.1.7 \ --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \ --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de - # via mkdocs + # via + # -c requirements.txt + # hatch + # mkdocs + # userpath colorama==0.4.6 \ --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \ --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6 # via mkdocs-material +distlib==0.3.7 \ + --hash=sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057 \ + --hash=sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8 + # via + # -c requirements.txt + # virtualenv +editables==0.5 \ + --hash=sha256:309627d9b5c4adc0e668d8c6fa7bac1ba7c8c5d415c2d27f60f081f8e80d1de2 \ + --hash=sha256:61e5ffa82629e0d8bfe09bc44a07db3c1ab8ed1ce78a6980732870f19b5e7d4c + # via + # -c requirements.txt + # hatchling +filelock==3.13.1 \ + --hash=sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e \ + --hash=sha256:57dbda9b35157b05fb3e58ee91448612eb674172fab98ee235ccb0b5bee19a1c + # via + # -c requirements.txt + # virtualenv ghp-import==2.1.0 \ --hash=sha256:8337dd7b50877f163d4c0289bc1f1c7f127550241988d568c1db512c4324a619 \ --hash=sha256:9c535c4c61193c2df8871222567d7fd7e5014d835f97dc7b7439069e2413d343 # via mkdocs -idna==3.4 \ - --hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \ - --hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2 - # via requests +h11==0.14.0 \ + --hash=sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d \ + --hash=sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761 + # via + # -c requirements.txt + # httpcore +hatch==1.7.0 \ + --hash=sha256:7afc701fd5b33684a6650e1ecab8957e19685f824240ba7458dcacd66f90fb46 \ + --hash=sha256:efc84112fd02ca85b7bab54f5e2ef71393a98dc849eac9aca390504031f8a1a8 + # via + # -c requirements.txt + # hatch.envs.docs +hatchling==1.18.0 \ + --hash=sha256:50e99c3110ce0afc3f7bdbadff1c71c17758e476731c27607940cfa6686489ca \ + --hash=sha256:b66dc254931ec42aa68b5febd1d342c58142cc5267b7ff3b12ba3fa5b4900c93 + # via + # -c requirements.txt + # hatch +httpcore==1.0.2 \ + --hash=sha256:096cc05bca73b8e459a1fc3dcf585148f63e534eae4339559c9b8a8d6399acc7 \ + --hash=sha256:9fc092e4799b26174648e54b74ed5f683132a464e95643b226e00c2ed2fa6535 + # via + # -c requirements.txt + # httpx +httpx==0.25.2 \ + --hash=sha256:8b8fcaa0c8ea7b05edd69a094e63a2094c4efcb48129fb757361bc423c0ad9e8 \ + --hash=sha256:a05d3d052d9b2dfce0e3896636467f8a5342fb2b902c819428e1ac65413ca118 + # via + # -c requirements.txt + # hatch +hyperlink==21.0.0 \ + --hash=sha256:427af957daa58bc909471c6c40f74c5450fa123dd093fc53efd2e91d2705a56b \ + --hash=sha256:e6b14c37ecb73e89c77d78cdb4c2cc8f3fb59a885c5b3f819ff4ed80f25af1b4 + # via + # -c requirements.txt + # hatch +idna==3.5 \ + --hash=sha256:27009fe2735bf8723353582d48575b23c533cc2c2de7b5a68908d91b5eb18d08 \ + --hash=sha256:79b8f0ac92d2351be5f6122356c9a592c96d81c9a79e4b488bf2a6a15f88057a + # via + # -c requirements.txt + # anyio + # httpx + # hyperlink + # requests +importlib-metadata==6.8.0 \ + --hash=sha256:3ebb78df84a805d7698245025b975d9d67053cd94c79245ba4b3eb694abe68bb \ + --hash=sha256:dbace7892d8c0c4ac1ad096662232f831d4e64f4c4545bd53016a3e9d4654743 + # via + # -c requirements.txt + # keyring +jaraco-classes==3.3.0 \ + --hash=sha256:10afa92b6743f25c0cf5f37c6bb6e18e2c5bb84a16527ccfc0040ea377e7aaeb \ + --hash=sha256:c063dd08e89217cee02c8d5e5ec560f2c8ce6cdc2fcdc2e68f7b2e5547ed3621 + # via + # -c requirements.txt + # keyring jinja2==3.1.2 \ --hash=sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852 \ --hash=sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61 @@ -130,6 +218,12 @@ jinja2==3.1.2 \ # mkdocs # mkdocs-material # mkdocstrings +keyring==24.3.0 \ + --hash=sha256:4446d35d636e6a10b8bce7caa66913dd9eca5fd222ca03a3d42c38608ac30836 \ + --hash=sha256:e730ecffd309658a08ee82535a3b5ec4b4c8669a9be11efb66249d8e0aeb9a25 + # via + # -c requirements.txt + # hatch markdown==3.5.1 \ --hash=sha256:5874b47d4ee3f0b14d764324d2c94c03ea66bee56f2d929da9f2508d65e722dc \ --hash=sha256:b65d7beb248dc22f2e8a31fb706d93798093c308dc1aba295aedeb9d41a813bd @@ -145,6 +239,12 @@ markdown-exec==1.6.0 \ # via # hatch.envs.docs # markdown-exec +markdown-it-py==3.0.0 \ + --hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \ + --hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb + # via + # -c requirements.txt + # rich markupsafe==2.1.3 \ --hash=sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e \ --hash=sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e \ @@ -210,6 +310,12 @@ markupsafe==2.1.3 \ # jinja2 # mkdocs # mkdocstrings +mdurl==0.1.2 \ + --hash=sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8 \ + --hash=sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba + # via + # -c requirements.txt + # markdown-it-py mergedeep==1.3.4 \ --hash=sha256:0096d52e9dad9939c3d975a774666af186eda617e6ca84df4c94dec30004f2a8 \ --hash=sha256:70775750742b25c0d8f36c55aed03d24c3384d17c951b3175d898bd778ef0307 @@ -238,27 +344,64 @@ mkdocstrings==0.22.0 \ --hash=sha256:2d4095d461554ff6a778fdabdca3c00c468c2f1459d469f7a7f622a2b23212ba \ --hash=sha256:82a33b94150ebb3d4b5c73bab4598c3e21468c79ec072eff6931c8f3bfc38256 # via hatch.envs.docs +more-itertools==10.1.0 \ + --hash=sha256:626c369fa0eb37bac0291bce8259b332fd59ac792fa5497b59837309cd5b114a \ + --hash=sha256:64e0735fcfdc6f3464ea133afe8ea4483b1c5fe3a3d69852e6503b43a0b222e6 + # via + # -c requirements.txt + # jaraco-classes packaging==23.2 \ --hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \ --hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7 - # via mkdocs + # via + # -c requirements.txt + # hatch + # hatchling + # mkdocs paginate==0.5.6 \ --hash=sha256:5e6007b6a9398177a7e1648d04fdd9f8c9766a1a945bceac82f1929e8c78af2d # via mkdocs-material pathspec==0.11.2 \ --hash=sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20 \ --hash=sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3 - # via mkdocs + # via + # -c requirements.txt + # hatchling + # mkdocs +pexpect==4.8.0 \ + --hash=sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937 \ + --hash=sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c + # via + # -c requirements.txt + # hatch platformdirs==4.0.0 \ --hash=sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b \ --hash=sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731 - # via mkdocs + # via + # -c requirements.txt + # hatch + # mkdocs + # virtualenv +pluggy==1.3.0 \ + --hash=sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12 \ + --hash=sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7 + # via + # -c requirements.txt + # hatchling +ptyprocess==0.7.0 \ + --hash=sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35 \ + --hash=sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220 + # via + # -c requirements.txt + # pexpect pygments==2.17.2 \ --hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \ --hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367 # via + # -c requirements.txt # mkdocs-material # pygments-ansi-color + # rich pygments-ansi-color==0.3.0 \ --hash=sha256:7018954cf5b11d1e734383a1bafab5af613213f246109417fee3f76da26d5431 \ --hash=sha256:7eb063feaecadad9d4d1fd3474cbfeadf3486b64f760a8f2a00fc25392180aba @@ -270,6 +413,11 @@ pymdown-extensions==10.4 \ # markdown-exec # mkdocs-material # mkdocstrings +pyperclip==1.8.2 \ + --hash=sha256:105254a8b04934f0bc84e9c24eb360a591aaf6535c9def5f29d92af107a9bf57 + # via + # -c requirements.txt + # hatch python-dateutil==2.8.2 \ --hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \ --hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 @@ -427,14 +575,63 @@ requests==2.31.0 \ --hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \ --hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1 # via mkdocs-material +rich==13.7.0 \ + --hash=sha256:5cb5123b5cf9ee70584244246816e9114227e0b98ad9176eede6ad54bf5403fa \ + --hash=sha256:6da14c108c4866ee9520bbffa71f6fe3962e193b7da68720583850cd4548e235 + # via + # -c requirements.txt + # hatch +shellingham==1.5.4 \ + --hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \ + --hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de + # via + # -c requirements.txt + # hatch six==1.16.0 \ --hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \ --hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 # via python-dateutil +sniffio==1.3.0 \ + --hash=sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101 \ + --hash=sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384 + # via + # -c requirements.txt + # anyio + # httpx +tomli-w==1.0.0 \ + --hash=sha256:9f2a07e8be30a0729e533ec968016807069991ae2fd921a78d42f429ae5f4463 \ + --hash=sha256:f463434305e0336248cac9c2dc8076b707d8a12d019dd349f5c1e382dd1ae1b9 + # via + # -c requirements.txt + # hatch +tomlkit==0.12.3 \ + --hash=sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4 \ + --hash=sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba + # via + # -c requirements.txt + # hatch +trove-classifiers==2023.11.22 \ + --hash=sha256:533df77e284fd645d90deeafd3ef710d290884efafe4f5009aa1663f95aec992 \ + --hash=sha256:c31a7e92f965f060a244b57d8ed5ee6f53fcb413ee17ce790e00577cb369ad99 + # via + # -c requirements.txt + # hatchling urllib3==2.1.0 \ --hash=sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3 \ --hash=sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54 # via requests +userpath==1.9.1 \ + --hash=sha256:ce8176728d98c914b6401781bf3b23fccd968d1647539c8788c7010375e02796 \ + --hash=sha256:e085053e5161f82558793c41d60375289efceb4b77d96033ea9c84fc0893f772 + # via + # -c requirements.txt + # hatch +virtualenv==20.24.7 \ + --hash=sha256:69050ffb42419c91f6c1284a7b24e0475d793447e35929b488bf6a0aade39353 \ + --hash=sha256:a18b3fd0314ca59a2e9f4b556819ed07183b3e9a3702ecfe213f593d44f7b3fd + # via + # -c requirements.txt + # hatch watchdog==3.0.0 \ --hash=sha256:0e06ab8858a76e1219e68c7573dfeba9dd1c0219476c5a44d5333b01d7e1743a \ --hash=sha256:13bbbb462ee42ec3c5723e1205be8ced776f05b100e4737518c67c8325cf6100 \ @@ -464,3 +661,9 @@ watchdog==3.0.0 \ --hash=sha256:d00e6be486affb5781468457b21a6cbe848c33ef43f9ea4a73b4882e5f188a44 \ --hash=sha256:d429c2430c93b7903914e4db9a966c7f2b068dd2ebdd2fa9b9ce094c7d459f33 # via mkdocs +zipp==3.17.0 \ + --hash=sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31 \ + --hash=sha256:84e64a1c28cf7e91ed2078bb8cc8c259cb19b76942096c8d7b84947690cabaf0 + # via + # -c requirements.txt + # importlib-metadata From 33c29c983081410bcfb452364dbbf7ce5660f2a1 Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 14:18:54 -0700 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20constraints=20api=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hatch_pip_compile/exceptions.py | 6 ++ hatch_pip_compile/header.py | 83 ------------------- hatch_pip_compile/lock.py | 140 ++++++++++++++++++++++++++++++++ hatch_pip_compile/plugin.py | 106 +++++++++++------------- requirements.txt | 1 - 5 files changed, 193 insertions(+), 143 deletions(-) delete mode 100644 hatch_pip_compile/header.py create mode 100644 hatch_pip_compile/lock.py diff --git a/hatch_pip_compile/exceptions.py b/hatch_pip_compile/exceptions.py index 6f58fb6..0451efe 100644 --- a/hatch_pip_compile/exceptions.py +++ b/hatch_pip_compile/exceptions.py @@ -13,3 +13,9 @@ class LockFileNotFoundError(HatchPipCompileError, FileNotFoundError): """ A lock file was not found """ + + +class LockFileError(HatchPipCompileError, ValueError): + """ + A lock file content Error + """ diff --git a/hatch_pip_compile/header.py b/hatch_pip_compile/header.py deleted file mode 100644 index 01bf332..0000000 --- a/hatch_pip_compile/header.py +++ /dev/null @@ -1,83 +0,0 @@ -""" -hatch-pip-compile header operations -""" - -import pathlib -import re -from dataclasses import dataclass -from textwrap import dedent -from typing import List, Optional - -from hatch.env.virtual import VirtualEnv -from packaging.version import Version - - -@dataclass -class PipCompileHeader: - """ - Header Metadata - """ - - lock_file: pathlib.Path - dependencies: List[str] - project_root: pathlib.Path - constraints_file: Optional[pathlib.Path] - env_name: str - project_name: str - virtualenv: Optional[VirtualEnv] = None - - def write_header(self) -> None: - """ - Post process lockfile - """ - version = f"{self.python_version.major}.{self.python_version.minor}" - raw_prefix = f""" - # - # This file is autogenerated by hatch-pip-compile with Python {version} - # - """ - prefix = dedent(raw_prefix).strip() - joined_dependencies = "\n".join([f"# - {dep}" for dep in self.dependencies]) - lockfile_text = self.lock_file.read_text() - cleaned_input_file = re.sub( - rf"-r \S*/{self.env_name}\.in", - f"hatch.envs.{self.env_name}", - lockfile_text, - ) - if self.constraints_file is not None: - constraints_path = self.constraints_file.relative_to(self.project_root) - constraints_line = f"# [constraints] {constraints_path}" - joined_dependencies = "\n".join([constraints_line, "#", joined_dependencies]) - cleaned_input_file = re.sub( - r"-c \S*", - f"-c {constraints_path}", - cleaned_input_file, - ) - prefix += "\n" + joined_dependencies + "\n#" - new_text = prefix + "\n\n" + cleaned_input_file - self.lock_file.write_text(new_text) - - def read_requirements(self) -> List[str]: - """ - Read requirements from lock file - """ - lock_file_text = self.lock_file.read_text() - parsed_requirements = [] - for line in lock_file_text.splitlines(): - if line.startswith("# - "): - rest_of_line = line[4:] - parsed_requirements.append(rest_of_line) - elif not line.startswith("#"): - break - return parsed_requirements - - @property - def python_version(self) -> Version: - """ - Get python version - """ - if self.virtualenv is not None: - return Version(self.virtualenv.environment["python_version"]) - else: - msg = "VirtualEnv is not set" - raise NotImplementedError(msg) diff --git a/hatch_pip_compile/lock.py b/hatch_pip_compile/lock.py new file mode 100644 index 0000000..52f8606 --- /dev/null +++ b/hatch_pip_compile/lock.py @@ -0,0 +1,140 @@ +""" +hatch-pip-compile header operations +""" + +import logging +import pathlib +import re +from dataclasses import dataclass +from textwrap import dedent +from typing import Iterable, List, Optional + +from hatch.env.virtual import VirtualEnv +from packaging.requirements import Requirement +from packaging.version import Version + +from hatch_pip_compile.exceptions import LockFileError + +logger = logging.getLogger(__name__) + + +@dataclass +class PipCompileLock: + """ + Pip Compile Lock File Operations + """ + + lock_file: pathlib.Path + dependencies: List[str] + project_root: pathlib.Path + constraints_file: Optional[pathlib.Path] + env_name: str + project_name: str + virtualenv: Optional[VirtualEnv] = None + + def process_lock(self) -> None: + """ + Post process lockfile + """ + version = f"{self.current_python_version.major}.{self.current_python_version.minor}" + raw_prefix = f""" + # + # This file is autogenerated by hatch-pip-compile with Python {version} + # + """ + prefix = dedent(raw_prefix).strip() + joined_dependencies = "\n".join([f"# - {dep}" for dep in self.dependencies]) + lockfile_text = self.lock_file.read_text() + cleaned_input_file = re.sub( + rf"-r \S*/{self.env_name}\.in", + f"hatch.envs.{self.env_name}", + lockfile_text, + ) + if self.constraints_file is not None: + constraints_path = self.constraints_file.relative_to(self.project_root) + constraints_line = f"# [constraints] {constraints_path}" + joined_dependencies = "\n".join([constraints_line, "#", joined_dependencies]) + cleaned_input_file = re.sub( + r"-c \S*", + f"-c {constraints_path}", + cleaned_input_file, + ) + prefix += "\n" + joined_dependencies + "\n#" + new_text = prefix + "\n\n" + cleaned_input_file + self.lock_file.write_text(new_text) + + def read_requirements(self) -> List[Requirement]: + """ + Read requirements from lock file + """ + lock_file_text = self.lock_file.read_text() + parsed_requirements = [] + for line in lock_file_text.splitlines(): + if line.startswith("# - "): + requirement = Requirement(line[4:]) + parsed_requirements.append(requirement) + elif not line.startswith("#"): + break + return parsed_requirements + + @property + def current_python_version(self) -> Version: + """ + Get python version + + In the case of running as a hatch plugin, the `virtualenv` will be set, + otherwise it will be None and the Python version will be read differently. + """ + if self.virtualenv is not None: + return Version(self.virtualenv.environment["python_version"]) + else: + msg = "VirtualEnv is not set" + raise NotImplementedError(msg) + + @property + def lock_file_version(self) -> Version: + """ + Get lock file version + """ + lock_file_text = self.lock_file.read_text() + match = re.search( + r"# This file is autogenerated by hatch-pip-compile with Python (.*)", lock_file_text + ) + if match is None: + msg = "Could not find lock file python version" + raise LockFileError(msg) + return Version(match.group(1)) + + def compare_python_versions(self, verbose: Optional[bool] = None) -> bool: + """ + Compare python versions + + Parameters + ---------- + verbose : Optional[bool] + Print warning if python versions are different, by default None + which will print the warning. Used as a plugin flag. + """ + lock_version = self.lock_file_version + current_version = self.current_python_version + match = (current_version.major == lock_version.major) and ( + current_version.minor == lock_version.minor + ) + if match is False and verbose is not False: + logger.error( + "[hatch-pip-compile] Your Python version is different " + "from the lock file, your results may vary." + ) + return lock_version == current_version + + def compare_requirements(self, requirements: Iterable[Requirement]) -> bool: + """ + Compare requirements + + Parameters + ---------- + requirements : Iterable[Requirement] + List of requirements to compare against the lock file + """ + lock_requirements = self.read_requirements() + return set(requirements) == set(lock_requirements) diff --git a/hatch_pip_compile/plugin.py b/hatch_pip_compile/plugin.py index bfdc4f3..5dcac41 100644 --- a/hatch_pip_compile/plugin.py +++ b/hatch_pip_compile/plugin.py @@ -4,15 +4,13 @@ import logging import pathlib -import re import tempfile from typing import Any, Dict, List, Optional from hatch.env.virtual import VirtualEnvironment -from packaging.version import Version from hatch_pip_compile.exceptions import HatchPipCompileError, LockFileNotFoundError -from hatch_pip_compile.header import PipCompileHeader +from hatch_pip_compile.lock import PipCompileLock logger = logging.getLogger(__name__) @@ -40,15 +38,15 @@ def __init__(self, *args, **kwargs): else: with self.metadata.context.apply_context(self.context): lock_filename = self.metadata.context.format(lock_filename_config) - self._piptools_detached_mode: bool = ( + self._piptools_lock_file = self.root / lock_filename + self.piptools_detached_mode: bool = ( self.metadata.hatch.config.get("envs", {}).get(self.name, {}).get("detached", False) ) - self._piptools_lock_file = self.root / lock_filename - self._piptools_header = PipCompileHeader( + self.piptools_lock = PipCompileLock( lock_file=self._piptools_lock_file, dependencies=self.dependencies, virtualenv=self.virtual_env, - constraints_file=self._piptools_constraints_file, + constraints_file=self.piptools_constraints_file, project_root=self.root, env_name=self.name, project_name=self.metadata.name, @@ -92,9 +90,15 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa Run pip-compile """ if self._piptools_lock_file.exists() is True: - correct_environment = self._lock_file_compare() - if correct_environment is True and self._piptools_constraints_file is not None: - correct_environment = self._piptools_default_environment._lock_file_compare() + correct_environment = self.piptools_lock.compare_requirements( + requirements=self.dependencies_complex + ) + if correct_environment is True and self.piptools_constraints_file is not None: + correct_environment = ( + self.piptools_default_environment.piptools_lock.compare_requirements( + requirements=self.piptools_default_environment.dependencies_complex + ) + ) if correct_environment is True: return cmd = [ @@ -116,19 +120,21 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa if self.config.get("pip-compile-hashes", True) is True: cmd.append("--generate-hashes") - if self._piptools_constraints_file is not None: - cmd.extend(["--constraint", str(self._piptools_constraints_file)]) + if self.piptools_constraints_file is not None: + cmd.extend(["--constraint", str(self.piptools_constraints_file)]) cmd.extend(self.config.get("pip-compile-args", [])) cmd.append(str(input_file)) self.virtual_env.platform.check_command(cmd) - self._piptools_header.write_header() + self.piptools_lock.process_lock() def _pip_compile_cli(self) -> None: """ Run pip-compile """ if self._piptools_lock_file.exists() is True: - matched_dependencies = self._lock_file_compare() + matched_dependencies = self.piptools_lock.compare_requirements( + requirements=self.dependencies_complex + ) if matched_dependencies is True: return self._piptools_lock_file.parent.mkdir(exist_ok=True) @@ -142,7 +148,9 @@ def _pip_sync_cli(self) -> None: """ Run pip-sync """ - self._compare_python_versions() + _ = self.piptools_lock.compare_python_versions( + verbose=self.config.get("pip-compile-verbose", None) + ) cmd = [ self.virtual_env.python_info.executable, "-m", @@ -180,7 +188,9 @@ def dependencies_in_sync(self): if len(self.dependencies) > 0 and (self._piptools_lock_file.exists() is False): return False elif len(self.dependencies) > 0 and (self._piptools_lock_file.exists() is True): - expected_locks = self._lock_file_compare() + expected_locks = self.piptools_lock.compare_requirements( + requirements=self.dependencies_complex + ) if expected_locks is False: return False return super().dependencies_in_sync() @@ -191,44 +201,8 @@ def sync_dependencies(self): """ self._hatch_pip_compile_install() - def _lock_file_compare(self) -> bool: - """ - Compare lock file - """ - parsed_requirements = self._piptools_header.read_requirements() - expected_output = "\n".join([*parsed_requirements, ""]) - new_output = "\n".join([*self.dependencies, ""]) - return expected_output == new_output - - def _compare_python_versions(self) -> bool: - """ - Compare python versions - """ - current_version = Version(self.virtual_env.environment["python_version"]) - lock_file_text = self._piptools_lock_file.read_text() - match = re.search( - r"# This file is autogenerated by hatch-pip-compile with Python (.*)", lock_file_text - ) - if match is not None: - lock_version = Version(match.group(1)) - if all( - [ - ( - current_version.major != lock_version.major - or current_version.minor != lock_version.minor - ), - self.config.get("pip-compile-verbose", None) is not False, - ] - ): - logger.error( - "[hatch-pip-compile] Your Python version is different " - "from the lock file, your results may vary." - ) - return False - return True - @property - def _piptools_constraints_file(self) -> Optional[pathlib.Path]: + def piptools_constraints_file(self) -> Optional[pathlib.Path]: """ Get default lock file """ @@ -240,15 +214,15 @@ def _piptools_constraints_file(self) -> Optional[pathlib.Path]: ) if default_config.get("type") != self.PLUGIN_NAME: constraints_file = None - elif self._piptools_detached_mode is True: + elif self.piptools_detached_mode is True: constraints_file = None else: - constraints_file = self._piptools_default_environment._piptools_lock_file - self._validate_default_lock(constraints_file=constraints_file) + constraints_file = self.piptools_default_environment._piptools_lock_file + self.piptools_validate_default_lock(constraints_file=constraints_file) return constraints_file @property - def _piptools_default_environment(self) -> "PipCompileEnvironment": + def piptools_default_environment(self) -> "PipCompileEnvironment": """ Get default pip compile environment """ @@ -266,9 +240,21 @@ def _piptools_default_environment(self) -> "PipCompileEnvironment": ) return default_env - def _validate_default_lock(self, constraints_file: Optional[pathlib.Path]) -> None: + def piptools_validate_default_lock(self, constraints_file: Optional[pathlib.Path]) -> None: """ Validate the default lock file + + Parameters + ---------- + constraints_file : Optional[pathlib.Path] + The optional default lock file + + Raises + ------ + LockFileNotFoundError + If the default lock file does not exist + HatchPipCompileError + If the default lock file is out of date """ if constraints_file is None: return @@ -278,7 +264,9 @@ def _validate_default_lock(self, constraints_file: Optional[pathlib.Path]) -> No ) raise LockFileNotFoundError(error_message) else: - up_to_date = self._piptools_default_environment._lock_file_compare() + up_to_date = self.piptools_default_environment.piptools_lock.compare_requirements( + requirements=self.piptools_default_environment.dependencies_complex + ) if up_to_date is False: error_message = ( f"[hatch-pip-compile] The default lock file {constraints_file} is out of date. " diff --git a/requirements.txt b/requirements.txt index 87ee779..9ab190d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.11 # -# - hatch # anyio==4.1.0 \ From eeb55445bab0c130d0d4f4763895b3400d47d81a Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 14:32:16 -0700 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=A8=20force=20--strip-extras?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +++-- docs/index.md | 13 +++-- hatch_pip_compile/plugin.py | 7 +-- requirements.txt | 94 +------------------------------------ 4 files changed, 14 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 045c5c7..6b4f3f2 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,12 @@ type to `pip-compile` to use this plugin for the respective environment. ### Configuration Options -| name | type | description | -| ------------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | -| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | -| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | -| pip-compile-strip-extras | `bool` | Whether to strip the extras from the lockfile ensuring it is constraints compatible, defaults to `true` | -| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | -| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | +| name | type | description | +| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | +| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | +| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | +| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | #### Examples diff --git a/docs/index.md b/docs/index.md index 8114574..503f9d4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -70,13 +70,12 @@ type to `pip-compile` to use this plugin for the respective environment. ### Configuration Options -| name | type | description | -| ------------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | -| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | -| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | -| pip-compile-strip-extras | `bool` | Whether to strip the extras from the lockfile ensuring it is constraints compatible, defaults to `true` | -| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | -| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | +| name | type | description | +| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | +| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | +| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | +| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | #### Examples diff --git a/hatch_pip_compile/plugin.py b/hatch_pip_compile/plugin.py index 5dcac41..caee4d9 100644 --- a/hatch_pip_compile/plugin.py +++ b/hatch_pip_compile/plugin.py @@ -60,7 +60,6 @@ def get_option_types() -> Dict[str, Any]: return { "lock-filename": str, "pip-compile-hashes": bool, - "pip-compile-strip-extras": bool, "pip-compile-args": List[str], } @@ -107,11 +106,7 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa "piptools", "compile", "--verbose" if self.config.get("pip-compile-verbose", None) is True else "--quiet", - ( - "--strip-extras" - if self.config.get("pip-compile-strip-extras", True) is True - else "--no-strip-extras" - ), + "--strip-extras", "--no-header", "--output-file", str(output_file), diff --git a/requirements.txt b/requirements.txt index 9ab190d..c9f569f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.11 # +# - hatch # anyio==4.1.0 \ @@ -13,91 +14,12 @@ certifi==2023.11.17 \ # via # httpcore # httpx -cffi==1.16.0 \ - --hash=sha256:0c9ef6ff37e974b73c25eecc13952c55bceed9112be2d9d938ded8e856138bcc \ - --hash=sha256:131fd094d1065b19540c3d72594260f118b231090295d8c34e19a7bbcf2e860a \ - --hash=sha256:1b8ebc27c014c59692bb2664c7d13ce7a6e9a629be20e54e7271fa696ff2b417 \ - --hash=sha256:2c56b361916f390cd758a57f2e16233eb4f64bcbeee88a4881ea90fca14dc6ab \ - --hash=sha256:2d92b25dbf6cae33f65005baf472d2c245c050b1ce709cc4588cdcdd5495b520 \ - --hash=sha256:31d13b0f99e0836b7ff893d37af07366ebc90b678b6664c955b54561fc36ef36 \ - --hash=sha256:32c68ef735dbe5857c810328cb2481e24722a59a2003018885514d4c09af9743 \ - --hash=sha256:3686dffb02459559c74dd3d81748269ffb0eb027c39a6fc99502de37d501faa8 \ - --hash=sha256:582215a0e9adbe0e379761260553ba11c58943e4bbe9c36430c4ca6ac74b15ed \ - --hash=sha256:5b50bf3f55561dac5438f8e70bfcdfd74543fd60df5fa5f62d94e5867deca684 \ - --hash=sha256:5bf44d66cdf9e893637896c7faa22298baebcd18d1ddb6d2626a6e39793a1d56 \ - --hash=sha256:6602bc8dc6f3a9e02b6c22c4fc1e47aa50f8f8e6d3f78a5e16ac33ef5fefa324 \ - --hash=sha256:673739cb539f8cdaa07d92d02efa93c9ccf87e345b9a0b556e3ecc666718468d \ - --hash=sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235 \ - --hash=sha256:68e7c44931cc171c54ccb702482e9fc723192e88d25a0e133edd7aff8fcd1f6e \ - --hash=sha256:6b3d6606d369fc1da4fd8c357d026317fbb9c9b75d36dc16e90e84c26854b088 \ - --hash=sha256:748dcd1e3d3d7cd5443ef03ce8685043294ad6bd7c02a38d1bd367cfd968e000 \ - --hash=sha256:7651c50c8c5ef7bdb41108b7b8c5a83013bfaa8a935590c5d74627c047a583c7 \ - --hash=sha256:7b78010e7b97fef4bee1e896df8a4bbb6712b7f05b7ef630f9d1da00f6444d2e \ - --hash=sha256:7e61e3e4fa664a8588aa25c883eab612a188c725755afff6289454d6362b9673 \ - --hash=sha256:80876338e19c951fdfed6198e70bc88f1c9758b94578d5a7c4c91a87af3cf31c \ - --hash=sha256:8895613bcc094d4a1b2dbe179d88d7fb4a15cee43c052e8885783fac397d91fe \ - --hash=sha256:88e2b3c14bdb32e440be531ade29d3c50a1a59cd4e51b1dd8b0865c54ea5d2e2 \ - --hash=sha256:8f8e709127c6c77446a8c0a8c8bf3c8ee706a06cd44b1e827c3e6a2ee6b8c098 \ - --hash=sha256:9cb4a35b3642fc5c005a6755a5d17c6c8b6bcb6981baf81cea8bfbc8903e8ba8 \ - --hash=sha256:9f90389693731ff1f659e55c7d1640e2ec43ff725cc61b04b2f9c6d8d017df6a \ - --hash=sha256:a09582f178759ee8128d9270cd1344154fd473bb77d94ce0aeb2a93ebf0feaf0 \ - --hash=sha256:a6a14b17d7e17fa0d207ac08642c8820f84f25ce17a442fd15e27ea18d67c59b \ - --hash=sha256:a72e8961a86d19bdb45851d8f1f08b041ea37d2bd8d4fd19903bc3083d80c896 \ - --hash=sha256:abd808f9c129ba2beda4cfc53bde801e5bcf9d6e0f22f095e45327c038bfe68e \ - --hash=sha256:ac0f5edd2360eea2f1daa9e26a41db02dd4b0451b48f7c318e217ee092a213e9 \ - --hash=sha256:b29ebffcf550f9da55bec9e02ad430c992a87e5f512cd63388abb76f1036d8d2 \ - --hash=sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b \ - --hash=sha256:b7be2d771cdba2942e13215c4e340bfd76398e9227ad10402a8767ab1865d2e6 \ - --hash=sha256:b84834d0cf97e7d27dd5b7f3aca7b6e9263c56308ab9dc8aae9784abb774d404 \ - --hash=sha256:b86851a328eedc692acf81fb05444bdf1891747c25af7529e39ddafaf68a4f3f \ - --hash=sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0 \ - --hash=sha256:c0f31130ebc2d37cdd8e44605fb5fa7ad59049298b3f745c74fa74c62fbfcfc4 \ - --hash=sha256:c6a164aa47843fb1b01e941d385aab7215563bb8816d80ff3a363a9f8448a8dc \ - --hash=sha256:d8a9d3ebe49f084ad71f9269834ceccbf398253c9fac910c4fd7053ff1386936 \ - --hash=sha256:db8e577c19c0fda0beb7e0d4e09e0ba74b1e4c092e0e40bfa12fe05b6f6d75ba \ - --hash=sha256:dc9b18bf40cc75f66f40a7379f6a9513244fe33c0e8aa72e2d56b0196a7ef872 \ - --hash=sha256:e09f3ff613345df5e8c3667da1d918f9149bd623cd9070c983c013792a9a62eb \ - --hash=sha256:e4108df7fe9b707191e55f33efbcb2d81928e10cea45527879a4749cbe472614 \ - --hash=sha256:e6024675e67af929088fda399b2094574609396b1decb609c55fa58b028a32a1 \ - --hash=sha256:e70f54f1796669ef691ca07d046cd81a29cb4deb1e5f942003f401c0c4a2695d \ - --hash=sha256:e715596e683d2ce000574bae5d07bd522c781a822866c20495e52520564f0969 \ - --hash=sha256:e760191dd42581e023a68b758769e2da259b5d52e3103c6060ddc02c9edb8d7b \ - --hash=sha256:ed86a35631f7bfbb28e108dd96773b9d5a6ce4811cf6ea468bb6a359b256b1e4 \ - --hash=sha256:ee07e47c12890ef248766a6e55bd38ebfb2bb8edd4142d56db91b21ea68b7627 \ - --hash=sha256:fa3a0128b152627161ce47201262d3140edb5a5c3da88d73a1b790a959126956 \ - --hash=sha256:fcc8eb6d5902bb1cf6dc4f187ee3ea80a1eba0a89aba40a5cb20a5087d961357 - # via cryptography click==8.1.7 \ --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \ --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de # via # hatch # userpath -cryptography==41.0.5 \ - --hash=sha256:0c327cac00f082013c7c9fb6c46b7cc9fa3c288ca702c74773968173bda421bf \ - --hash=sha256:0d2a6a598847c46e3e321a7aef8af1436f11c27f1254933746304ff014664d84 \ - --hash=sha256:227ec057cd32a41c6651701abc0328135e472ed450f47c2766f23267b792a88e \ - --hash=sha256:22892cc830d8b2c89ea60148227631bb96a7da0c1b722f2aac8824b1b7c0b6b8 \ - --hash=sha256:392cb88b597247177172e02da6b7a63deeff1937fa6fec3bbf902ebd75d97ec7 \ - --hash=sha256:3be3ca726e1572517d2bef99a818378bbcf7d7799d5372a46c79c29eb8d166c1 \ - --hash=sha256:573eb7128cbca75f9157dcde974781209463ce56b5804983e11a1c462f0f4e88 \ - --hash=sha256:580afc7b7216deeb87a098ef0674d6ee34ab55993140838b14c9b83312b37b86 \ - --hash=sha256:5a70187954ba7292c7876734183e810b728b4f3965fbe571421cb2434d279179 \ - --hash=sha256:73801ac9736741f220e20435f84ecec75ed70eda90f781a148f1bad546963d81 \ - --hash=sha256:7d208c21e47940369accfc9e85f0de7693d9a5d843c2509b3846b2db170dfd20 \ - --hash=sha256:8254962e6ba1f4d2090c44daf50a547cd5f0bf446dc658a8e5f8156cae0d8548 \ - --hash=sha256:88417bff20162f635f24f849ab182b092697922088b477a7abd6664ddd82291d \ - --hash=sha256:a48e74dad1fb349f3dc1d449ed88e0017d792997a7ad2ec9587ed17405667e6d \ - --hash=sha256:b948e09fe5fb18517d99994184854ebd50b57248736fd4c720ad540560174ec5 \ - --hash=sha256:c707f7afd813478e2019ae32a7c49cd932dd60ab2d2a93e796f68236b7e1fbf1 \ - --hash=sha256:d38e6031e113b7421db1de0c1b1f7739564a88f1684c6b89234fbf6c11b75147 \ - --hash=sha256:d3977f0e276f6f5bf245c403156673db103283266601405376f075c849a0b936 \ - --hash=sha256:da6a0ff8f1016ccc7477e6339e1d50ce5f59b88905585f77193ebd5068f1e797 \ - --hash=sha256:e270c04f4d9b5671ebcc792b3ba5d4488bf7c42c3c241a3748e2599776f29696 \ - --hash=sha256:e886098619d3815e0ad5790c973afeee2c0e6e04b4da90b88e6bd06e2a0b1b72 \ - --hash=sha256:ec3b055ff8f1dce8e6ef28f626e0972981475173d7973d63f271b29c8a2897da \ - --hash=sha256:fba1e91467c65fe64a82c689dc6cf58151158993b13eb7a7f3f4b7f395636723 - # via secretstorage distlib==0.3.7 \ --hash=sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057 \ --hash=sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8 @@ -149,12 +71,6 @@ jaraco-classes==3.3.0 \ --hash=sha256:10afa92b6743f25c0cf5f37c6bb6e18e2c5bb84a16527ccfc0040ea377e7aaeb \ --hash=sha256:c063dd08e89217cee02c8d5e5ec560f2c8ce6cdc2fcdc2e68f7b2e5547ed3621 # via keyring -jeepney==0.8.0 \ - --hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \ - --hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755 - # via - # keyring - # secretstorage keyring==24.3.0 \ --hash=sha256:4446d35d636e6a10b8bce7caa66913dd9eca5fd222ca03a3d42c38608ac30836 \ --hash=sha256:e730ecffd309658a08ee82535a3b5ec4b4c8669a9be11efb66249d8e0aeb9a25 @@ -199,10 +115,6 @@ ptyprocess==0.7.0 \ --hash=sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35 \ --hash=sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220 # via pexpect -pycparser==2.21 \ - --hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \ - --hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206 - # via cffi pygments==2.17.2 \ --hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \ --hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367 @@ -214,10 +126,6 @@ rich==13.7.0 \ --hash=sha256:5cb5123b5cf9ee70584244246816e9114227e0b98ad9176eede6ad54bf5403fa \ --hash=sha256:6da14c108c4866ee9520bbffa71f6fe3962e193b7da68720583850cd4548e235 # via hatch -secretstorage==3.3.3 \ - --hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \ - --hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99 - # via keyring shellingham==1.5.4 \ --hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \ --hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de From 87489ccaa38bd024e8eb275a42feb179a644acf2 Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 14:40:33 -0700 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=90=9B=20linux=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 93 +++++++++++++++++++++++++ requirements/requirements-docs.txt | 106 ++++++++++++++++++++++++++++- 2 files changed, 196 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index c9f569f..87ee779 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,12 +14,91 @@ certifi==2023.11.17 \ # via # httpcore # httpx +cffi==1.16.0 \ + --hash=sha256:0c9ef6ff37e974b73c25eecc13952c55bceed9112be2d9d938ded8e856138bcc \ + --hash=sha256:131fd094d1065b19540c3d72594260f118b231090295d8c34e19a7bbcf2e860a \ + --hash=sha256:1b8ebc27c014c59692bb2664c7d13ce7a6e9a629be20e54e7271fa696ff2b417 \ + --hash=sha256:2c56b361916f390cd758a57f2e16233eb4f64bcbeee88a4881ea90fca14dc6ab \ + --hash=sha256:2d92b25dbf6cae33f65005baf472d2c245c050b1ce709cc4588cdcdd5495b520 \ + --hash=sha256:31d13b0f99e0836b7ff893d37af07366ebc90b678b6664c955b54561fc36ef36 \ + --hash=sha256:32c68ef735dbe5857c810328cb2481e24722a59a2003018885514d4c09af9743 \ + --hash=sha256:3686dffb02459559c74dd3d81748269ffb0eb027c39a6fc99502de37d501faa8 \ + --hash=sha256:582215a0e9adbe0e379761260553ba11c58943e4bbe9c36430c4ca6ac74b15ed \ + --hash=sha256:5b50bf3f55561dac5438f8e70bfcdfd74543fd60df5fa5f62d94e5867deca684 \ + --hash=sha256:5bf44d66cdf9e893637896c7faa22298baebcd18d1ddb6d2626a6e39793a1d56 \ + --hash=sha256:6602bc8dc6f3a9e02b6c22c4fc1e47aa50f8f8e6d3f78a5e16ac33ef5fefa324 \ + --hash=sha256:673739cb539f8cdaa07d92d02efa93c9ccf87e345b9a0b556e3ecc666718468d \ + --hash=sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235 \ + --hash=sha256:68e7c44931cc171c54ccb702482e9fc723192e88d25a0e133edd7aff8fcd1f6e \ + --hash=sha256:6b3d6606d369fc1da4fd8c357d026317fbb9c9b75d36dc16e90e84c26854b088 \ + --hash=sha256:748dcd1e3d3d7cd5443ef03ce8685043294ad6bd7c02a38d1bd367cfd968e000 \ + --hash=sha256:7651c50c8c5ef7bdb41108b7b8c5a83013bfaa8a935590c5d74627c047a583c7 \ + --hash=sha256:7b78010e7b97fef4bee1e896df8a4bbb6712b7f05b7ef630f9d1da00f6444d2e \ + --hash=sha256:7e61e3e4fa664a8588aa25c883eab612a188c725755afff6289454d6362b9673 \ + --hash=sha256:80876338e19c951fdfed6198e70bc88f1c9758b94578d5a7c4c91a87af3cf31c \ + --hash=sha256:8895613bcc094d4a1b2dbe179d88d7fb4a15cee43c052e8885783fac397d91fe \ + --hash=sha256:88e2b3c14bdb32e440be531ade29d3c50a1a59cd4e51b1dd8b0865c54ea5d2e2 \ + --hash=sha256:8f8e709127c6c77446a8c0a8c8bf3c8ee706a06cd44b1e827c3e6a2ee6b8c098 \ + --hash=sha256:9cb4a35b3642fc5c005a6755a5d17c6c8b6bcb6981baf81cea8bfbc8903e8ba8 \ + --hash=sha256:9f90389693731ff1f659e55c7d1640e2ec43ff725cc61b04b2f9c6d8d017df6a \ + --hash=sha256:a09582f178759ee8128d9270cd1344154fd473bb77d94ce0aeb2a93ebf0feaf0 \ + --hash=sha256:a6a14b17d7e17fa0d207ac08642c8820f84f25ce17a442fd15e27ea18d67c59b \ + --hash=sha256:a72e8961a86d19bdb45851d8f1f08b041ea37d2bd8d4fd19903bc3083d80c896 \ + --hash=sha256:abd808f9c129ba2beda4cfc53bde801e5bcf9d6e0f22f095e45327c038bfe68e \ + --hash=sha256:ac0f5edd2360eea2f1daa9e26a41db02dd4b0451b48f7c318e217ee092a213e9 \ + --hash=sha256:b29ebffcf550f9da55bec9e02ad430c992a87e5f512cd63388abb76f1036d8d2 \ + --hash=sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b \ + --hash=sha256:b7be2d771cdba2942e13215c4e340bfd76398e9227ad10402a8767ab1865d2e6 \ + --hash=sha256:b84834d0cf97e7d27dd5b7f3aca7b6e9263c56308ab9dc8aae9784abb774d404 \ + --hash=sha256:b86851a328eedc692acf81fb05444bdf1891747c25af7529e39ddafaf68a4f3f \ + --hash=sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0 \ + --hash=sha256:c0f31130ebc2d37cdd8e44605fb5fa7ad59049298b3f745c74fa74c62fbfcfc4 \ + --hash=sha256:c6a164aa47843fb1b01e941d385aab7215563bb8816d80ff3a363a9f8448a8dc \ + --hash=sha256:d8a9d3ebe49f084ad71f9269834ceccbf398253c9fac910c4fd7053ff1386936 \ + --hash=sha256:db8e577c19c0fda0beb7e0d4e09e0ba74b1e4c092e0e40bfa12fe05b6f6d75ba \ + --hash=sha256:dc9b18bf40cc75f66f40a7379f6a9513244fe33c0e8aa72e2d56b0196a7ef872 \ + --hash=sha256:e09f3ff613345df5e8c3667da1d918f9149bd623cd9070c983c013792a9a62eb \ + --hash=sha256:e4108df7fe9b707191e55f33efbcb2d81928e10cea45527879a4749cbe472614 \ + --hash=sha256:e6024675e67af929088fda399b2094574609396b1decb609c55fa58b028a32a1 \ + --hash=sha256:e70f54f1796669ef691ca07d046cd81a29cb4deb1e5f942003f401c0c4a2695d \ + --hash=sha256:e715596e683d2ce000574bae5d07bd522c781a822866c20495e52520564f0969 \ + --hash=sha256:e760191dd42581e023a68b758769e2da259b5d52e3103c6060ddc02c9edb8d7b \ + --hash=sha256:ed86a35631f7bfbb28e108dd96773b9d5a6ce4811cf6ea468bb6a359b256b1e4 \ + --hash=sha256:ee07e47c12890ef248766a6e55bd38ebfb2bb8edd4142d56db91b21ea68b7627 \ + --hash=sha256:fa3a0128b152627161ce47201262d3140edb5a5c3da88d73a1b790a959126956 \ + --hash=sha256:fcc8eb6d5902bb1cf6dc4f187ee3ea80a1eba0a89aba40a5cb20a5087d961357 + # via cryptography click==8.1.7 \ --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \ --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de # via # hatch # userpath +cryptography==41.0.5 \ + --hash=sha256:0c327cac00f082013c7c9fb6c46b7cc9fa3c288ca702c74773968173bda421bf \ + --hash=sha256:0d2a6a598847c46e3e321a7aef8af1436f11c27f1254933746304ff014664d84 \ + --hash=sha256:227ec057cd32a41c6651701abc0328135e472ed450f47c2766f23267b792a88e \ + --hash=sha256:22892cc830d8b2c89ea60148227631bb96a7da0c1b722f2aac8824b1b7c0b6b8 \ + --hash=sha256:392cb88b597247177172e02da6b7a63deeff1937fa6fec3bbf902ebd75d97ec7 \ + --hash=sha256:3be3ca726e1572517d2bef99a818378bbcf7d7799d5372a46c79c29eb8d166c1 \ + --hash=sha256:573eb7128cbca75f9157dcde974781209463ce56b5804983e11a1c462f0f4e88 \ + --hash=sha256:580afc7b7216deeb87a098ef0674d6ee34ab55993140838b14c9b83312b37b86 \ + --hash=sha256:5a70187954ba7292c7876734183e810b728b4f3965fbe571421cb2434d279179 \ + --hash=sha256:73801ac9736741f220e20435f84ecec75ed70eda90f781a148f1bad546963d81 \ + --hash=sha256:7d208c21e47940369accfc9e85f0de7693d9a5d843c2509b3846b2db170dfd20 \ + --hash=sha256:8254962e6ba1f4d2090c44daf50a547cd5f0bf446dc658a8e5f8156cae0d8548 \ + --hash=sha256:88417bff20162f635f24f849ab182b092697922088b477a7abd6664ddd82291d \ + --hash=sha256:a48e74dad1fb349f3dc1d449ed88e0017d792997a7ad2ec9587ed17405667e6d \ + --hash=sha256:b948e09fe5fb18517d99994184854ebd50b57248736fd4c720ad540560174ec5 \ + --hash=sha256:c707f7afd813478e2019ae32a7c49cd932dd60ab2d2a93e796f68236b7e1fbf1 \ + --hash=sha256:d38e6031e113b7421db1de0c1b1f7739564a88f1684c6b89234fbf6c11b75147 \ + --hash=sha256:d3977f0e276f6f5bf245c403156673db103283266601405376f075c849a0b936 \ + --hash=sha256:da6a0ff8f1016ccc7477e6339e1d50ce5f59b88905585f77193ebd5068f1e797 \ + --hash=sha256:e270c04f4d9b5671ebcc792b3ba5d4488bf7c42c3c241a3748e2599776f29696 \ + --hash=sha256:e886098619d3815e0ad5790c973afeee2c0e6e04b4da90b88e6bd06e2a0b1b72 \ + --hash=sha256:ec3b055ff8f1dce8e6ef28f626e0972981475173d7973d63f271b29c8a2897da \ + --hash=sha256:fba1e91467c65fe64a82c689dc6cf58151158993b13eb7a7f3f4b7f395636723 + # via secretstorage distlib==0.3.7 \ --hash=sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057 \ --hash=sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8 @@ -71,6 +150,12 @@ jaraco-classes==3.3.0 \ --hash=sha256:10afa92b6743f25c0cf5f37c6bb6e18e2c5bb84a16527ccfc0040ea377e7aaeb \ --hash=sha256:c063dd08e89217cee02c8d5e5ec560f2c8ce6cdc2fcdc2e68f7b2e5547ed3621 # via keyring +jeepney==0.8.0 \ + --hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \ + --hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755 + # via + # keyring + # secretstorage keyring==24.3.0 \ --hash=sha256:4446d35d636e6a10b8bce7caa66913dd9eca5fd222ca03a3d42c38608ac30836 \ --hash=sha256:e730ecffd309658a08ee82535a3b5ec4b4c8669a9be11efb66249d8e0aeb9a25 @@ -115,6 +200,10 @@ ptyprocess==0.7.0 \ --hash=sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35 \ --hash=sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220 # via pexpect +pycparser==2.21 \ + --hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \ + --hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206 + # via cffi pygments==2.17.2 \ --hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \ --hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367 @@ -126,6 +215,10 @@ rich==13.7.0 \ --hash=sha256:5cb5123b5cf9ee70584244246816e9114227e0b98ad9176eede6ad54bf5403fa \ --hash=sha256:6da14c108c4866ee9520bbffa71f6fe3962e193b7da68720583850cd4548e235 # via hatch +secretstorage==3.3.3 \ + --hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \ + --hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99 + # via keyring shellingham==1.5.4 \ --hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \ --hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de diff --git a/requirements/requirements-docs.txt b/requirements/requirements-docs.txt index 60abfc1..d4a54f5 100644 --- a/requirements/requirements-docs.txt +++ b/requirements/requirements-docs.txt @@ -28,6 +28,62 @@ certifi==2023.11.17 \ # httpcore # httpx # requests +cffi==1.16.0 \ + --hash=sha256:0c9ef6ff37e974b73c25eecc13952c55bceed9112be2d9d938ded8e856138bcc \ + --hash=sha256:131fd094d1065b19540c3d72594260f118b231090295d8c34e19a7bbcf2e860a \ + --hash=sha256:1b8ebc27c014c59692bb2664c7d13ce7a6e9a629be20e54e7271fa696ff2b417 \ + --hash=sha256:2c56b361916f390cd758a57f2e16233eb4f64bcbeee88a4881ea90fca14dc6ab \ + --hash=sha256:2d92b25dbf6cae33f65005baf472d2c245c050b1ce709cc4588cdcdd5495b520 \ + --hash=sha256:31d13b0f99e0836b7ff893d37af07366ebc90b678b6664c955b54561fc36ef36 \ + --hash=sha256:32c68ef735dbe5857c810328cb2481e24722a59a2003018885514d4c09af9743 \ + --hash=sha256:3686dffb02459559c74dd3d81748269ffb0eb027c39a6fc99502de37d501faa8 \ + --hash=sha256:582215a0e9adbe0e379761260553ba11c58943e4bbe9c36430c4ca6ac74b15ed \ + --hash=sha256:5b50bf3f55561dac5438f8e70bfcdfd74543fd60df5fa5f62d94e5867deca684 \ + --hash=sha256:5bf44d66cdf9e893637896c7faa22298baebcd18d1ddb6d2626a6e39793a1d56 \ + --hash=sha256:6602bc8dc6f3a9e02b6c22c4fc1e47aa50f8f8e6d3f78a5e16ac33ef5fefa324 \ + --hash=sha256:673739cb539f8cdaa07d92d02efa93c9ccf87e345b9a0b556e3ecc666718468d \ + --hash=sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235 \ + --hash=sha256:68e7c44931cc171c54ccb702482e9fc723192e88d25a0e133edd7aff8fcd1f6e \ + --hash=sha256:6b3d6606d369fc1da4fd8c357d026317fbb9c9b75d36dc16e90e84c26854b088 \ + --hash=sha256:748dcd1e3d3d7cd5443ef03ce8685043294ad6bd7c02a38d1bd367cfd968e000 \ + --hash=sha256:7651c50c8c5ef7bdb41108b7b8c5a83013bfaa8a935590c5d74627c047a583c7 \ + --hash=sha256:7b78010e7b97fef4bee1e896df8a4bbb6712b7f05b7ef630f9d1da00f6444d2e \ + --hash=sha256:7e61e3e4fa664a8588aa25c883eab612a188c725755afff6289454d6362b9673 \ + --hash=sha256:80876338e19c951fdfed6198e70bc88f1c9758b94578d5a7c4c91a87af3cf31c \ + --hash=sha256:8895613bcc094d4a1b2dbe179d88d7fb4a15cee43c052e8885783fac397d91fe \ + --hash=sha256:88e2b3c14bdb32e440be531ade29d3c50a1a59cd4e51b1dd8b0865c54ea5d2e2 \ + --hash=sha256:8f8e709127c6c77446a8c0a8c8bf3c8ee706a06cd44b1e827c3e6a2ee6b8c098 \ + --hash=sha256:9cb4a35b3642fc5c005a6755a5d17c6c8b6bcb6981baf81cea8bfbc8903e8ba8 \ + --hash=sha256:9f90389693731ff1f659e55c7d1640e2ec43ff725cc61b04b2f9c6d8d017df6a \ + --hash=sha256:a09582f178759ee8128d9270cd1344154fd473bb77d94ce0aeb2a93ebf0feaf0 \ + --hash=sha256:a6a14b17d7e17fa0d207ac08642c8820f84f25ce17a442fd15e27ea18d67c59b \ + --hash=sha256:a72e8961a86d19bdb45851d8f1f08b041ea37d2bd8d4fd19903bc3083d80c896 \ + --hash=sha256:abd808f9c129ba2beda4cfc53bde801e5bcf9d6e0f22f095e45327c038bfe68e \ + --hash=sha256:ac0f5edd2360eea2f1daa9e26a41db02dd4b0451b48f7c318e217ee092a213e9 \ + --hash=sha256:b29ebffcf550f9da55bec9e02ad430c992a87e5f512cd63388abb76f1036d8d2 \ + --hash=sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b \ + --hash=sha256:b7be2d771cdba2942e13215c4e340bfd76398e9227ad10402a8767ab1865d2e6 \ + --hash=sha256:b84834d0cf97e7d27dd5b7f3aca7b6e9263c56308ab9dc8aae9784abb774d404 \ + --hash=sha256:b86851a328eedc692acf81fb05444bdf1891747c25af7529e39ddafaf68a4f3f \ + --hash=sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0 \ + --hash=sha256:c0f31130ebc2d37cdd8e44605fb5fa7ad59049298b3f745c74fa74c62fbfcfc4 \ + --hash=sha256:c6a164aa47843fb1b01e941d385aab7215563bb8816d80ff3a363a9f8448a8dc \ + --hash=sha256:d8a9d3ebe49f084ad71f9269834ceccbf398253c9fac910c4fd7053ff1386936 \ + --hash=sha256:db8e577c19c0fda0beb7e0d4e09e0ba74b1e4c092e0e40bfa12fe05b6f6d75ba \ + --hash=sha256:dc9b18bf40cc75f66f40a7379f6a9513244fe33c0e8aa72e2d56b0196a7ef872 \ + --hash=sha256:e09f3ff613345df5e8c3667da1d918f9149bd623cd9070c983c013792a9a62eb \ + --hash=sha256:e4108df7fe9b707191e55f33efbcb2d81928e10cea45527879a4749cbe472614 \ + --hash=sha256:e6024675e67af929088fda399b2094574609396b1decb609c55fa58b028a32a1 \ + --hash=sha256:e70f54f1796669ef691ca07d046cd81a29cb4deb1e5f942003f401c0c4a2695d \ + --hash=sha256:e715596e683d2ce000574bae5d07bd522c781a822866c20495e52520564f0969 \ + --hash=sha256:e760191dd42581e023a68b758769e2da259b5d52e3103c6060ddc02c9edb8d7b \ + --hash=sha256:ed86a35631f7bfbb28e108dd96773b9d5a6ce4811cf6ea468bb6a359b256b1e4 \ + --hash=sha256:ee07e47c12890ef248766a6e55bd38ebfb2bb8edd4142d56db91b21ea68b7627 \ + --hash=sha256:fa3a0128b152627161ce47201262d3140edb5a5c3da88d73a1b790a959126956 \ + --hash=sha256:fcc8eb6d5902bb1cf6dc4f187ee3ea80a1eba0a89aba40a5cb20a5087d961357 + # via + # -c requirements.txt + # cryptography charset-normalizer==3.3.2 \ --hash=sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027 \ --hash=sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087 \ @@ -132,6 +188,33 @@ colorama==0.4.6 \ --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \ --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6 # via mkdocs-material +cryptography==41.0.5 \ + --hash=sha256:0c327cac00f082013c7c9fb6c46b7cc9fa3c288ca702c74773968173bda421bf \ + --hash=sha256:0d2a6a598847c46e3e321a7aef8af1436f11c27f1254933746304ff014664d84 \ + --hash=sha256:227ec057cd32a41c6651701abc0328135e472ed450f47c2766f23267b792a88e \ + --hash=sha256:22892cc830d8b2c89ea60148227631bb96a7da0c1b722f2aac8824b1b7c0b6b8 \ + --hash=sha256:392cb88b597247177172e02da6b7a63deeff1937fa6fec3bbf902ebd75d97ec7 \ + --hash=sha256:3be3ca726e1572517d2bef99a818378bbcf7d7799d5372a46c79c29eb8d166c1 \ + --hash=sha256:573eb7128cbca75f9157dcde974781209463ce56b5804983e11a1c462f0f4e88 \ + --hash=sha256:580afc7b7216deeb87a098ef0674d6ee34ab55993140838b14c9b83312b37b86 \ + --hash=sha256:5a70187954ba7292c7876734183e810b728b4f3965fbe571421cb2434d279179 \ + --hash=sha256:73801ac9736741f220e20435f84ecec75ed70eda90f781a148f1bad546963d81 \ + --hash=sha256:7d208c21e47940369accfc9e85f0de7693d9a5d843c2509b3846b2db170dfd20 \ + --hash=sha256:8254962e6ba1f4d2090c44daf50a547cd5f0bf446dc658a8e5f8156cae0d8548 \ + --hash=sha256:88417bff20162f635f24f849ab182b092697922088b477a7abd6664ddd82291d \ + --hash=sha256:a48e74dad1fb349f3dc1d449ed88e0017d792997a7ad2ec9587ed17405667e6d \ + --hash=sha256:b948e09fe5fb18517d99994184854ebd50b57248736fd4c720ad540560174ec5 \ + --hash=sha256:c707f7afd813478e2019ae32a7c49cd932dd60ab2d2a93e796f68236b7e1fbf1 \ + --hash=sha256:d38e6031e113b7421db1de0c1b1f7739564a88f1684c6b89234fbf6c11b75147 \ + --hash=sha256:d3977f0e276f6f5bf245c403156673db103283266601405376f075c849a0b936 \ + --hash=sha256:da6a0ff8f1016ccc7477e6339e1d50ce5f59b88905585f77193ebd5068f1e797 \ + --hash=sha256:e270c04f4d9b5671ebcc792b3ba5d4488bf7c42c3c241a3748e2599776f29696 \ + --hash=sha256:e886098619d3815e0ad5790c973afeee2c0e6e04b4da90b88e6bd06e2a0b1b72 \ + --hash=sha256:ec3b055ff8f1dce8e6ef28f626e0972981475173d7973d63f271b29c8a2897da \ + --hash=sha256:fba1e91467c65fe64a82c689dc6cf58151158993b13eb7a7f3f4b7f395636723 + # via + # -c requirements.txt + # secretstorage distlib==0.3.7 \ --hash=sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057 \ --hash=sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8 @@ -211,6 +294,13 @@ jaraco-classes==3.3.0 \ # via # -c requirements.txt # keyring +jeepney==0.8.0 \ + --hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \ + --hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755 + # via + # -c requirements.txt + # keyring + # secretstorage jinja2==3.1.2 \ --hash=sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852 \ --hash=sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61 @@ -236,9 +326,7 @@ markdown==3.5.1 \ markdown-exec==1.6.0 \ --hash=sha256:7dc22dda1e94815d72529caf6ec7a44a164d68e204894a48d4d0702425517504 \ --hash=sha256:a52a84dda65c841f1a6a605d219cef9503b0a38fef8cd6c1f19b41a02d0e8d9d - # via - # hatch.envs.docs - # markdown-exec + # via hatch.envs.docs markdown-it-py==3.0.0 \ --hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \ --hash=sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb @@ -394,6 +482,12 @@ ptyprocess==0.7.0 \ # via # -c requirements.txt # pexpect +pycparser==2.21 \ + --hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \ + --hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206 + # via + # -c requirements.txt + # cffi pygments==2.17.2 \ --hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \ --hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367 @@ -581,6 +675,12 @@ rich==13.7.0 \ # via # -c requirements.txt # hatch +secretstorage==3.3.3 \ + --hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \ + --hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99 + # via + # -c requirements.txt + # keyring shellingham==1.5.4 \ --hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \ --hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de From e7c4f5bfae822780d9e0a99dbc4bcd97442ed3a7 Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 19:21:50 -0700 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=A8=20pip-compile-constraint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hatch_pip_compile/plugin.py | 98 +++++++++++++++++++++++-------------- pyproject.toml | 1 + 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/hatch_pip_compile/plugin.py b/hatch_pip_compile/plugin.py index caee4d9..3668a21 100644 --- a/hatch_pip_compile/plugin.py +++ b/hatch_pip_compile/plugin.py @@ -22,7 +22,13 @@ class PipCompileEnvironment(VirtualEnvironment): PLUGIN_NAME = "pip-compile" - _default_env_name = "default" + default_env_name = "default" + + def __repr__(self): + """ + Get representation of PipCompileEnvironment + """ + return f"<{self.__class__.__name__} - {self.name}>" def __init__(self, *args, **kwargs): """ @@ -31,7 +37,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) lock_filename_config = self.config.get("lock-filename") if lock_filename_config is None: - if self.name == self._default_env_name: + if self.name == self.default_env_name: lock_filename = "requirements.txt" else: lock_filename = f"requirements/requirements-{self.name}.txt" @@ -39,9 +45,6 @@ def __init__(self, *args, **kwargs): with self.metadata.context.apply_context(self.context): lock_filename = self.metadata.context.format(lock_filename_config) self._piptools_lock_file = self.root / lock_filename - self.piptools_detached_mode: bool = ( - self.metadata.hatch.config.get("envs", {}).get(self.name, {}).get("detached", False) - ) self.piptools_lock = PipCompileLock( lock_file=self._piptools_lock_file, dependencies=self.dependencies, @@ -61,6 +64,7 @@ def get_option_types() -> Dict[str, Any]: "lock-filename": str, "pip-compile-hashes": bool, "pip-compile-args": List[str], + "pip-compile-constraint": str, } def _hatch_pip_compile_install(self): @@ -93,10 +97,10 @@ def _pip_compile_command(self, output_file: pathlib.Path, input_file: pathlib.Pa requirements=self.dependencies_complex ) if correct_environment is True and self.piptools_constraints_file is not None: - correct_environment = ( - self.piptools_default_environment.piptools_lock.compare_requirements( - requirements=self.piptools_default_environment.dependencies_complex - ) + constraints_env = self.config["pip-compile-constraint"] + environment = self.get_piptools_environment(environment_name=constraints_env) + correct_environment = environment.piptools_lock.compare_requirements( + requirements=environment.dependencies_complex ) if correct_environment is True: return @@ -201,31 +205,39 @@ def piptools_constraints_file(self) -> Optional[pathlib.Path]: """ Get default lock file """ - if self.name == self._default_env_name: + constraint_env = self.config.get("pip-compile-constraint") + if constraint_env is None: + return None + elif self.name == constraint_env: + return None + environment = self.get_piptools_environment(environment_name=constraint_env) + if environment.config.get("type") != self.PLUGIN_NAME: + logger.error("The constraint environment is not a hatch-pip-compile environment.") constraints_file = None else: - default_config = self.metadata.hatch.config.get("envs", {}).get( - self._default_env_name, {} - ) - if default_config.get("type") != self.PLUGIN_NAME: - constraints_file = None - elif self.piptools_detached_mode is True: - constraints_file = None - else: - constraints_file = self.piptools_default_environment._piptools_lock_file - self.piptools_validate_default_lock(constraints_file=constraints_file) + constraints_file = environment._piptools_lock_file + environment.piptools_validate_lock( + constraints_file=constraints_file, environment=environment + ) return constraints_file - @property - def piptools_default_environment(self) -> "PipCompileEnvironment": + def get_piptools_environment(self, environment_name: str) -> "PipCompileEnvironment": """ - Get default pip compile environment + Get a `PipCompileEnvironment` instance for an environment + other than the current instance. This is useful + for recursively checking other environments for lock file + validity and defining inheritance. """ - default_env = PipCompileEnvironment( + if environment_name not in self.pipools_environment_dict.keys(): + error_message = ( + f"[hatch-pip-compile] The environment {environment_name} does not exist." + ) + raise HatchPipCompileError(error_message) + return PipCompileEnvironment( root=self.root, metadata=self.metadata, - name=self._default_env_name, - config=self.metadata.hatch.config["envs"].get(self._default_env_name, {}), + name=environment_name, + config=self.pipools_environment_dict.get(environment_name, {}), matrix_variables=self.matrix_variables, data_directory=self.data_directory, isolated_data_directory=self.isolated_data_directory, @@ -233,38 +245,50 @@ def piptools_default_environment(self) -> "PipCompileEnvironment": verbosity=self.verbosity, app=self.app, ) - return default_env - def piptools_validate_default_lock(self, constraints_file: Optional[pathlib.Path]) -> None: + def piptools_validate_lock( + self, constraints_file: Optional[pathlib.Path], environment: "PipCompileEnvironment" + ) -> None: """ - Validate the default lock file + Validate the lock file Parameters ---------- constraints_file : Optional[pathlib.Path] - The optional default lock file + The optional lock file + environment : PipCompileEnvironment + The environment to validate against Raises ------ LockFileNotFoundError - If the default lock file does not exist + If the lock file does not exist HatchPipCompileError - If the default lock file is out of date + If the lock file is out of date """ if constraints_file is None: return elif not constraints_file.exists(): error_message = ( - f"[hatch-pip-compile] The default lock file {constraints_file} does not exist." + f"[hatch-pip-compile] The lock file {constraints_file} does not exist. " + f"Please create it: `hatch env create {environment.name}`" ) raise LockFileNotFoundError(error_message) else: - up_to_date = self.piptools_default_environment.piptools_lock.compare_requirements( - requirements=self.piptools_default_environment.dependencies_complex + up_to_date = environment.piptools_lock.compare_requirements( + requirements=environment.dependencies_complex ) if up_to_date is False: error_message = ( - f"[hatch-pip-compile] The default lock file {constraints_file} is out of date. " - "Please update it." + f"[hatch-pip-compile] The lock file {constraints_file} is out of date. " + "Please update it: " + f"`hatch env run --env {environment.name} -- python --version`" ) raise HatchPipCompileError(error_message) + + @property + def pipools_environment_dict(self) -> Dict[str, Any]: + """ + Get the environment dictionary + """ + return self.metadata.hatch.config.get("envs", {}) diff --git a/pyproject.toml b/pyproject.toml index f2c09ab..a5ed82b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ python = ["3.8", "3.9", "3.10", "3.11", "3.12"] [tool.hatch.envs.default] path = ".venv" +pip-compile-constraint = "default" post-install-commands = [ "pre-commit install" ] From e537a00b30fb0a7e8498919fee1fc7e870da7c37 Mon Sep 17 00:00:00 2001 From: juftin Date: Fri, 24 Nov 2023 19:59:06 -0700 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9D=20pip-compile-constraint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++---- docs/index.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 162 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6b4f3f2..5ac962d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ at `requirements.txt` (non-default lockfiles are located at `requirements/requirements-{env_name}.txt`). Alongside `pip-compile`, this plugin also uses [pip-sync] to install the dependencies from the lockfile into your environment. +See [lock-filename](#lock-filename) for more information on changing the default +lockfile paths and [pip-compile-constraint](#pip-compile-constraint) for more +information on syncing dependency versions across environments. + ## Configuration The [environment plugin] name is `pip-compile`. Set your environment @@ -70,12 +74,13 @@ type to `pip-compile` to use this plugin for the respective environment. ### Configuration Options -| name | type | description | -| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | -| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | -| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | -| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | -| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | +| name | type | description | +| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | +| pip-compile-constraint | `str` | An environment to use as a constraint file, ensuring that all shared dependencies are pinned to the same versions. | +| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | +| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | +| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | #### Examples @@ -120,6 +125,75 @@ Changing the lock filename to a path in the project root: lock-filename = "linting-requirements.txt" ``` +##### pip-compile-constraint + +An environment to use as a constraint, ensuring that all shared dependencies are +pinned to the same versions. For example, if you have a `default` environment and +a `test` environment, you can set the `pip-compile-constraint` option to `default` +on the `test` environment to ensure that all shared dependencies are pinned to the +same versions. + +- **_pyproject.toml_** + + ```toml + [tool.hatch.envs.default] + type = "pip-compile" + + [tool.hatch.envs.test] + dependencies = [ + "pytest" + ] + type = "pip-compile" + pip-compile-constraint = "default" + ``` + +- **_hatch.toml_** + + ```toml + [envs.default] + type = "pip-compile" + + [envs.test] + dependencies = [ + "pytest" + ] + type = "pip-compile" + pip-compile-constraint = "default" + ``` + +By default, all environments inherit from the `default` environment via +[inheritance]. A common use case is to set the `pip-compile-constraint` +and `type` options on the `default` environment and inherit them on +all other environments. It's important to note that when `detached = true`, +inheritance is disabled and the `type` and `pip-compile-constraint` options +must be set explicitly. + +- **_pyproject.toml_** + + ```toml + [tool.hatch.envs.default] + type = "pip-compile" + pip-compile-constraint = "default" + + [tool.hatch.envs.test] + dependencies = [ + "pytest" + ] + ``` + +- **_hatch.toml_** + + ```toml + [envs.default] + type = "pip-compile" + pip-compile-constraint = "default" + + [envs.test] + dependencies = [ + "pytest" + ] + ``` + ##### pip-compile-hashes Whether to generate hashes in the lockfile. Defaults to `true`. @@ -241,3 +315,4 @@ pip install hatch hatch-pip-compile [Changelog]: https://github.com/juftin/hatch-pip-compile/releases [environment plugin]: https://hatch.pypa.io/latest/plugins/environment/ [pip]: https://pip.pypa.io/en/stable/ +[inheritance]: https://hatch.pypa.io/1.7/config/environment/overview/#inheritance diff --git a/docs/index.md b/docs/index.md index 503f9d4..bc26b40 100644 --- a/docs/index.md +++ b/docs/index.md @@ -49,6 +49,10 @@ at `requirements.txt` (non-default lockfiles are located at `requirements/requirements-{env_name}.txt`). Alongside `pip-compile`, this plugin also uses [pip-sync] to install the dependencies from the lockfile into your environment. +See [lock-filename](#lock-filename) for more information on changing the default +lockfile paths and [pip-compile-constraint](#pip-compile-constraint) for more +information on syncing dependency versions across environments. + ## Configuration The [environment plugin] name is `pip-compile`. Set your environment @@ -70,12 +74,13 @@ type to `pip-compile` to use this plugin for the respective environment. ### Configuration Options -| name | type | description | -| ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | -| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | -| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | -| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | -| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | +| name | type | description | +| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| lock-filename | `str` | The filename of the ultimate lockfile. `default` env is `requirements.txt`, non-default is `requirements/requirements-{env_name}.txt` | +| pip-compile-constraint | `str` | An environment to use as a constraint file, ensuring that all shared dependencies are pinned to the same versions. | +| pip-compile-hashes | `bool` | Whether to generate hashes in the lockfile. Defaults to `true`. | +| pip-compile-verbose | `bool` | Set to `true` to run `pip-compile` in verbose mode instead of quiet mode, set to `false` to silence warnings | +| pip-compile-args | `list[str]` | Additional command-line arguments to pass to `pip-compile` | #### Examples @@ -120,6 +125,75 @@ Changing the lock filename to a path in the project root: lock-filename = "linting-requirements.txt" ``` +##### pip-compile-constraint + +An environment to use as a constraint, ensuring that all shared dependencies are +pinned to the same versions. For example, if you have a `default` environment and +a `test` environment, you can set the `pip-compile-constraint` option to `default` +on the `test` environment to ensure that all shared dependencies are pinned to the +same versions. + +- **_pyproject.toml_** + + ```toml + [tool.hatch.envs.default] + type = "pip-compile" + + [tool.hatch.envs.test] + dependencies = [ + "pytest" + ] + type = "pip-compile" + pip-compile-constraint = "default" + ``` + +- **_hatch.toml_** + + ```toml + [envs.default] + type = "pip-compile" + + [envs.test] + dependencies = [ + "pytest" + ] + type = "pip-compile" + pip-compile-constraint = "default" + ``` + +By default, all environments inherit from the `default` environment via +[inheritance]. A common use case is to set the `pip-compile-constraint` +and `type` options on the `default` environment and inherit them on +all other environments. It's important to note that when `detached = true`, +inheritance is disabled and the `type` and `pip-compile-constraint` options +must be set explicitly. + +- **_pyproject.toml_** + + ```toml + [tool.hatch.envs.default] + type = "pip-compile" + pip-compile-constraint = "default" + + [tool.hatch.envs.test] + dependencies = [ + "pytest" + ] + ``` + +- **_hatch.toml_** + + ```toml + [envs.default] + type = "pip-compile" + pip-compile-constraint = "default" + + [envs.test] + dependencies = [ + "pytest" + ] + ``` + ##### pip-compile-hashes Whether to generate hashes in the lockfile. Defaults to `true`. @@ -231,3 +305,4 @@ pip install hatch hatch-pip-compile [Changelog]: https://github.com/juftin/hatch-pip-compile/releases [environment plugin]: https://hatch.pypa.io/latest/plugins/environment/ [pip]: https://pip.pypa.io/en/stable/ +[inheritance]: https://hatch.pypa.io/1.7/config/environment/overview/#inheritance