Commit 66bb5644 by Bartek Sokorski Committed by Bartosz Sokorski

Migrate from flake8 to ruff

parent dd483c8c
[flake8]
min_python_version = 3.7.0
max-line-length = 88
ban-relative-imports = true
# flake8-use-fstring: https://github.com/MichaelKim0407/flake8-use-fstring#--percent-greedy-and---format-greedy
format-greedy = 1
inline-quotes = double
enable-extensions = TC, TC1
type-checking-strict = true
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E203: Whitespace before ':' (pycqa/pycodestyle#373)
E203,
# SIM106: Handle error-cases first
SIM106,
# ANN101: Missing type annotation for self in method
ANN101,
# ANN102: Missing type annotation for cls in classmethod
ANN102,
# PIE781: assign-and-return
PIE781,
# PIE798 no-unnecessary-class: Consider using a module for namespacing instead
PIE798,
per-file-ignores =
# TC002: Move third-party import '...' into a type-checking block
__init__.py:TC002,
# ANN201: Missing return type annotation for public function
tests/test_*:ANN201
tests/**/test_*:ANN201
extend-exclude =
# Frozen and not subject to change in this repo:
get-poetry.py,
install-poetry.py,
# External to the project's coding standards:
tests/fixtures/*,
tests/**/fixtures/*,
...@@ -27,24 +27,6 @@ repos: ...@@ -27,24 +27,6 @@ repos:
- id: python-use-type-annotations - id: python-use-type-annotations
- id: python-check-blanket-noqa - id: python-check-blanket-noqa
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: &flake8_deps
- flake8-annotations==3.0.0
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8-eradicate==1.4.0
- flake8-pie==0.16.0
- flake8-quotes==3.3.2
- flake8-simplify==0.19.3
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.3.0
- flake8-typing-imports==1.14.0
- flake8-use-fstring==1.4
- pep8-naming==0.13.3
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v3.3.1 rev: v3.3.1
hooks: hooks:
...@@ -80,14 +62,12 @@ repos: ...@@ -80,14 +62,12 @@ repos:
hooks: hooks:
- id: black - id: black
- repo: https://github.com/pycqa/flake8
# freeze to commit rev to prevent automatic updates, since newer versions of flake8 are not compatible with plugins
rev: 6027577d325b0dd8bf1e465ebd29b71b5f0d005b
hooks:
- id: flake8
additional_dependencies: *flake8_deps
- repo: https://github.com/pre-commit/pre-commit - repo: https://github.com/pre-commit/pre-commit
rev: v2.21.0 rev: v2.21.0
hooks: hooks:
- id: validate_manifest - id: validate_manifest
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.262
hooks:
- id: ruff
...@@ -122,6 +122,41 @@ requires = ["poetry-core>=1.1.0"] ...@@ -122,6 +122,41 @@ requires = ["poetry-core>=1.1.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.ruff]
fix = true
unfixable = [
"ERA", # do not autoremove commented out code
]
target-version = "py37"
line-length = 88
extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"ERA", # flake8-eradicate/eradicate
"PIE", # flake8-pie
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"N", # pep8-naming
"RUF", # ruff checks
]
ignore = [
"B904", # use 'raise ... from err'
"B905", # use explicit 'strict=' parameter with 'zip()'
"N818" # Exception name should be named with an Error suffix
]
extend-exclude = [
"docs/*",
# Frozen and not subject to change in this repo
"install-poetry.py",
# External to the project's coding standards
"tests/**/fixtures/*",
]
[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
[tool.isort] [tool.isort]
py_version = 37 py_version = 37
profile = "black" profile = "black"
......
...@@ -202,7 +202,7 @@ class Application(BaseApplication): ...@@ -202,7 +202,7 @@ class Application(BaseApplication):
from poetry.console.io.inputs.run_argv_input import RunArgvInput from poetry.console.io.inputs.run_argv_input import RunArgvInput
input = cast("ArgvInput", io.input) input = cast("ArgvInput", io.input)
run_input = RunArgvInput([self._name or ""] + input._tokens) run_input = RunArgvInput([self._name or "", *input._tokens])
# For the run command reset the definition # For the run command reset the definition
# with only the set options (i.e. the options given before the command) # with only the set options (i.e. the options given before the command)
for option_name, value in input.options.items(): for option_name, value in input.options.items():
......
...@@ -67,8 +67,9 @@ list of installed packages ...@@ -67,8 +67,9 @@ list of installed packages
] ]
for group_name, section in [ for group_name, section in [
(MAIN_GROUP, poetry_content["dependencies"]) (MAIN_GROUP, poetry_content["dependencies"]),
] + group_sections: *group_sections,
]:
removed += self._remove_packages(packages, section, group_name) removed += self._remove_packages(packages, section, group_name)
if group_name != MAIN_GROUP: if group_name != MAIN_GROUP:
if not section: if not section:
......
...@@ -26,5 +26,5 @@ class IOHandler(logging.Handler): ...@@ -26,5 +26,5 @@ class IOHandler(logging.Handler):
self._io.write_error_line(msg) self._io.write_error_line(msg)
else: else:
self._io.write_line(msg) self._io.write_line(msg)
except Exception: # noqa: PIE786 except Exception:
self.handleError(record) self.handleError(record)
...@@ -63,7 +63,7 @@ PEP517_META_BUILD_DEPS = ["build==0.10.0", "pyproject_hooks==1.0.0"] ...@@ -63,7 +63,7 @@ PEP517_META_BUILD_DEPS = ["build==0.10.0", "pyproject_hooks==1.0.0"]
class PackageInfoError(ValueError): class PackageInfoError(ValueError):
def __init__(self, path: Path, *reasons: BaseException | str) -> None: def __init__(self, path: Path, *reasons: BaseException | str) -> None:
reasons = (f"Unable to determine package info for path: {path!s}",) + reasons reasons = (f"Unable to determine package info for path: {path!s}", *reasons)
super().__init__("\n\n".join(str(msg).strip() for msg in reasons if msg)) super().__init__("\n\n".join(str(msg).strip() for msg in reasons if msg))
......
...@@ -155,7 +155,7 @@ class Chef: ...@@ -155,7 +155,7 @@ class Chef:
context: Callable[ context: Callable[
[str], AbstractContextManager[zipfile.ZipFile | tarfile.TarFile] [str], AbstractContextManager[zipfile.ZipFile | tarfile.TarFile]
] ]
if suffix == ".zip": if suffix == ".zip": # noqa: SIM108
context = zipfile.ZipFile context = zipfile.ZipFile
else: else:
context = tarfile.open context = tarfile.open
......
...@@ -291,7 +291,7 @@ class Executor: ...@@ -291,7 +291,7 @@ class Executor:
# error to be picked up by the error handler. # error to be picked up by the error handler.
if result == -2: if result == -2:
raise KeyboardInterrupt raise KeyboardInterrupt
except Exception as e: # noqa: PIE786 except Exception as e:
try: try:
from cleo.ui.exception_trace import ExceptionTrace from cleo.ui.exception_trace import ExceptionTrace
......
...@@ -671,18 +671,18 @@ class Provider: ...@@ -671,18 +671,18 @@ class Provider:
# the requirements will be merged. # the requirements will be merged.
# #
# For instance: # For instance:
# - enum34; python_version=="2.7" # enum34; python_version=="2.7"
# - enum34; python_version=="3.3" # enum34; python_version=="3.3"
# #
# will become: # will become:
# - enum34; python_version=="2.7" or python_version=="3.3" # enum34; python_version=="2.7" or python_version=="3.3"
# #
# If the duplicate dependencies have different constraints # If the duplicate dependencies have different constraints
# we have to split the dependency graph. # we have to split the dependency graph.
# #
# An example of this is: # An example of this is:
# - pypiwin32 (220); sys_platform == "win32" and python_version >= "3.6" # pypiwin32 (220); sys_platform == "win32" and python_version >= "3.6"
# - pypiwin32 (219); sys_platform == "win32" and python_version < "3.6" # pypiwin32 (219); sys_platform == "win32" and python_version < "3.6"
duplicates: dict[str, list[Dependency]] = defaultdict(list) duplicates: dict[str, list[Dependency]] = defaultdict(list)
for dep in dependencies: for dep in dependencies:
duplicates[dep.complete_name].append(dep) duplicates[dep.complete_name].append(dep)
...@@ -702,19 +702,19 @@ class Provider: ...@@ -702,19 +702,19 @@ class Provider:
for group in dep_groups: for group in dep_groups:
# In order to reduce the number of overrides we merge duplicate # In order to reduce the number of overrides we merge duplicate
# dependencies by constraint. For instance, if we have: # dependencies by constraint. For instance, if we have:
# - foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7" # foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7"
# - foo (>=2.0) ; python_version >= "3.7" # foo (>=2.0) ; python_version >= "3.7"
# we can avoid two overrides by merging them to: # we can avoid two overrides by merging them to:
# - foo (>=2.0) ; python_version >= "3.6" # foo (>=2.0) ; python_version >= "3.6"
# However, if we want to merge dependencies by constraint we have to # However, if we want to merge dependencies by constraint we have to
# merge dependencies by markers first in order to avoid unnecessary # merge dependencies by markers first in order to avoid unnecessary
# solver failures. For instance, if we have: # solver failures. For instance, if we have:
# - foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7" # foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7"
# - foo (>=2.0) ; python_version >= "3.7" # foo (>=2.0) ; python_version >= "3.7"
# - foo (<2.1) ; python_version >= "3.7" # foo (<2.1) ; python_version >= "3.7"
# we must not merge the first two constraints but the last two: # we must not merge the first two constraints but the last two:
# - foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7" # foo (>=2.0) ; python_version >= "3.6" and python_version < "3.7"
# - foo (>=2.0,<2.1) ; python_version >= "3.7" # foo (>=2.0,<2.1) ; python_version >= "3.7"
deps += self._merge_dependencies_by_constraint( deps += self._merge_dependencies_by_constraint(
self._merge_dependencies_by_marker(group) self._merge_dependencies_by_marker(group)
) )
...@@ -748,13 +748,13 @@ class Provider: ...@@ -748,13 +748,13 @@ class Provider:
# tell the solver to make new resolutions with specific overrides. # tell the solver to make new resolutions with specific overrides.
# #
# For instance, if the foo (1.2.3) package has the following dependencies: # For instance, if the foo (1.2.3) package has the following dependencies:
# - bar (>=2.0) ; python_version >= "3.6" # bar (>=2.0) ; python_version >= "3.6"
# - bar (<2.0) ; python_version < "3.6" # bar (<2.0) ; python_version < "3.6"
# #
# then the solver will need to make two new resolutions # then the solver will need to make two new resolutions
# with the following overrides: # with the following overrides:
# - {<Package foo (1.2.3): {"bar": <Dependency bar (>=2.0)>} # {<Package foo (1.2.3): {"bar": <Dependency bar (>=2.0)>}
# - {<Package foo (1.2.3): {"bar": <Dependency bar (<2.0)>} # {<Package foo (1.2.3): {"bar": <Dependency bar (<2.0)>}
def fmt_warning(d: Dependency) -> str: def fmt_warning(d: Dependency) -> str:
dependency_marker = d.marker if not d.marker.is_any() else "*" dependency_marker = d.marker if not d.marker.is_any() else "*"
...@@ -1005,16 +1005,16 @@ class Provider: ...@@ -1005,16 +1005,16 @@ class Provider:
environment markers to the inverse of the union of the environment markers to the inverse of the union of the
other dependencies markers. other dependencies markers.
For instance, if we have the following dependencies: For instance, if we have the following dependencies:
- ipython ipython
- ipython (1.2.4) ; implementation_name == "pypy" ipython (1.2.4) ; implementation_name == "pypy"
the marker for `ipython` will become `implementation_name != "pypy"`. the marker for `ipython` will become `implementation_name != "pypy"`.
Further, we have to merge the constraints of the requirements Further, we have to merge the constraints of the requirements
without markers into the constraints of the requirements with markers. without markers into the constraints of the requirements with markers.
for instance, if we have the following dependencies: for instance, if we have the following dependencies:
- foo (>= 1.2) foo (>= 1.2)
- foo (!= 1.2.1) ; python == 3.10 foo (!= 1.2.1) ; python == 3.10
the constraint for the second entry will become (!= 1.2.1, >= 1.2). the constraint for the second entry will become (!= 1.2.1, >= 1.2).
""" """
...@@ -1052,10 +1052,10 @@ class Provider: ...@@ -1052,10 +1052,10 @@ class Provider:
# and the inverted marker is not empty, # and the inverted marker is not empty,
# a dependency with the inverted union of all markers is required # a dependency with the inverted union of all markers is required
# in order to not miss other dependencies later, for instance: # in order to not miss other dependencies later, for instance:
# - foo (1.0) ; python == 3.7 # foo (1.0) ; python == 3.7
# - foo (2.0) ; python == 3.8 # foo (2.0) ; python == 3.8
# - bar (2.0) ; python == 3.8 # bar (2.0) ; python == 3.8
# - bar (3.0) ; python == 3.9 # bar (3.0) ; python == 3.9
# #
# the last dependency would be missed without this, # the last dependency would be missed without this,
# because the intersection with both foo dependencies is empty. # because the intersection with both foo dependencies is empty.
......
...@@ -75,12 +75,12 @@ class Solver: ...@@ -75,12 +75,12 @@ class Solver:
if len(self._overrides) > 1: if len(self._overrides) > 1:
self._provider.debug( self._provider.debug(
# ignore the warning as provider does not do interpolation # ignore the warning as provider does not do interpolation
f"Complete version solving took {end - start:.3f}" # noqa: PIE803 f"Complete version solving took {end - start:.3f}"
f" seconds with {len(self._overrides)} overrides" f" seconds with {len(self._overrides)} overrides"
) )
self._provider.debug( self._provider.debug(
# ignore the warning as provider does not do interpolation # ignore the warning as provider does not do interpolation
"Resolved with overrides:" # noqa: PIE803 "Resolved with overrides:"
f" {', '.join(f'({b})' for b in self._overrides)}" f" {', '.join(f'({b})' for b in self._overrides)}"
) )
...@@ -126,7 +126,7 @@ class Solver: ...@@ -126,7 +126,7 @@ class Solver:
for override in overrides: for override in overrides:
self._provider.debug( self._provider.debug(
# ignore the warning as provider does not do interpolation # ignore the warning as provider does not do interpolation
"<comment>Retrying dependency resolution " # noqa: PIE803 "<comment>Retrying dependency resolution "
f"with the following overrides ({override}).</comment>" f"with the following overrides ({override}).</comment>"
) )
self._provider.set_overrides(override) self._provider.set_overrides(override)
......
...@@ -246,5 +246,5 @@ class PyPiRepository(HTTPRepository): ...@@ -246,5 +246,5 @@ class PyPiRepository(HTTPRepository):
@staticmethod @staticmethod
def _get_yanked(json_data: dict[str, Any]) -> str | bool: def _get_yanked(json_data: dict[str, Any]) -> str | bool:
if json_data.get("yanked", False): if json_data.get("yanked", False):
return json_data.get("yanked_reason") or True # noqa: SIM222 return json_data.get("yanked_reason") or True
return False return False
...@@ -130,10 +130,7 @@ class RepositoryPool(AbstractRepository): ...@@ -130,10 +130,7 @@ class RepositoryPool(AbstractRepository):
DeprecationWarning, DeprecationWarning,
stacklevel=2, stacklevel=2,
) )
if default: priority = Priority.DEFAULT if default else Priority.SECONDARY
priority = Priority.DEFAULT
else:
priority = Priority.SECONDARY
if priority is Priority.DEFAULT and self.has_default(): if priority is Priority.DEFAULT and self.has_default():
raise ValueError("Only one repository can be the default.") raise ValueError("Only one repository can be the default.")
......
...@@ -1944,7 +1944,7 @@ class NullEnv(SystemEnv): ...@@ -1944,7 +1944,7 @@ class NullEnv(SystemEnv):
return "" return ""
def execute(self, bin: str, *args: str, **kwargs: Any) -> int: def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
self.executed.append([bin] + list(args)) self.executed.append([bin, *list(args)])
if self._execute: if self._execute:
return super().execute(bin, *args, **kwargs) return super().execute(bin, *args, **kwargs)
......
...@@ -47,7 +47,8 @@ class SystemGit: ...@@ -47,7 +47,8 @@ class SystemGit:
(folder / ".git").as_posix(), (folder / ".git").as_posix(),
"--work-tree", "--work-tree",
folder.as_posix(), folder.as_posix(),
) + args *args,
)
git_command = find_git_command() git_command = find_git_command()
env = os.environ.copy() env = os.environ.copy()
......
...@@ -12,7 +12,7 @@ from poetry.factory import Factory ...@@ -12,7 +12,7 @@ from poetry.factory import Factory
@pytest.fixture @pytest.fixture
def example_system_pyproject(): def example_system_pyproject() -> str:
package = ProjectPackage("poetry-instance", __version__) package = ProjectPackage("poetry-instance", __version__)
plugin = Package("poetry-plugin", "1.2.3") plugin = Package("poetry-plugin", "1.2.3")
...@@ -27,7 +27,7 @@ def example_system_pyproject(): ...@@ -27,7 +27,7 @@ def example_system_pyproject():
def test_generate_system_pyproject_trailing_newline( def test_generate_system_pyproject_trailing_newline(
existing_newlines: int, existing_newlines: int,
example_system_pyproject: str, example_system_pyproject: str,
): ) -> None:
cmd = SelfCommand() cmd = SelfCommand()
cmd.system_pyproject.write_text(example_system_pyproject + "\n" * existing_newlines) cmd.system_pyproject.write_text(example_system_pyproject + "\n" * existing_newlines)
cmd.generate_system_pyproject() cmd.generate_system_pyproject()
...@@ -38,7 +38,7 @@ def test_generate_system_pyproject_trailing_newline( ...@@ -38,7 +38,7 @@ def test_generate_system_pyproject_trailing_newline(
def test_generate_system_pyproject_carriage_returns( def test_generate_system_pyproject_carriage_returns(
example_system_pyproject: str, example_system_pyproject: str,
): ) -> None:
cmd = SelfCommand() cmd = SelfCommand()
cmd.system_pyproject.write_text(example_system_pyproject + "\n") cmd.system_pyproject.write_text(example_system_pyproject + "\n")
cmd.generate_system_pyproject() cmd.generate_system_pyproject()
......
...@@ -1049,10 +1049,7 @@ def test_package_include( ...@@ -1049,10 +1049,7 @@ def test_package_include(
), ),
) )
if include is None: packages = "" if include is None else f'packages = [{{include = "{include}"}}]\n'
packages = ""
else:
packages = f'packages = [{{include = "{include}"}}]\n'
expected = ( expected = (
f"[tool.poetry]\n" f"[tool.poetry]\n"
......
...@@ -188,7 +188,7 @@ url = "https://example.org/url-package-1.0-cp39-win_amd64.whl" ...@@ -188,7 +188,7 @@ url = "https://example.org/url-package-1.0-cp39-win_amd64.whl"
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -221,7 +221,7 @@ redis = ["redis (>=2.10.5)"] ...@@ -221,7 +221,7 @@ redis = ["redis (>=2.10.5)"]
lock-version = "2.0" lock-version = "2.0"
python-versions = "~2.7 || ^3.4" python-versions = "~2.7 || ^3.4"
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77" content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
""" # noqa: E800 """
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
f.write(content) f.write(content)
...@@ -282,7 +282,7 @@ files = [] ...@@ -282,7 +282,7 @@ files = []
python-versions = "*" python-versions = "*"
lock-version = "2.0" lock-version = "2.0"
content-hash = "123456789" content-hash = "123456789"
""" # noqa: E800 """
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
f.write(content) f.write(content)
...@@ -346,7 +346,7 @@ files = [] ...@@ -346,7 +346,7 @@ files = []
python-versions = "*" python-versions = "*"
lock-version = "2.0" lock-version = "2.0"
content-hash = "123456789" content-hash = "123456789"
""" # noqa: E800 """
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
f.write(content) f.write(content)
...@@ -537,7 +537,7 @@ files = [] ...@@ -537,7 +537,7 @@ files = []
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -579,7 +579,7 @@ foo = ["B (>=1.0.0)"] ...@@ -579,7 +579,7 @@ foo = ["B (>=1.0.0)"]
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with locker.lock.open(encoding="utf-8") as f: with locker.lock.open(encoding="utf-8") as f:
content = f.read() content = f.read()
...@@ -611,7 +611,7 @@ foo = ["bar"] ...@@ -611,7 +611,7 @@ foo = ["bar"]
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with locker.lock.open("w", encoding="utf-8") as f: with locker.lock.open("w", encoding="utf-8") as f:
f.write(content) f.write(content)
...@@ -658,7 +658,7 @@ reference = "legacy" ...@@ -658,7 +658,7 @@ reference = "legacy"
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -703,7 +703,7 @@ def test_locker_should_raise_an_error_if_lock_version_is_newer_and_not_allowed( ...@@ -703,7 +703,7 @@ def test_locker_should_raise_an_error_if_lock_version_is_newer_and_not_allowed(
lock-version = "3.0" lock-version = "3.0"
python-versions = "~2.7 || ^3.4" python-versions = "~2.7 || ^3.4"
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77" content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
""" # noqa: E800 """
caplog.set_level(logging.WARNING, logger="poetry.packages.locker") caplog.set_level(logging.WARNING, logger="poetry.packages.locker")
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
...@@ -740,7 +740,7 @@ C = ["first", "second", "third"] ...@@ -740,7 +740,7 @@ C = ["first", "second", "third"]
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with locker.lock.open(encoding="utf-8") as f: with locker.lock.open(encoding="utf-8") as f:
content = f.read() content = f.read()
...@@ -778,7 +778,7 @@ B = {{version = "^1.0.0", extras = ["a", "b", "c"], optional = true}} ...@@ -778,7 +778,7 @@ B = {{version = "^1.0.0", extras = ["a", "b", "c"], optional = true}}
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with locker.lock.open(encoding="utf-8") as f: with locker.lock.open(encoding="utf-8") as f:
content = f.read() content = f.read()
...@@ -891,7 +891,7 @@ I = {{git = "https://github.com/python-poetry/poetry.git", rev = "spam"}} ...@@ -891,7 +891,7 @@ I = {{git = "https://github.com/python-poetry/poetry.git", rev = "spam"}}
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -935,7 +935,7 @@ subdirectory = "subdir" ...@@ -935,7 +935,7 @@ subdirectory = "subdir"
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -979,7 +979,7 @@ C = ["first (==1.0.0)", "second (==1.0.0)", "third (==1.0.0)"] ...@@ -979,7 +979,7 @@ C = ["first (==1.0.0)", "second (==1.0.0)", "third (==1.0.0)"]
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -1010,7 +1010,7 @@ url = "lib/libA" ...@@ -1010,7 +1010,7 @@ url = "lib/libA"
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
f.write(content) f.write(content)
...@@ -1155,7 +1155,7 @@ resolved_reference = "123456" ...@@ -1155,7 +1155,7 @@ resolved_reference = "123456"
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
assert content == expected assert content == expected
...@@ -1173,7 +1173,7 @@ package = [] ...@@ -1173,7 +1173,7 @@ package = []
lock-version = "2.0" lock-version = "2.0"
python-versions = "*" python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800 """
with open(locker.lock, "w", encoding="utf-8") as f: with open(locker.lock, "w", encoding="utf-8") as f:
f.write(old_content) f.write(old_content)
......
...@@ -107,7 +107,7 @@ def test_load_successful_with_invalid_distribution( ...@@ -107,7 +107,7 @@ def test_load_successful_with_invalid_distribution(
invalid_dist_info.mkdir(parents=True) invalid_dist_info.mkdir(parents=True)
mocker.patch( mocker.patch(
"poetry.utils._compat.metadata.Distribution.discover", "poetry.utils._compat.metadata.Distribution.discover",
return_value=INSTALLED_RESULTS + [metadata.PathDistribution(invalid_dist_info)], return_value=[*INSTALLED_RESULTS, metadata.PathDistribution(invalid_dist_info)],
) )
repository_with_invalid_distribution = InstalledRepository.load(env) repository_with_invalid_distribution = InstalledRepository.load(env)
......
...@@ -7,7 +7,7 @@ from poetry.core.packages.package import Package ...@@ -7,7 +7,7 @@ from poetry.core.packages.package import Package
from poetry.repositories.lockfile_repository import LockfileRepository from poetry.repositories.lockfile_repository import LockfileRepository
def test_has_package(): def test_has_package() -> None:
repo = LockfileRepository() repo = LockfileRepository()
url_package = Package( url_package = Package(
...@@ -32,7 +32,7 @@ def test_has_package(): ...@@ -32,7 +32,7 @@ def test_has_package():
assert repo.has_package(deepcopy(url_package_2)) assert repo.has_package(deepcopy(url_package_2))
def test_remove_package(): def test_remove_package() -> None:
url_package = Package( url_package = Package(
"a", "1.0", source_type="url", source_url="https://example.org/a.whl" "a", "1.0", source_type="url", source_url="https://example.org/a.whl"
) )
......
...@@ -51,10 +51,7 @@ class MockRepository(PyPiRepository): ...@@ -51,10 +51,7 @@ class MockRepository(PyPiRepository):
) -> dict[str, Any] | None: ) -> dict[str, Any] | None:
parts = url.split("/")[1:] parts = url.split("/")[1:]
name = parts[0] name = parts[0]
if len(parts) == 3: version = parts[1] if len(parts) == 3 else None
version = parts[1]
else:
version = None
if not version: if not version:
fixture = self.JSON_FIXTURES / (name + ".json") fixture = self.JSON_FIXTURES / (name + ".json")
...@@ -340,7 +337,7 @@ def test_urls() -> None: ...@@ -340,7 +337,7 @@ def test_urls() -> None:
assert repository.authenticated_url == "https://pypi.org/simple/" assert repository.authenticated_url == "https://pypi.org/simple/"
def test_find_links_for_package_of_supported_types(): def test_find_links_for_package_of_supported_types() -> None:
repo = MockRepository() repo = MockRepository()
package = repo.find_packages(Factory.create_dependency("hbmqtt", "0.9.6")) package = repo.find_packages(Factory.create_dependency("hbmqtt", "0.9.6"))
...@@ -353,7 +350,7 @@ def test_find_links_for_package_of_supported_types(): ...@@ -353,7 +350,7 @@ def test_find_links_for_package_of_supported_types():
assert links[0].show_url == "hbmqtt-0.9.6.tar.gz" assert links[0].show_url == "hbmqtt-0.9.6.tar.gz"
def test_get_release_info_includes_only_supported_types(): def test_get_release_info_includes_only_supported_types() -> None:
repo = MockRepository() repo = MockRepository()
release_info = repo._get_release_info(name="hbmqtt", version="0.9.6") release_info = repo._get_release_info(name="hbmqtt", version="0.9.6")
......
...@@ -81,7 +81,7 @@ def test_repository_from_single_repo_pool_legacy( ...@@ -81,7 +81,7 @@ def test_repository_from_single_repo_pool_legacy(
assert pool.get_priority("foo") == expected_priority assert pool.get_priority("foo") == expected_priority
def test_repository_with_normal_default_secondary_and_explicit_repositories(): def test_repository_with_normal_default_secondary_and_explicit_repositories() -> None:
secondary = LegacyRepository("secondary", "https://secondary.com") secondary = LegacyRepository("secondary", "https://secondary.com")
default = LegacyRepository("default", "https://default.com") default = LegacyRepository("default", "https://default.com")
repo1 = LegacyRepository("foo", "https://foo.bar") repo1 = LegacyRepository("foo", "https://foo.bar")
......
...@@ -38,7 +38,7 @@ class MockSinglePageRepository(SinglePageRepository): ...@@ -38,7 +38,7 @@ class MockSinglePageRepository(SinglePageRepository):
raise RuntimeError("Tests are not configured for downloads") raise RuntimeError("Tests are not configured for downloads")
def test_single_page_repository_get_page(): def test_single_page_repository_get_page() -> None:
repo = MockSinglePageRepository("jax_releases") repo = MockSinglePageRepository("jax_releases")
page = repo.get_page("/ignored") page = repo.get_page("/ignored")
...@@ -52,7 +52,7 @@ def test_single_page_repository_get_page(): ...@@ -52,7 +52,7 @@ def test_single_page_repository_get_page():
assert link.path.startswith("/jax-releases/") assert link.path.startswith("/jax-releases/")
def test_single_page_repository_find_packages(): def test_single_page_repository_find_packages() -> None:
repo = MockSinglePageRepository("jax_releases") repo = MockSinglePageRepository("jax_releases")
dep = Dependency("jaxlib", "0.3.7") dep = Dependency("jaxlib", "0.3.7")
......
...@@ -12,7 +12,7 @@ if TYPE_CHECKING: ...@@ -12,7 +12,7 @@ if TYPE_CHECKING:
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
def test_env_site_simple(tmp_path: Path, mocker: MockerFixture): def test_env_site_simple(tmp_path: Path, mocker: MockerFixture) -> None:
# emulate permission error when creating directory # emulate permission error when creating directory
mocker.patch("pathlib.Path.mkdir", side_effect=OSError()) mocker.patch("pathlib.Path.mkdir", side_effect=OSError())
site_packages = SitePackages(Path("/non-existent"), fallbacks=[tmp_path]) site_packages = SitePackages(Path("/non-existent"), fallbacks=[tmp_path])
...@@ -30,7 +30,7 @@ def test_env_site_simple(tmp_path: Path, mocker: MockerFixture): ...@@ -30,7 +30,7 @@ def test_env_site_simple(tmp_path: Path, mocker: MockerFixture):
assert not (site_packages.path / "hello.txt").exists() assert not (site_packages.path / "hello.txt").exists()
def test_env_site_select_first(tmp_path: Path): def test_env_site_select_first(tmp_path: Path) -> None:
fallback = tmp_path / "fallback" fallback = tmp_path / "fallback"
fallback.mkdir(parents=True) fallback.mkdir(parents=True)
......
...@@ -42,7 +42,7 @@ zipfile36>=0.1.0.0,<0.2.0.0 ...@@ -42,7 +42,7 @@ zipfile36>=0.1.0.0,<0.2.0.0
[dev] [dev]
isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort
""" # noqa: E501 """
result = parse_requires(requires) result = parse_requires(requires)
# fmt: off # fmt: off
expected = [ expected = [
......
...@@ -34,7 +34,7 @@ from poetry.utils import patterns ...@@ -34,7 +34,7 @@ from poetry.utils import patterns
), ),
], ],
) )
def test_wheel_file_re(filename: str, expected: dict[str, str | None]): def test_wheel_file_re(filename: str, expected: dict[str, str | None]) -> None:
match = patterns.wheel_file_re.match(filename) match = patterns.wheel_file_re.match(filename)
groups = match.groupdict() groups = match.groupdict()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment