Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make .pre-commit-config.yaml similar to poetry repo #271

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 61 additions & 52 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,81 @@
exclude: |
(?x)(
^tests/.*/fixtures/.*
| ^src/poetry/core/_vendor
)

repos:
- repo: https://github.com/psf/black
rev: 21.9b0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: black
exclude: ^src/poetry/core/_vendor
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: check-merge-conflict
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: pretty-format-json
args:
- --autofix
- --no-ensure-ascii
- --no-sort-keys
- id: check-ast
- id: debug-statements
- id: check-docstring-first

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: flake8
additional_dependencies:
- flake8-annotations
- flake8-bugbear
- flake8-comprehensions
- flake8-eradicate
- flake8-simplify
- flake8-tidy-imports
- flake8-use-fstring
- id: python-check-mock-methods
- id: python-use-type-annotations
- id: python-check-blanket-type-ignore
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: mypy
pass_filenames: false
- id: yesqa
additional_dependencies: &flake8_deps
- flake8-annotations==2.7.0
- flake8-bugbear==22.1.11
- flake8-comprehensions==3.8.0
- flake8-eradicate==1.2.0
- flake8-simplify==0.15.1
- flake8-tidy-imports==4.6.0
- flake8-use-fstring==1.3

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args:
- --py36-plus

- repo: https://github.com/pycqa/isort
rev: 5.9.3
rev: 5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
exclude: |
(?x)(
^.*/?setup\.py$
| ^src/poetry/core/_vendor
| tests/.*\.pyi$
)

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: pyupgrade
args:
- --py36-plus
exclude: ^src/poetry/core/_vendor
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: trailing-whitespace
exclude: |
(?x)(
^tests/.*/fixtures/.*
| ^src/poetry/core/_vendor
)
- id: end-of-file-fixer
exclude: |
(?x)(
^tests/.*/fixtures/.*
| ^src/poetry/core/_vendor
)
- id: debug-statements
exclude: ^src/poetry/core/_vendor

- id: check-json
exclude: ^src/poetry/core/_vendor
- id: flake8
additional_dependencies: *flake8_deps

- id: pretty-format-json
exclude: ^src/poetry/core/_vendor
args:
- --no-sort-keys
- --autofix
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
hooks:
- id: mypy
pass_filenames: false
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ isort = {version = "^5.9.3", python = "^3.6.1"}

