diff options
author | Sharlatan Hellseher <sharlatanus@gmail.com> | 2024-11-29 14:57:19 +0000 |
---|---|---|
committer | Sharlatan Hellseher <sharlatanus@gmail.com> | 2024-12-13 21:01:36 +0000 |
commit | a33c8eadd090c91011ea4fa78eed0ea7a6135a78 (patch) | |
tree | 1944f1351023dd9962972c5d5bfd64d3af06d9bb /gnu | |
parent | 372b1491a544871ae4b9c8f7d47123d51be8a876 (diff) | |
download | guix-a33c8eadd090c91011ea4fa78eed0ea7a6135a78.tar guix-a33c8eadd090c91011ea4fa78eed0ea7a6135a78.tar.gz |
gnu: python-pydocstyle: Update to 6.3.0.
* gnu/packages/python-xyz.scm (python-pydocstyle): Update to 6.3.0.
[source]: Swap to git checkout containing tests.
<patches>: Add patch published upstream to fix compatibility with PEP701.
[build-system]: Swap to pyrpoject-build-system.
[arguments]<test-flags>: Disable tests requiring pip install.
<phases>: Add 'set-version.
[native-inputs]: Add poetry-core, python-pytest, and python-tomli.
* gnu/packages/patches/python-pydocstyle-add-support-for-pep701.patch:
Add file.
* gnu/local.mk: Register patch.
Change-Id: Ia43906383ac454c3918d0c9335cb8f744443ad29
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/local.mk | 1 | ||||
-rw-r--r-- | gnu/packages/patches/python-pydocstyle-add-support-for-pep701.patch | 109 | ||||
-rw-r--r-- | gnu/packages/python-xyz.scm | 38 |
3 files changed, 139 insertions, 9 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index c8ab31f9e6..ffb8eb6d29 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1946,6 +1946,7 @@ dist_patch_DATA = \ %D%/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch \ %D%/packages/patches/python-random2-getrandbits-test.patch \ %D%/packages/patches/python-pillow-use-zlib-1.3.patch \ + %D%/packages/patches/python-pydocstyle-add-support-for-pep701.patch \ %D%/packages/patches/python-pyreadstat-link-libiconv.patch \ %D%/packages/patches/python-pyls-black-41.patch \ %D%/packages/patches/python-sip-include-dirs.patch \ diff --git a/gnu/packages/patches/python-pydocstyle-add-support-for-pep701.patch b/gnu/packages/patches/python-pydocstyle-add-support-for-pep701.patch new file mode 100644 index 0000000000..48404b601e --- /dev/null +++ b/gnu/packages/patches/python-pydocstyle-add-support-for-pep701.patch @@ -0,0 +1,109 @@ +From 306c7c8f2d863bdc098a65d2dadbd4703b9b16d5 Mon Sep 17 00:00:00 2001 +From: Alfred Wingate <parona@protonmail.com> +Date: Wed, 1 Nov 2023 11:12:08 +0200 +Subject: [PATCH] Add support for PEP701 + +* fstrings are broken into several distinct tokens in py3.12, reattach + them together as a singular string to preserve previous behavior. + +Closes: https://github.com/PyCQA/pydocstyle/issues/646 +Signed-off-by: Alfred Wingate <parona@protonmail.com> +--- + docs/release_notes.rst | 8 ++++++++ + src/pydocstyle/parser.py | 23 +++++++++++++++++++++++ + src/tests/parser_test.py | 29 +++++++++++++++++++++++++++++ + 3 files changed, 60 insertions(+) + +diff --git a/docs/release_notes.rst b/docs/release_notes.rst +index 46e36562..3db4c189 100644 +--- a/docs/release_notes.rst ++++ b/docs/release_notes.rst +@@ -4,6 +4,14 @@ Release Notes + **pydocstyle** version numbers follow the + `Semantic Versioning <http://semver.org/>`_ specification. + ++ ++Current development version ++--------------------------- ++ ++Bug Fixes ++ ++* Add support for PEP-701 fixing fstring parsing in python3.12 (#656). ++ + 6.3.0 - January 17th, 2023 + -------------------------- + +diff --git a/src/pydocstyle/parser.py b/src/pydocstyle/parser.py +index 95bd0a10..875f769d 100644 +--- a/src/pydocstyle/parser.py ++++ b/src/pydocstyle/parser.py +@@ -479,6 +479,29 @@ def parse_docstring(self): + ) + self.stream.move() + return docstring ++ if (sys.version_info.major, sys.version_info.minor) >= ( ++ 3, ++ 12, ++ ) and self.current.kind == tk.FSTRING_START: ++ ++ def fstring(string): ++ """Recursively parse fstring tokens to output it as one string.""" ++ while self.current.kind != tk.FSTRING_END: ++ self.stream.move() ++ string += self.current.value ++ if self.current.kind == tk.FSTRING_START: ++ string = fstring(string) ++ self.stream.move() ++ string += self.current.value ++ return string ++ ++ # Reattach fstring tokens together into a string to deal with PEP 701 in python3.12 ++ start = self.current.start[0] ++ string = fstring(self.current.value) ++ end = self.current.end[0] ++ docstring = Docstring(string, start, end) ++ self.stream.move() ++ return docstring + return None + + def parse_decorators(self): +diff --git a/src/tests/parser_test.py b/src/tests/parser_test.py +index 582c6cde..2c0bbaca 100644 +--- a/src/tests/parser_test.py ++++ b/src/tests/parser_test.py +@@ -114,6 +114,35 @@ def do_something(pos_param0, pos_param1, kw_param0="default"): + assert str(function) == 'in public function `do_something`' + + ++def test_nested_fstring(): ++ """Test parsing fstring with nested fstrings.""" ++ parser = Parser() ++ code = CodeSnippet("""\ ++ def do_something(pos_param0, pos_param1, kw_param0="default"): ++ f\"""Do something. {f"This is a nested fstring."}\""" ++ return None ++ """) ++ module = parser.parse(code, 'file_path') ++ assert module.is_public ++ assert module.dunder_all is None ++ ++ function, = module.children ++ assert function.name == 'do_something' ++ assert function.decorators == [] ++ assert function.children == [] ++ assert function.docstring == 'f"""Do something. {f"This is a nested fstring."}"""' ++ assert function.docstring.start == 2 ++ assert function.docstring.end == 2 ++ assert function.kind == 'function' ++ assert function.parent == module ++ assert function.start == 1 ++ assert function.end == 3 ++ assert function.error_lineno == 2 ++ assert function.source == code.getvalue() ++ assert function.is_public ++ assert str(function) == 'in public function `do_something`' ++ ++ + def test_decorated_function(): + """Test parsing of a simple function with a decorator.""" + parser = Parser() diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm index 9024137bed..5a138d18ee 100644 --- a/gnu/packages/python-xyz.scm +++ b/gnu/packages/python-xyz.scm @@ -8495,22 +8495,42 @@ in Markdown format. Instead of executing your Python code like so many other documentation tools, it parses it using docspec instead.") (license license:expat))) +;; XXX: The project is deprecated upstream, still in use by some packages, +;; consider to remove when nothing depends on it. (define-public python-pydocstyle (package (name "python-pydocstyle") - (version "3.0.0") + (version "6.3.0") (source (origin - (method url-fetch) - (uri (pypi-uri "pydocstyle" version)) + (method git-fetch) ;no tests in PyPI archive + (uri (git-reference + (url "https://github.com/PyCQA/pydocstyle") + (commit version))) + (file-name (git-file-name name version)) (sha256 - (base32 - "1m1xv9clkg9lgzyza6dnj359z04vh5g0h49nhzghv7lg81gchhap")))) - (build-system python-build-system) + (base32 "1aabvnxmy939y5b7jpnygpnkgbi4id9j461v7bwzxwdmdffnnd1j")) + (patches (search-patches + "python-pydocstyle-add-support-for-pep701.patch")))) + (build-system pyproject-build-system) + (arguments + (list + ;; It tries to install with pip. + #:test-flags #~(list "--ignore=src/tests/test_integration.py") + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'set-version + (lambda _ + (substitute* "pyproject.toml" + (("0.0.0-dev") #$version))))))) + (native-inputs + (list python-poetry-core + python-pytest + python-tomli)) (propagated-inputs - (list python-six python-snowballstemmer)) - (home-page - "https://github.com/PyCQA/pydocstyle/") + (list python-six + python-snowballstemmer)) + (home-page "https://github.com/PyCQA/pydocstyle/") (synopsis "Python docstring style checker") (description "This package provides a style checker for the Python Language |