From 15d6a3b946c7a463468bae8b74f979eed5f49c1f Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 6 Sep 2024 20:40:26 +0200 Subject: [PATCH 1/9] Add vendoring config for Grayskull's parse_poetry_version --- conda_lock/_vendor/vendor.txt | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/conda_lock/_vendor/vendor.txt b/conda_lock/_vendor/vendor.txt index 74d635f6..39897a88 100644 --- a/conda_lock/_vendor/vendor.txt +++ b/conda_lock/_vendor/vendor.txt @@ -2,6 +2,7 @@ cleo==2.1.0 poetry==1.8.3 poetry-core==1.9.0 +git+https://github.com/maresb/grayskull.git@d367c1605f320bae345b441b81ba38f5f72dc17e # install conda from github git+https://github.com/conda/conda.git@22.9.0 diff --git a/pyproject.toml b/pyproject.toml index cdd1608a..e01d83cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -151,6 +151,7 @@ drop = [ "poetry/utils/shell.py", "poetry/core/_vendor/six.py", "poetry/core/_vendor/six.LICENSE", + '^grayskull\/(?!strategy$|strategy\/parse_poetry_version\.py$|strategy\/__init__\.py$).*$', ] substitute = [ # simple substitution patch to fix conda.exports From 7ae0015555a59a55dbf8c8bceaa60bfb8fc16407 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 6 Sep 2024 20:45:25 +0200 Subject: [PATCH 2/9] Vendor Grayskull's parse_poetry_version --- conda_lock/_vendor/grayskull.pyi | 1 + conda_lock/_vendor/grayskull/LICENSE | 202 ++++++++++++++++ .../_vendor/grayskull/strategy/__init__.py | 0 .../strategy/parse_poetry_version.py | 224 ++++++++++++++++++ 4 files changed, 427 insertions(+) create mode 100644 conda_lock/_vendor/grayskull.pyi create mode 100644 conda_lock/_vendor/grayskull/LICENSE create mode 100644 conda_lock/_vendor/grayskull/strategy/__init__.py create mode 100644 conda_lock/_vendor/grayskull/strategy/parse_poetry_version.py diff --git a/conda_lock/_vendor/grayskull.pyi b/conda_lock/_vendor/grayskull.pyi new file mode 100644 index 00000000..03cda700 --- /dev/null +++ b/conda_lock/_vendor/grayskull.pyi @@ -0,0 +1 @@ +from grayskull import * \ No newline at end of file diff --git a/conda_lock/_vendor/grayskull/LICENSE b/conda_lock/_vendor/grayskull/LICENSE new file mode 100644 index 00000000..52cf42fd --- /dev/null +++ b/conda_lock/_vendor/grayskull/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2023 Marcelo Duarte Trevisani + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/conda_lock/_vendor/grayskull/strategy/__init__.py b/conda_lock/_vendor/grayskull/strategy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/conda_lock/_vendor/grayskull/strategy/parse_poetry_version.py b/conda_lock/_vendor/grayskull/strategy/parse_poetry_version.py new file mode 100644 index 00000000..65aba425 --- /dev/null +++ b/conda_lock/_vendor/grayskull/strategy/parse_poetry_version.py @@ -0,0 +1,224 @@ +import re +from typing import Dict, Optional + +import semver + +VERSION_REGEX = re.compile( + r"""^[vV]? + (?P0|[1-9]\d*) + (\. + (?P0|[1-9]\d*) + (\. + (?P0|[1-9]\d*) + )? + )?$ + """, + re.VERBOSE, +) + + +class InvalidVersion(BaseException): + pass + + +def parse_version(version: str) -> Dict[str, Optional[int]]: + """ + Parses a version string (not necessarily semver) to a dictionary with keys + "major", "minor", and "patch". "minor" and "patch" are possibly None. + + >>> parse_version("0") + {'major': 0, 'minor': None, 'patch': None} + >>> parse_version("1") + {'major': 1, 'minor': None, 'patch': None} + >>> parse_version("1.2") + {'major': 1, 'minor': 2, 'patch': None} + >>> parse_version("1.2.3") + {'major': 1, 'minor': 2, 'patch': 3} + """ + match = VERSION_REGEX.search(version) + if not match: + raise InvalidVersion(f"Could not parse version {version}.") + + return { + key: None if value is None else int(value) + for key, value in match.groupdict().items() + } + + +def vdict_to_vinfo(version_dict: Dict[str, Optional[int]]) -> semver.VersionInfo: + """ + Coerces version dictionary to a semver.VersionInfo object. If minor or patch + numbers are missing, 0 is substituted in their place. + """ + ver = {key: 0 if value is None else value for key, value in version_dict.items()} + return semver.VersionInfo(**ver) + + +def coerce_to_semver(version: str) -> str: + """ + Coerces a version string to a semantic version. + """ + if semver.VersionInfo.is_valid(version): + return version + + parsed_version = parse_version(version) + vinfo = vdict_to_vinfo(parsed_version) + return str(vinfo) + + +def get_caret_ceiling(target: str) -> str: + """ + Accepts a Poetry caret target and returns the exclusive version ceiling. + + Targets that are invalid semver strings (e.g. "1.2", "0") are handled + according to the Poetry caret requirements specification, which is based on + whether the major version is 0: + + - If the major version is 0, the ceiling is determined by bumping the + rightmost specified digit and then coercing it to semver. + Example: 0 => 1.0.0, 0.1 => 0.2.0, 0.1.2 => 0.1.3 + + - If the major version is not 0, the ceiling is determined by + coercing it to semver and then bumping the major version. + Example: 1 => 2.0.0, 1.2 => 2.0.0, 1.2.3 => 2.0.0 + + # Examples from Poetry docs + >>> get_caret_ceiling("0") + '1.0.0' + >>> get_caret_ceiling("0.0") + '0.1.0' + >>> get_caret_ceiling("0.0.3") + '0.0.4' + >>> get_caret_ceiling("0.2.3") + '0.3.0' + >>> get_caret_ceiling("1") + '2.0.0' + >>> get_caret_ceiling("1.2") + '2.0.0' + >>> get_caret_ceiling("1.2.3") + '2.0.0' + """ + if not semver.VersionInfo.is_valid(target): + target_dict = parse_version(target) + + if target_dict["major"] == 0: + if target_dict["minor"] is None: + target_dict["major"] += 1 + elif target_dict["patch"] is None: + target_dict["minor"] += 1 + else: + target_dict["patch"] += 1 + return str(vdict_to_vinfo(target_dict)) + + vdict_to_vinfo(target_dict) + return str(vdict_to_vinfo(target_dict).bump_major()) + + target_vinfo = semver.VersionInfo.parse(target) + + if target_vinfo.major == 0: + if target_vinfo.minor == 0: + return str(target_vinfo.bump_patch()) + else: + return str(target_vinfo.bump_minor()) + else: + return str(target_vinfo.bump_major()) + + +def get_tilde_ceiling(target: str) -> str: + """ + Accepts a Poetry tilde target and returns the exclusive version ceiling. + + # Examples from Poetry docs + >>> get_tilde_ceiling("1") + '2.0.0' + >>> get_tilde_ceiling("1.2") + '1.3.0' + >>> get_tilde_ceiling("1.2.3") + '1.3.0' + """ + target_dict = parse_version(target) + if target_dict["minor"]: + return str(vdict_to_vinfo(target_dict).bump_minor()) + + return str(vdict_to_vinfo(target_dict).bump_major()) + + +def encode_poetry_version(poetry_specifier: str) -> str: + """ + Encodes Poetry version specifier as a Conda version specifier. + + Example: ^1 => >=1.0.0,<2.0.0 + + # should be unchanged + >>> encode_poetry_version("1.*") + '1.*' + >>> encode_poetry_version(">=1,<2") + '>=1,<2' + >>> encode_poetry_version("==1.2.3") + '==1.2.3' + >>> encode_poetry_version("!=1.2.3") + '!=1.2.3' + + # strip spaces + >>> encode_poetry_version(">= 1, < 2") + '>=1,<2' + + # handle exact version specifiers correctly + >>> encode_poetry_version("1.2.3") + '1.2.3' + >>> encode_poetry_version("==1.2.3") + '==1.2.3' + + # handle caret operator correctly + # examples from Poetry docs + >>> encode_poetry_version("^0") + '>=0.0.0,<1.0.0' + >>> encode_poetry_version("^0.0") + '>=0.0.0,<0.1.0' + >>> encode_poetry_version("^0.0.3") + '>=0.0.3,<0.0.4' + >>> encode_poetry_version("^0.2.3") + '>=0.2.3,<0.3.0' + >>> encode_poetry_version("^1") + '>=1.0.0,<2.0.0' + >>> encode_poetry_version("^1.2") + '>=1.2.0,<2.0.0' + >>> encode_poetry_version("^1.2.3") + '>=1.2.3,<2.0.0' + + # handle tilde operator correctly + # examples from Poetry docs + >>> encode_poetry_version("~1") + '>=1.0.0,<2.0.0' + >>> encode_poetry_version("~1.2") + '>=1.2.0,<1.3.0' + >>> encode_poetry_version("~1.2.3") + '>=1.2.3,<1.3.0' + """ + poetry_clauses = poetry_specifier.split(",") + + conda_clauses = [] + for poetry_clause in poetry_clauses: + poetry_clause = poetry_clause.replace(" ", "") + if poetry_clause.startswith("^"): + # handle ^ operator + target = poetry_clause[1:] + floor = coerce_to_semver(target) + ceiling = get_caret_ceiling(target) + conda_clauses.append(">=" + floor) + conda_clauses.append("<" + ceiling) + continue + + if poetry_clause.startswith("~"): + # handle ~ operator + target = poetry_clause[1:] + floor = coerce_to_semver(target) + ceiling = get_tilde_ceiling(target) + conda_clauses.append(">=" + floor) + conda_clauses.append("<" + ceiling) + continue + + # other poetry clauses should be conda-compatible + conda_clauses.append(poetry_clause) + + return ",".join(conda_clauses) From 04490772219784beebbb70dc913f9e9f7a737939 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 6 Sep 2024 21:59:20 +0200 Subject: [PATCH 3/9] Add semver dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index e01d83cf..2b5b9fef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ "jinja2", "pydantic >=1.10", "pyyaml >= 5.1", + "semver >=3,<4", "setuptools", 'tomli ; python_version <"3.11"', "typing-extensions", From 05de5840de551904b40992ec3f36be66e6b0a57f Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Fri, 6 Sep 2024 21:48:39 +0200 Subject: [PATCH 4/9] Use Grayskull to parse versions --- conda_lock/src_parser/pyproject_toml.py | 64 ++++++++++++++----------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index c5f9e196..d803db1b 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -15,7 +15,6 @@ Optional, Sequence, Tuple, - Union, ) from urllib.parse import urldefrag @@ -29,6 +28,9 @@ from packaging.utils import canonicalize_name as canonicalize_pypi_name from typing_extensions import Literal +from conda_lock._vendor.grayskull.strategy.parse_poetry_version import ( + encode_poetry_version, +) from conda_lock.common import get_in from conda_lock.lookup import get_forward_lookup as get_lookup from conda_lock.models.lock_spec import ( @@ -69,10 +71,6 @@ ) -def join_version_components(pieces: Sequence[Union[str, int]]) -> str: - return ".".join(str(p) for p in pieces) - - def normalize_pypi_name(name: str) -> str: cname = canonicalize_pypi_name(name) if cname in get_lookup(): @@ -90,32 +88,40 @@ def normalize_pypi_name(name: str) -> str: def poetry_version_to_conda_version(version_string: Optional[str]) -> Optional[str]: + """Convert a Poetry-style version string to a Conda-compatible version string. + + >>> poetry_version_to_conda_version("1.2.3.4") + '1.2.3.4' + + >>> poetry_version_to_conda_version("1.2.3, 2.3, <=3.4") + '1.2.3,2.3,<=3.4' + + >>> poetry_version_to_conda_version("^0.14.2") + '>=0.14.2,<0.15.0' + + >>> poetry_version_to_conda_version("^1.2.3") + '>=1.2.3,<2.0.0' + + >>> poetry_version_to_conda_version("^0.0.1") + '>=0.0.1,<0.0.2' + + >>> poetry_version_to_conda_version("~1.2.3") + '>=1.2.3,<1.3.0' + + >>> poetry_version_to_conda_version("~1.2") + '>=1.2.0,<1.3.0' + + >>> poetry_version_to_conda_version("~1") + '>=1.0.0,<2.0.0' + + >>> poetry_version_to_conda_version(None) + + >>> poetry_version_to_conda_version("~1.2.3, ^2.3") + '>=1.2.3,<1.3.0,>=2.3.0,<3.0.0' + """ if version_string is None: return None - components = [c.replace(" ", "").strip() for c in version_string.split(",")] - output_components = [] - - for c in components: - if len(c) == 0: - continue - version_pieces = c.lstrip("<>=^~!").split(".") - if c[0] == "^": - upper_version = [int(version_pieces[0]) + 1] - for i in range(1, len(version_pieces)): - upper_version.append(0) - - output_components.append(f">={join_version_components(version_pieces)}") - output_components.append(f"<{join_version_components(upper_version)}") - elif c[0] == "~": - upper_version = [int(version_pieces[0]), int(version_pieces[1]) + 1] - for i in range(2, len(version_pieces)): - upper_version.append(0) - - output_components.append(f">={join_version_components(version_pieces)}") - output_components.append(f"<{join_version_components(upper_version)}") - else: - output_components.append(c.replace("===", "=").replace("==", "=")) - return ",".join(output_components) + return encode_poetry_version(version_string) def handle_mapping( From d143fc9b134c8792291babf61bbde42bffb04e75 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 7 Sep 2024 00:48:04 +0200 Subject: [PATCH 5/9] Adapt test output with trailing zeros in version number --- tests/test_conda_lock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index c3a0041b..074bab91 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -709,7 +709,7 @@ def test_parse_poetry(poetry_pyproject_toml: Path): } assert specs["python"].manager == "conda" - assert specs["python"].version == ">=3.7,<4.0" + assert specs["python"].version == ">=3.7.0,<4.0.0" assert specs["requests"].version == ">=2.13.0,<3.0.0" assert specs["toml"].version == ">=0.10" assert specs["sqlite"].version == ">=3.34" @@ -731,7 +731,7 @@ def test_parse_poetry_default_pip(poetry_pyproject_toml_default_pip: Path): } assert specs["python"].manager == "conda" - assert specs["python"].version == ">=3.7,<4.0" + assert specs["python"].version == ">=3.7.0,<4.0.0" assert specs["sqlite"].manager == "conda" assert specs["certifi"].manager == "conda" assert specs["requests"].manager == "pip" From 4e0a8bd12de31a4fccdec986fec749d3c8231168 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 7 Sep 2024 01:09:11 +0200 Subject: [PATCH 6/9] Reimplement previous replacement of === and == by = --- conda_lock/conda_lock.py | 1 + conda_lock/src_parser/pyproject_toml.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/conda_lock/conda_lock.py b/conda_lock/conda_lock.py index 2381229d..9c53cef2 100644 --- a/conda_lock/conda_lock.py +++ b/conda_lock/conda_lock.py @@ -634,6 +634,7 @@ def format_pip_requirement( s += f"#sha256={spec.hash.sha256}" return s else: + # TODO: Use of '===' is explicitly discouraged. Could we use == instead? s = f"{spec.name} === {spec.version}" if spec.hash.sha256: s += f" --hash=sha256:{spec.hash.sha256}" diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index d803db1b..337680ad 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -121,7 +121,17 @@ def poetry_version_to_conda_version(version_string: Optional[str]) -> Optional[s """ if version_string is None: return None - return encode_poetry_version(version_string) + conda_version = encode_poetry_version(version_string) + # Python's '===' is explicitly discouraged in PEP 440: + # + # Python's '==' seems equivalent to conda's '==': + # + # + # I'm unconvinced that this is correct, but let's replicate the previous behavior for now. + conda_version = conda_version.replace("===", "=").replace("==", "=") + # # I think the correct thing should be instead: + # conda_version = conda_version.replace("===", "==") + return conda_version def handle_mapping( From f8bb1ea7f457cff9acf2ebf1522c47fcdd3aaf09 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 7 Sep 2024 01:12:41 +0200 Subject: [PATCH 7/9] Only replace === by == --- conda_lock/src_parser/pyproject_toml.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 337680ad..a513eaed 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -127,10 +127,7 @@ def poetry_version_to_conda_version(version_string: Optional[str]) -> Optional[s # Python's '==' seems equivalent to conda's '==': # # - # I'm unconvinced that this is correct, but let's replicate the previous behavior for now. - conda_version = conda_version.replace("===", "=").replace("==", "=") - # # I think the correct thing should be instead: - # conda_version = conda_version.replace("===", "==") + conda_version = conda_version.replace("===", "==") return conda_version From 5c1122d7f9c7027a8c094aca54a8ce1190ba9de3 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 7 Sep 2024 01:36:29 +0200 Subject: [PATCH 8/9] Adjust tests to account for == --- tests/test_conda_lock.py | 2 +- tests/test_regression.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 074bab91..4899f2b4 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -447,7 +447,7 @@ def test_parse_environment_file_with_pip(pip_environment: Path): manager="pip", category="main", extras=[], - version="=0.9.1", + version="==0.9.1", ) ] diff --git a/tests/test_regression.py b/tests/test_regression.py index d602e30b..3d163183 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -105,6 +105,6 @@ def test_pip_environment_regression_gh449(pip_environment_regression_gh449: Path manager="pip", category="main", extras=["dotenv", "email"], - version="=1.10.10", + version="==1.10.10", ) ] From b7b36c416b58d02af26b8ce178eba3be962e7194 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 7 Sep 2024 14:34:08 +0200 Subject: [PATCH 9/9] Use == instead of === when specifying pip versions --- conda_lock/conda_lock.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conda_lock/conda_lock.py b/conda_lock/conda_lock.py index 9c53cef2..f1643261 100644 --- a/conda_lock/conda_lock.py +++ b/conda_lock/conda_lock.py @@ -634,8 +634,7 @@ def format_pip_requirement( s += f"#sha256={spec.hash.sha256}" return s else: - # TODO: Use of '===' is explicitly discouraged. Could we use == instead? - s = f"{spec.name} === {spec.version}" + s = f"{spec.name} == {spec.version}" if spec.hash.sha256: s += f" --hash=sha256:{spec.hash.sha256}" return s