From 01973490338e5781e9a77a1832f5934ba0eda792 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:45:19 -0800 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#1667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 24.1.1 → 24.2.0](https://github.com/psf/black/compare/24.1.1...24.2.0) - [github.com/asottile/pyupgrade: v3.15.0 → v3.15.1](https://github.com/asottile/pyupgrade/compare/v3.15.0...v3.15.1) * Exempt flake8 E501 + let black do it's thing --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Cooper Ry Lees --- .flake8 | 2 +- .pre-commit-config.yaml | 4 +- docs/conf.py | 36 ++++--- src/bandersnatch/mirror.py | 10 +- src/bandersnatch/simple.py | 56 +++++----- .../tests/plugins/test_filename.py | 12 ++- .../tests/plugins/test_storage_plugins.py | 13 ++- src/bandersnatch/tests/test_mirror.py | 44 ++++---- .../tests/test_simple_fixtures.py | 100 ++++++++++-------- src/bandersnatch/utils.py | 37 ++++--- 10 files changed, 175 insertions(+), 139 deletions(-) diff --git a/.flake8 b/.flake8 index 0d0a51ef6..52b065f41 100644 --- a/.flake8 +++ b/.flake8 @@ -6,7 +6,7 @@ max_line_length = 88 # E722 is a duplicate of B001. # P207 is a duplicate of B003. # W503 is against PEP8 -ignore = E203, E704, E722, P207, W503 +ignore = E203, E501, E704, E722, P207, W503 max-complexity = 20 exclude = build, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1ac2337a..129bed578 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,13 +10,13 @@ repos: exclude: ^docs/conf.py$ - repo: https://github.com/psf/black - rev: 24.1.1 + rev: 24.2.0 hooks: - id: black args: [--target-version, py38, --preview] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.1 hooks: - id: pyupgrade args: [--py310-plus] diff --git a/docs/conf.py b/docs/conf.py index 17998752b..541006d0e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -214,13 +214,15 @@ class DocStub: # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). -latex_documents = [( - "index", - doc_module.__name__ + ".tex", - doc_module.__name__ + " Documentation", - "PyPA", - "manual", -)] +latex_documents = [ + ( + "index", + doc_module.__name__ + ".tex", + doc_module.__name__ + " Documentation", + "PyPA", + "manual", + ) +] # The name of an image file (relative to this directory) to place at the top of # the title page. @@ -260,15 +262,17 @@ class DocStub: # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) -texinfo_documents = [( - "index", - doc_module.__name__, - doc_module.__name__ + " Documentation", - "", - doc_module.__name__, - doc_module.__name__ + " Documentation", - "Miscellaneous", -)] +texinfo_documents = [ + ( + "index", + doc_module.__name__, + doc_module.__name__ + " Documentation", + "", + doc_module.__name__, + doc_module.__name__ + " Documentation", + "Miscellaneous", + ) +] # Documents to append as an appendix to all manuals. # texinfo_appendices = [] diff --git a/src/bandersnatch/mirror.py b/src/bandersnatch/mirror.py index 85776f3d6..d4eb83bf1 100644 --- a/src/bandersnatch/mirror.py +++ b/src/bandersnatch/mirror.py @@ -493,10 +493,12 @@ def _bootstrap(self, flock_timeout: float = 1.0) -> None: ] if self.json_save: logger.debug("Adding json directories to bootstrap") - paths.extend([ - self.storage_backend.PATH_BACKEND("web/json"), - self.storage_backend.PATH_BACKEND("web/pypi"), - ]) + paths.extend( + [ + self.storage_backend.PATH_BACKEND("web/json"), + self.storage_backend.PATH_BACKEND("web/pypi"), + ] + ) for path in paths: path = self.homedir / path if not path.exists(): diff --git a/src/bandersnatch/simple.py b/src/bandersnatch/simple.py index bdfd483e3..c657eedfb 100644 --- a/src/bandersnatch/simple.py +++ b/src/bandersnatch/simple.py @@ -115,9 +115,13 @@ def find_packages_in_dir(self, simple_dir: Path) -> list[str]: """Given a directory that contains simple packages indexes, return a sorted list of normalized package names. This presumes every directory within is a simple package index directory.""" - return sorted({ - str(x.name) for x in self.storage_backend.scandir(simple_dir) if x.is_dir() - }) + return sorted( + { + str(x.name) + for x in self.storage_backend.scandir(simple_dir) + if x.is_dir() + } + ) def gen_html_file_tags(self, release: dict) -> str: file_tags = "" @@ -183,16 +187,18 @@ def generate_html_simple_page(self, package: Package) -> str: digest_name = self.digest_name - simple_page_content += "\n".join([ - ' {}
'.format( - self._file_url_to_local_url(r["url"]), - digest_name, - r["digests"][digest_name], - self.gen_html_file_tags(r), - r["filename"], - ) - for r in release_files - ]) + simple_page_content += "\n".join( + [ + ' {}
'.format( + self._file_url_to_local_url(r["url"]), + digest_name, + r["digests"][digest_name], + self.gen_html_file_tags(r), + r["filename"], + ) + for r in release_files + ] + ) simple_page_content += ( f"\n \n\n" @@ -219,17 +225,19 @@ def generate_json_simple_page( # Add release files into the JSON dict for r in release_files: - package_json["files"].append({ - "filename": r["filename"], - "hashes": { - self.digest_name: r["digests"][self.digest_name], - }, - "requires-python": r.get("requires_python", ""), - "size": r["size"], - "upload-time": r.get("upload_time_iso_8601", ""), - "url": self._file_url_to_local_url(r["url"]), - "yanked": r.get("yanked", False), - }) + package_json["files"].append( + { + "filename": r["filename"], + "hashes": { + self.digest_name: r["digests"][self.digest_name], + }, + "requires-python": r.get("requires_python", ""), + "size": r["size"], + "upload-time": r.get("upload_time_iso_8601", ""), + "url": self._file_url_to_local_url(r["url"]), + "yanked": r.get("yanked", False), + } + ) if pretty: return json.dumps(package_json, indent=4) diff --git a/src/bandersnatch/tests/plugins/test_filename.py b/src/bandersnatch/tests/plugins/test_filename.py index ab2ae9cdb..cc42faf54 100644 --- a/src/bandersnatch/tests/plugins/test_filename.py +++ b/src/bandersnatch/tests/plugins/test_filename.py @@ -143,11 +143,13 @@ def test_exclude_platform(self) -> None: "flag": "DROP", }, ], - "0.2": [{ - "packagetype": "bdist_egg", - "filename": "foobar-0.1-freebsd-6.0-RELEASE-i386.egg", - "flag": "DROP", - }], + "0.2": [ + { + "packagetype": "bdist_egg", + "filename": "foobar-0.1-freebsd-6.0-RELEASE-i386.egg", + "flag": "DROP", + } + ], "0.3": [ { "packagetype": "bdist_wheel", diff --git a/src/bandersnatch/tests/plugins/test_storage_plugins.py b/src/bandersnatch/tests/plugins/test_storage_plugins.py index 91b2e3777..57787f6d5 100644 --- a/src/bandersnatch/tests/plugins/test_storage_plugins.py +++ b/src/bandersnatch/tests/plugins/test_storage_plugins.py @@ -942,11 +942,14 @@ def test_get_hash(self) -> None: class TestFilesystemStoragePlugin(BaseStoragePluginTestCase): backend = "filesystem" - base_find_contents = "\n".join([ - line - for line in BaseStoragePluginTestCase.base_find_contents.split("\n") - if "web{0}local-stats{0}days{0}.swiftkeep".format(os.path.sep) != line.strip() - ]) + base_find_contents = "\n".join( + [ + line + for line in BaseStoragePluginTestCase.base_find_contents.split("\n") + if "web{0}local-stats{0}days{0}.swiftkeep".format(os.path.sep) + != line.strip() + ] + ) class TestSwiftStoragePlugin(BaseStoragePluginTestCase): diff --git a/src/bandersnatch/tests/test_mirror.py b/src/bandersnatch/tests/test_mirror.py index 5582f20dd..a55c86e8c 100644 --- a/src/bandersnatch/tests/test_mirror.py +++ b/src/bandersnatch/tests/test_mirror.py @@ -38,26 +38,30 @@ def iter_content(*args: Any, **kwargs: Any) -> Iterator[bytes]: # master.get() returned data needs to have a .json() method and iter_content -FAKE_RELEASE_DATA = JsonDict({ - "info": {"name": "foo", "version": "0.1"}, - "last_serial": 654_321, - "releases": { - "0.1": [{ - "url": "https://pypi.example.com/packages/any/f/foo/foo.zip", - "filename": "foo.zip", - "digests": { - "md5": "ebdad75ed9a852bbfd9be4c18bf76d00", - "sha256": ( - "746e6da7eda8b75af9acbdd29808473df08a00362981f0949023e387da1a4734" - ), - }, - "md5_digest": "ebdad75ed9a852bbfd9be4c18bf76d00", - "packagetype": "sdist", - "size": 1234, - "upload_time_iso_8601": "2000-01-01T01:23:45.123456Z", - }] - }, -}) +FAKE_RELEASE_DATA = JsonDict( + { + "info": {"name": "foo", "version": "0.1"}, + "last_serial": 654_321, + "releases": { + "0.1": [ + { + "url": "https://pypi.example.com/packages/any/f/foo/foo.zip", + "filename": "foo.zip", + "digests": { + "md5": "ebdad75ed9a852bbfd9be4c18bf76d00", + "sha256": ( + "746e6da7eda8b75af9acbdd29808473df08a00362981f0949023e387da1a4734" + ), + }, + "md5_digest": "ebdad75ed9a852bbfd9be4c18bf76d00", + "packagetype": "sdist", + "size": 1234, + "upload_time_iso_8601": "2000-01-01T01:23:45.123456Z", + } + ] + }, + } +) def touch_files(paths: list[Path]) -> None: diff --git a/src/bandersnatch/tests/test_simple_fixtures.py b/src/bandersnatch/tests/test_simple_fixtures.py index 83c94b684..f0a422e45 100644 --- a/src/bandersnatch/tests/test_simple_fixtures.py +++ b/src/bandersnatch/tests/test_simple_fixtures.py @@ -36,29 +36,57 @@ }, "last_serial": 10333928, "releases": { - "0.69": [{ - "comment_text": "", - "digests": { - "md5": "4328d962656395fbd3e730c9d30bb48c", - "sha256": ( - "5c11f48399f9b1bca802751513f1f97bff6ce97e6facb576b7729e1351453c10" - ), - }, - "downloads": -1, - "filename": "69-0.69.tar.gz", - "has_sig": False, - "md5_digest": "4328d962656395fbd3e730c9d30bb48c", - "packagetype": "sdist", - "python_version": "source", - "requires_python": ">=3.6", - "size": 1078, - "upload_time": "2018-05-17T03:37:19", - "upload_time_iso_8601": "2018-05-17T03:37:19.330556Z", - "url": "https://files.pythonhosted.org/packages/d3/cc/95dc5434362bd333a1fec275231775d748315b26edf1e7e568e6f8660238/69-0.69.tar.gz", - "yanked": False, - "yanked_reason": None, - }], - "6.9": [{ + "0.69": [ + { + "comment_text": "", + "digests": { + "md5": "4328d962656395fbd3e730c9d30bb48c", + "sha256": ( + "5c11f48399f9b1bca802751513f1f97bff6ce97e6facb576b7729e1351453c10" + ), + }, + "downloads": -1, + "filename": "69-0.69.tar.gz", + "has_sig": False, + "md5_digest": "4328d962656395fbd3e730c9d30bb48c", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=3.6", + "size": 1078, + "upload_time": "2018-05-17T03:37:19", + "upload_time_iso_8601": "2018-05-17T03:37:19.330556Z", + "url": "https://files.pythonhosted.org/packages/d3/cc/95dc5434362bd333a1fec275231775d748315b26edf1e7e568e6f8660238/69-0.69.tar.gz", + "yanked": False, + "yanked_reason": None, + } + ], + "6.9": [ + { + "comment_text": "", + "digests": { + "md5": "ff4bf804ef3722a1fd8853a8a32513d4", + "sha256": ( + "0c8deb7c8574787283c3fc08b714ee63fd6752a38d13515a9d8508798d428597" + ), + }, + "downloads": -1, + "filename": "69-6.9.tar.gz", + "has_sig": False, + "md5_digest": "ff4bf804ef3722a1fd8853a8a32513d4", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=3.6", + "size": 1077, + "upload_time": "2018-05-17T03:47:45", + "upload_time_iso_8601": "2018-05-17T03:47:45.953704Z", + "url": "https://files.pythonhosted.org/packages/7b/6e/7c4ce77c6ca092e94e19b78282b459e7f8270362da655cbc6a75eeb9cdd7/69-6.9.tar.gz", + "yanked": False, + "yanked_reason": None, + } + ], + }, + "urls": [ + { "comment_text": "", "digests": { "md5": "ff4bf804ef3722a1fd8853a8a32513d4", @@ -79,30 +107,8 @@ "url": "https://files.pythonhosted.org/packages/7b/6e/7c4ce77c6ca092e94e19b78282b459e7f8270362da655cbc6a75eeb9cdd7/69-6.9.tar.gz", "yanked": False, "yanked_reason": None, - }], - }, - "urls": [{ - "comment_text": "", - "digests": { - "md5": "ff4bf804ef3722a1fd8853a8a32513d4", - "sha256": ( - "0c8deb7c8574787283c3fc08b714ee63fd6752a38d13515a9d8508798d428597" - ), - }, - "downloads": -1, - "filename": "69-6.9.tar.gz", - "has_sig": False, - "md5_digest": "ff4bf804ef3722a1fd8853a8a32513d4", - "packagetype": "sdist", - "python_version": "source", - "requires_python": ">=3.6", - "size": 1077, - "upload_time": "2018-05-17T03:47:45", - "upload_time_iso_8601": "2018-05-17T03:47:45.953704Z", - "url": "https://files.pythonhosted.org/packages/7b/6e/7c4ce77c6ca092e94e19b78282b459e7f8270362da655cbc6a75eeb9cdd7/69-6.9.tar.gz", - "yanked": False, - "yanked_reason": None, - }], + } + ], "vulnerabilities": [], } diff --git a/src/bandersnatch/utils.py b/src/bandersnatch/utils.py index 6a3fa1d6f..2c297f7cd 100644 --- a/src/bandersnatch/utils.py +++ b/src/bandersnatch/utils.py @@ -199,20 +199,27 @@ def parse_version(version: str) -> list[str]: tag_separator1 = "-" tag_separator2 = "." - _versions.extend([ - tag_separator1 + i + _version_without_dot + tag_separator1 for i in interpreters - ]) - _versions.extend([ - tag_separator1 - + INTERPRETER_SHORT_NAMES.get("python") - + _version_with_dot - + tag_separator1 - ]) - _versions.extend([ - tag_separator1 - + INTERPRETER_SHORT_NAMES.get("python") - + _version_with_dot - + tag_separator2 - ]) + _versions.extend( + [ + tag_separator1 + i + _version_without_dot + tag_separator1 + for i in interpreters + ] + ) + _versions.extend( + [ + tag_separator1 + + INTERPRETER_SHORT_NAMES.get("python") + + _version_with_dot + + tag_separator1 + ] + ) + _versions.extend( + [ + tag_separator1 + + INTERPRETER_SHORT_NAMES.get("python") + + _version_with_dot + + tag_separator2 + ] + ) return _versions