Skip to content

Commit e81166e

Browse files
authored
Misc tidying (python-poetry#570)
1 parent 8180576 commit e81166e

20 files changed

+67
-60
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ repos:
1111
- id: trailing-whitespace
1212
exclude: "vendors/patches/jsonschema.patch"
1313
- id: end-of-file-fixer
14-
- id: debug-statements
1514
- id: check-merge-conflict
1615
- id: check-case-conflict
1716
- id: check-json

src/poetry/core/constraints/generic/empty_constraint.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
class EmptyConstraint(BaseConstraint):
77
pretty_string = None
88

9-
def matches(self, _: BaseConstraint) -> bool:
10-
return True
11-
129
def is_empty(self) -> bool:
1310
return True
1411

src/poetry/core/factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Any
88
from typing import Dict
99
from typing import List
10-
from typing import Mapping
1110
from typing import Union
1211
from warnings import warn
1312

@@ -18,6 +17,8 @@
1817

1918

2019
if TYPE_CHECKING:
20+
from collections.abc import Mapping
21+
2122
from poetry.core.packages.dependency import Dependency
2223
from poetry.core.packages.dependency_group import DependencyGroup
2324
from poetry.core.packages.project_package import ProjectPackage
@@ -260,7 +261,7 @@ def create_dependency(
260261
'the "allows-prereleases" property, which is deprecated. '
261262
'Use "allow-prereleases" instead.'
262263
)
263-
warn(message, DeprecationWarning)
264+
warn(message, DeprecationWarning, stacklevel=2)
264265
logger.warning(message)
265266

266267
allows_prereleases = constraint.get(

src/poetry/core/masonry/builders/builder.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ def find_excluded_files(self, fmt: str | None = None) -> set[str]:
106106

107107
# Checking VCS
108108
vcs = get_vcs(self._path)
109-
if not vcs:
110-
vcs_ignored_files = set()
111-
else:
112-
vcs_ignored_files = set(vcs.get_ignored_files())
109+
vcs_ignored_files = set(vcs.get_ignored_files()) if vcs else set()
113110

114111
explicitly_excluded = set()
115112
for excluded_glob in self._package.exclude:

src/poetry/core/masonry/builders/sdist.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
from posixpath import join as pjoin
1515
from pprint import pformat
1616
from typing import TYPE_CHECKING
17-
from typing import Iterable
18-
from typing import Iterator
1917

2018
from poetry.core.masonry.builders.builder import Builder
2119
from poetry.core.masonry.builders.builder import BuildIncludeFile
2220
from poetry.core.masonry.utils.helpers import distribution_name
2321

2422

2523
if TYPE_CHECKING:
24+
from collections.abc import Iterable
25+
from collections.abc import Iterator
2626
from tarfile import TarInfo
2727

2828
from poetry.core.masonry.utils.package_include import PackageInclude
@@ -280,13 +280,11 @@ def find_nearest_pkg(rel_path: str) -> tuple[str, str]:
280280
continue
281281

282282
is_subpkg = any(
283-
[filename.endswith(".py") for filename in filenames]
283+
filename.endswith(".py") for filename in filenames
284284
) and not all(
285-
[
286-
self.is_excluded(Path(path, filename).relative_to(self._path))
287-
for filename in filenames
288-
if filename.endswith(".py")
289-
]
285+
self.is_excluded(Path(path, filename).relative_to(self._path))
286+
for filename in filenames
287+
if filename.endswith(".py")
290288
)
291289
if is_subpkg:
292290
subpkg_paths.add(from_top_level)

src/poetry/core/masonry/builders/wheel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from io import StringIO
1616
from pathlib import Path
1717
from typing import TYPE_CHECKING
18-
from typing import Iterator
1918
from typing import TextIO
2019

2120
from packaging.tags import sys_tags
@@ -31,6 +30,8 @@
3130

3231

3332
if TYPE_CHECKING:
33+
from collections.abc import Iterator
34+
3435
from packaging.utils import NormalizedName
3536

3637
from poetry.core.poetry import Poetry
@@ -357,7 +358,7 @@ def _add_file(
357358
zinfo.external_attr |= 0x10 # MS-DOS directory flag
358359

359360
hashsum = hashlib.sha256()
360-
with open(full_path, "rb") as src:
361+
with full_path.open("rb") as src:
361362
while True:
362363
buf = src.read(1024 * 8)
363364
if not buf:

src/poetry/core/packages/dependency.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from contextlib import suppress
88
from pathlib import Path
99
from typing import TYPE_CHECKING
10-
from typing import Iterable
1110
from typing import TypeVar
1211

1312
from packaging.utils import canonicalize_name
@@ -23,6 +22,8 @@
2322

2423

2524
if TYPE_CHECKING:
25+
from collections.abc import Iterable
26+
2627
from packaging.utils import NormalizedName
2728

2829
from poetry.core.constraints.version import VersionConstraint
@@ -345,9 +346,9 @@ def create_from_pep_508(
345346
cls, name: str, relative_to: Path | None = None
346347
) -> Dependency:
347348
"""
348-
Resolve a PEP-508 requirement string to a `Dependency` instance. If a `relative_to`
349-
path is specified, this is used as the base directory if the identified dependency is
350-
of file or directory type.
349+
Resolve a PEP-508 requirement string to a `Dependency` instance. If a
350+
`relative_to` path is specified, this is used as the base directory if the
351+
identified dependency is of file or directory type.
351352
"""
352353
from poetry.core.packages.url_dependency import URLDependency
353354
from poetry.core.packages.utils.link import Link
@@ -459,10 +460,7 @@ def create_from_pep_508(
459460
dep._constraint = parse_constraint(version)
460461
else:
461462
constraint: VersionConstraint | str
462-
if req.pretty_constraint:
463-
constraint = req.constraint
464-
else:
465-
constraint = "*"
463+
constraint = req.constraint if req.pretty_constraint else "*"
466464
dep = Dependency(name, constraint, extras=req.extras)
467465

468466
if req.marker:
@@ -507,8 +505,8 @@ def _make_file_or_dir_dep(
507505
extras: list[str] | None = None,
508506
) -> FileDependency | DirectoryDependency | None:
509507
"""
510-
Helper function to create a file or directoru dependency with the given arguments. If
511-
path is not a file or directory that exists, `None` is returned.
508+
Helper function to create a file or directoru dependency with the given arguments.
509+
If path is not a file or directory that exists, `None` is returned.
512510
"""
513511
from poetry.core.packages.directory_dependency import DirectoryDependency
514512
from poetry.core.packages.file_dependency import FileDependency

src/poetry/core/packages/directory_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import functools
44

55
from typing import TYPE_CHECKING
6-
from typing import Iterable
76

87
from poetry.core.packages.path_dependency import PathDependency
98
from poetry.core.packages.utils.utils import is_python_project
109
from poetry.core.pyproject.toml import PyProjectTOML
1110

1211

1312
if TYPE_CHECKING:
13+
from collections.abc import Iterable
1414
from pathlib import Path
1515

1616

src/poetry/core/packages/file_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import warnings
66

77
from typing import TYPE_CHECKING
8-
from typing import Iterable
98

109
from poetry.core.packages.path_dependency import PathDependency
1110

1211

1312
if TYPE_CHECKING:
13+
from collections.abc import Iterable
1414
from pathlib import Path
1515

1616

src/poetry/core/packages/package.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
import warnings
66

77
from contextlib import contextmanager
8-
from pathlib import Path
98
from typing import TYPE_CHECKING
10-
from typing import Collection
11-
from typing import Iterable
12-
from typing import Iterator
139
from typing import TypeVar
1410

1511
from poetry.core.constraints.version import parse_constraint
@@ -22,6 +18,11 @@
2218

2319

2420
if TYPE_CHECKING:
21+
from collections.abc import Collection
22+
from collections.abc import Iterable
23+
from collections.abc import Iterator
24+
from pathlib import Path
25+
2526
from packaging.utils import NormalizedName
2627

2728
from poetry.core.constraints.version import Version

0 commit comments

Comments
 (0)