From 003977941b8b3abdb28dc0ac02a786cfa87da594 Mon Sep 17 00:00:00 2001 From: moyiz <8603313+moyiz@users.noreply.github.com> Date: Sat, 30 Oct 2021 11:56:13 +0300 Subject: [PATCH 1/4] Bump pyparsing, update usages and update UT Add support to `pyparsing>=3.0.0`. Changes required: - `originalTextFor` -> `original_text_for` - `stringEnd` -> `string_end` - `stringStart` -> `string_start` Update UT: `test_parseexception_error_msg` to check for `string_end` instead of `stringEnd` in exception message. --- packaging/markers.py | 6 +++--- packaging/requirements.py | 12 ++++++------ setup.py | 2 +- tests/test_requirements.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packaging/markers.py b/packaging/markers.py index cb640e8f..e4d6f057 100644 --- a/packaging/markers.py +++ b/packaging/markers.py @@ -16,8 +16,8 @@ ParseResults, QuotedString, ZeroOrMore, - stringEnd, - stringStart, + string_end, + string_start, ) from .specifiers import InvalidSpecifier, Specifier @@ -135,7 +135,7 @@ def serialize(self) -> str: MARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN) MARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR) -MARKER = stringStart + MARKER_EXPR + stringEnd +MARKER = string_start + MARKER_EXPR + string_end def _coerce_parse_result(results: Union[ParseResults, List[Any]]) -> List[Any]: diff --git a/packaging/requirements.py b/packaging/requirements.py index 53f9a3aa..cf00901f 100644 --- a/packaging/requirements.py +++ b/packaging/requirements.py @@ -15,9 +15,9 @@ Regex, Word, ZeroOrMore, - originalTextFor, - stringEnd, - stringStart, + original_text_for, + string_end, + string_start, ) from .markers import MARKER_EXPR, Marker @@ -63,10 +63,10 @@ class InvalidRequirement(ValueError): _VERSION_SPEC = Optional((LPAREN + VERSION_MANY + RPAREN) | VERSION_MANY) _VERSION_SPEC.setParseAction(lambda s, l, t: t._raw_spec or "") -VERSION_SPEC = originalTextFor(_VERSION_SPEC)("specifier") +VERSION_SPEC = original_text_for(_VERSION_SPEC)("specifier") VERSION_SPEC.setParseAction(lambda s, l, t: t[1]) -MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker") +MARKER_EXPR = original_text_for(MARKER_EXPR())("marker") MARKER_EXPR.setParseAction( lambda s, l, t: Marker(s[t._original_start : t._original_end]) ) @@ -78,7 +78,7 @@ class InvalidRequirement(ValueError): NAMED_REQUIREMENT = NAME + Optional(EXTRAS) + (URL_AND_MARKER | VERSION_AND_MARKER) -REQUIREMENT = stringStart + NAMED_REQUIREMENT + stringEnd +REQUIREMENT = string_start + NAMED_REQUIREMENT + string_end # pyparsing isn't thread safe during initialization, so we do it eagerly, see # issue #104 REQUIREMENT.parseString("x[]") diff --git a/setup.py b/setup.py index c6a1caec..8839ba68 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ author=about["__author__"], author_email=about["__email__"], python_requires=">=3.6", - install_requires=["pyparsing>=2.0.2,<3"], # Needed to avoid issue #91 + install_requires=["pyparsing>=3.0.0"], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", diff --git a/tests/test_requirements.py b/tests/test_requirements.py index 8cc45687..6a764259 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -192,4 +192,4 @@ def test_sys_platform_linux_in(self): def test_parseexception_error_msg(self): with pytest.raises(InvalidRequirement) as e: Requirement("toto 42") - assert "Expected stringEnd" in str(e.value) + assert "Expected string_end" in str(e.value) From 478d8a05c35aa73b091b0223728c2f1d765fa291 Mon Sep 17 00:00:00 2001 From: moyiz <8603313+moyiz@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:09:47 +0300 Subject: [PATCH 2/4] session.install for lint Install current `packaging` and its dependencies during lint. `nox` depends on `packaging`, by installing `nox` during lint phase, `packaging` dependencies defined in working branch are overridden by latest `packaging` release dependencies. In this case, since the PR changes the constraints on `pyparsing`, without a `session.install(".")` the incorrect `pyparsing` version will be installed. --- noxfile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/noxfile.py b/noxfile.py index 956201a6..b57bb841 100644 --- a/noxfile.py +++ b/noxfile.py @@ -59,6 +59,9 @@ def lint(session): session.install("pre-commit") session.run("pre-commit", "run", "--all-files") + # Install current package and dependencies + session.install(".") + # Check the distribution session.install("build", "twine") session.run("python", "-m", "build") From b8e9b5c4067e0de2644a7a8f81773db365eddbab Mon Sep 17 00:00:00 2001 From: moyiz <8603313+moyiz@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:36:05 +0300 Subject: [PATCH 3/4] Install current packaging before build This ensures that we install the dependencies of current working branch of `packaging`. Similar to previous commit. `build` package depends on `packaging` and installing it overrides the dependencies of current working branch by the dependencies of latest `packaging` release. --- .github/workflows/lint.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d03f16fd..c4a8d026 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,6 +49,9 @@ jobs: - name: Install dependencies run: python -m pip install --upgrade build + - name: Install package and dependencies + run: python -m pip install -e . + - name: Build run: python -m build From c319f2a22d672b2f0dfe0e32c537cc43d10a7349 Mon Sep 17 00:00:00 2001 From: Moyiz <8603313+moyiz@users.noreply.github.com> Date: Mon, 1 Nov 2021 15:28:45 +0200 Subject: [PATCH 4/4] Remove re-installation in favor of stateless build See: https://github.com/pypa/packaging/pull/480/files#r740158146 As suggested by @layday, local `packaging` package directory takes precedence over the installed `packaging`. By building with `pyproject-build`, CWD will not be added to python path. --- .github/workflows/lint.yml | 5 +---- noxfile.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4a8d026..f37e6346 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -49,11 +49,8 @@ jobs: - name: Install dependencies run: python -m pip install --upgrade build - - name: Install package and dependencies - run: python -m pip install -e . - - name: Build - run: python -m build + run: pyproject-build - name: Archive files uses: actions/upload-artifact@v1 diff --git a/noxfile.py b/noxfile.py index b57bb841..10564101 100644 --- a/noxfile.py +++ b/noxfile.py @@ -59,12 +59,9 @@ def lint(session): session.install("pre-commit") session.run("pre-commit", "run", "--all-files") - # Install current package and dependencies - session.install(".") - # Check the distribution session.install("build", "twine") - session.run("python", "-m", "build") + session.run("pyproject-build") session.run("twine", "check", *glob.glob("dist/*"))