[tool.black]
line-length = 88
experimental_string_processing = true
include = '\.pyi?$'
exclude = '''
/(
Expand Down
6 changes: 4 additions & 2 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,17 @@ def validate(
for extra in extras:
if extra not in config["extras"]:
result["errors"].append(
f'Script "{name}" requires extra "{extra}" which is not defined.'
f'Script "{name}" requires extra "{extra}" which is not'
" defined."
)

# Checking types of all readme files (must match)
if "readme" in config and not isinstance(config["readme"], str):
readme_types = {readme_content_type(r) for r in config["readme"]}
if len(readme_types) > 1:
result["errors"].append(
f"Declared README files must be of same type: found {', '.join(sorted(readme_types))}"
"Declared README files must be of same type: found"
f" {', '.join(sorted(readme_types))}"
)

return result
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/masonry/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


if TYPE_CHECKING:
from poetry.core.poetry import Poetry # noqa
from poetry.core.poetry import Poetry


class Builder:
Expand Down
8 changes: 5 additions & 3 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


if TYPE_CHECKING:
from poetry.core.poetry import Poetry # noqa
from poetry.core.poetry import Poetry


AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"()]+) <(?P<email>.+?)>$")
Expand Down Expand Up @@ -290,7 +290,8 @@ def convert_entry_points(self) -> Dict[str, List[str]]:

if "callable" in specification:
warnings.warn(
f"Use of callable in script specification ({name}) is deprecated. Use reference instead.",
f"Use of callable in script specification ({name}) is deprecated."
" Use reference instead.",
DeprecationWarning,
)
specification = {
Expand Down Expand Up @@ -328,7 +329,8 @@ def convert_script_files(self) -> List[Path]:

if Path(source).is_absolute():
raise RuntimeError(
f"{source} in {name} is an absolute path. Expected relative path."
f"{source} in {name} is an absolute path. Expected relative"
" path."
)

abs_path = Path.joinpath(self._path, source)
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


if TYPE_CHECKING:
from poetry.core.poetry import Poetry # noqa
from poetry.core.poetry import Poetry

wheel_file_template = """\
Wheel-Version: 1.0
Expand Down
18 changes: 10 additions & 8 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
if TYPE_CHECKING:
from poetry.core.packages.dependency_group import DependencyGroup
from poetry.core.packages.types import DependencyTypes
from poetry.core.semver.helpers import VersionTypes # noqa
from poetry.core.semver.version import Version # noqa
from poetry.core.spdx.license import License # noqa
from poetry.core.version.markers import BaseMarker # noqa
from poetry.core.semver.helpers import VersionTypes
from poetry.core.semver.version import Version
from poetry.core.spdx.license import License
from poetry.core.version.markers import BaseMarker

AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"()&]+)(?: <(?P<email>.+?)>)?$")

Expand Down Expand Up @@ -268,7 +268,7 @@ def license(self) -> Optional["License"]:
@license.setter
def license(self, value: Optional[Union[str, "License"]]) -> None:
from poetry.core.spdx.helpers import license_by_id
from poetry.core.spdx.license import License # noqa
from poetry.core.spdx.license import License

if value is None or isinstance(value, License):
self._license = value
Expand All @@ -277,7 +277,7 @@ def license(self, value: Optional[Union[str, "License"]]) -> None:

@property
def all_classifiers(self) -> List[str]:
from poetry.core.semver.version import Version # noqa
from poetry.core.semver.version import Version

classifiers = copy.copy(self.classifiers)

Expand Down Expand Up @@ -347,7 +347,8 @@ def readme(self) -> Path:
import warnings

warnings.warn(
"`readme` is deprecated: you are getting only the first readme file. Please use the plural form `readmes`.",
"`readme` is deprecated: you are getting only the first readme file. Please"
" use the plural form `readmes`.",
DeprecationWarning,
)
return next(iter(self.readmes), None)
Expand All @@ -357,7 +358,8 @@ def readme(self, path: Path) -> None:
import warnings

warnings.warn(
"`readme` is deprecated. Please assign a tuple to the plural form `readmes`.",
"`readme` is deprecated. Please assign a tuple to the plural form"
" `readmes`.",
DeprecationWarning,
)
self.readmes = (path,)
Expand Down
19 changes: 9 additions & 10 deletions src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@


if TYPE_CHECKING:
from poetry.core.packages.constraints import BaseConstraint # noqa
from poetry.core.semver.helpers import VersionTypes # noqa
from poetry.core.semver.version import Version # noqa
from poetry.core.semver.version_constraint import VersionConstraint # noqa
from poetry.core.semver.version_range import VersionRange # noqa
from poetry.core.semver.version_union import VersionUnion # noqa
from poetry.core.version.markers import BaseMarker # noqa
from poetry.core.packages.constraints import BaseConstraint
from poetry.core.semver.helpers import VersionTypes
from poetry.core.semver.version import Version
from poetry.core.semver.version_constraint import VersionConstraint
from poetry.core.semver.version_union import VersionUnion
from poetry.core.version.markers import BaseMarker


BZ2_EXTENSIONS = (".tar.bz2", ".tbz")
Expand All @@ -32,15 +31,15 @@
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS

try:
import bz2 # noqa
import bz2 # noqa: F401

SUPPORTED_EXTENSIONS += BZ2_EXTENSIONS
except ImportError:
pass

try:
# Only for Python 3.3+
import lzma # noqa
import lzma # noqa: F401
Comment on lines 40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is python <3.3 compat still required here?

if we need it, we should use

if sys.version_info >= (3, 3):
    import lzma
    ....

or similar

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to avoid logic change to the code within this PR, because its only about formatting. I think this is better handled in #263 for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @tony

Copy link
Contributor

@tony tony Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think try/catch still makes sense here. It's true was originally an underlying version constraint.

lzma is optionally built in. You can compile CPython without lzma

Could not figure out the flags, Not having the library seems to do it:

❯ sudo apt remove liblzma-dev
❯ make distclean
❯ ./configure
❯ make -j8
❯ ./python -V
Python 3.11.0a4+

❯ ./python -c 'import lzma'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/projects/c/cpython/Lib/lzma.py", line 27, in <module>
    from _lzma import *
    ^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_lzma'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense


SUPPORTED_EXTENSIONS += XZ_EXTENSIONS
except ImportError:
Expand Down Expand Up @@ -300,7 +299,7 @@ def get_python_constraint_from_marker(
from poetry.core.semver.empty_constraint import EmptyConstraint
from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version import Version
from poetry.core.semver.version_range import VersionRange # noqa
from poetry.core.semver.version_range import VersionRange

python_marker = marker.only("python_version", "python_full_version")
if python_marker.is_any():
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/semver/empty_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


if TYPE_CHECKING:
from poetry.core.semver import VersionTypes # noqa
from poetry.core.semver.version import Version # noqa
from poetry.core.semver import VersionTypes
from poetry.core.semver.version import Version


class EmptyConstraint(VersionConstraint):
Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/semver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


if TYPE_CHECKING:
from poetry.core.semver.empty_constraint import EmptyConstraint # noqa
from poetry.core.semver.version import Version # noqa
from poetry.core.semver.version_range import VersionRange # noqa
from poetry.core.semver.version_union import VersionUnion # noqa
from poetry.core.semver.empty_constraint import EmptyConstraint
from poetry.core.semver.version import Version
from poetry.core.semver.version_range import VersionRange
from poetry.core.semver.version_union import VersionUnion


VersionTypes = Union["Version", "VersionRange", "VersionUnion", "EmptyConstraint"]
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/core/spdx/data/licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -1040,17 +1040,17 @@
false
],
"LiLiQ-P-1.1": [
"Licence Libre du Qu\u00e9bec \u2013 Permissive version 1.1",
"Licence Libre du Québec – Permissive version 1.1",
true,
false
],
"LiLiQ-R-1.1": [
"Licence Libre du Qu\u00e9bec \u2013 R\u00e9ciprocit\u00e9 version 1.1",
"Licence Libre du Québec – Réciprocité version 1.1",
true,
false
],
"LiLiQ-Rplus-1.1": [
"Licence Libre du Qu\u00e9bec \u2013 R\u00e9ciprocit\u00e9 forte version 1.1",
"Licence Libre du Québec – Réciprocité forte version 1.1",
true,
false
],
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/toml/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


if TYPE_CHECKING:
from tomlkit.toml_document import TOMLDocument # noqa
from tomlkit.toml_document import TOMLDocument


class TOMLFile(BaseTOMLFile):
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/utils/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError # noqa
FileNotFoundError = IOError
Comment on lines 12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here - can we use if sys.version_info > ...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @tony

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #263 I pushed a change removing this



def list_to_shell_command(cmd: List[str]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/version/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


if TYPE_CHECKING:
from poetry.core.semver.version_constraint import VersionConstraint # noqa
from poetry.core.semver.version_constraint import VersionConstraint

PYTHON_VERSION = [
"2.7.*",
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@


if TYPE_CHECKING:
from lark import Tree # noqa
from lark import Tree

from poetry.core.semver.helpers import VersionTypes # noqa
from poetry.core.semver.helpers import VersionTypes

MarkerTypes = Union[
"AnyMarker", "EmptyMarker", "SingleMarker", "MultiMarker", "MarkerUnion"
Expand Down
Loading