Skip to content

Commit

Permalink
chore: ban relative imports
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Nov 17, 2021
1 parent e92d680 commit 2397618
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 159 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
max-line-length = 88
ignore = E501, E203, W503, ANN101, ANN102
ban-relative-imports = True
mypy-init-return = True
per-file-ignores =
__init__.py:F401
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repos:
- flake8-annotations
- flake8-bugbear
- flake8-comprehensions
- flake8-tidy-imports

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
Expand Down
46 changes: 24 additions & 22 deletions poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@


if TYPE_CHECKING:
from .packages.project_package import ProjectPackage
from .packages.types import DependencyTypes
from .poetry import Poetry
from .spdx.license import License
from .version.markers import MarkerTypes
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.packages.types import DependencyTypes
from poetry.core.poetry import Poetry
from poetry.core.spdx.license import License
from poetry.core.version.markers import MarkerTypes

logger = logging.getLogger(__name__)

Expand All @@ -28,8 +28,8 @@ class Factory:
def create_poetry(
self, cwd: Optional[Path] = None, with_groups: bool = True
) -> "Poetry":
from .poetry import Poetry
from .pyproject.toml import PyProjectTOML
from poetry.core.poetry import Poetry
from poetry.core.pyproject.toml import PyProjectTOML

poetry_file = self.locate(cwd)
local_config = PyProjectTOML(path=poetry_file).poetry_config
Expand All @@ -55,7 +55,7 @@ def create_poetry(

@classmethod
def get_package(cls, name: str, version: str) -> "ProjectPackage":
from .packages.project_package import ProjectPackage
from poetry.core.packages.project_package import ProjectPackage

return ProjectPackage(name, version, version)

Expand All @@ -67,9 +67,9 @@ def configure_package(
root: Path,
with_groups: bool = True,
) -> "ProjectPackage":
from .packages.dependency import Dependency
from .packages.dependency_group import DependencyGroup
from .spdx.helpers import license_by_id
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.dependency_group import DependencyGroup
from poetry.core.spdx.helpers import license_by_id

package.root_dir = root

Expand Down Expand Up @@ -230,16 +230,18 @@ def create_dependency(
groups: Optional[List[str]] = None,
root_dir: Optional[Path] = None,
) -> "DependencyTypes":
from .packages.constraints import parse_constraint as parse_generic_constraint
from .packages.dependency import Dependency
from .packages.directory_dependency import DirectoryDependency
from .packages.file_dependency import FileDependency
from .packages.url_dependency import URLDependency
from .packages.utils.utils import create_nested_marker
from .packages.vcs_dependency import VCSDependency
from .semver.helpers import parse_constraint
from .version.markers import AnyMarker
from .version.markers import parse_marker
from poetry.core.packages.constraints import (
parse_constraint as parse_generic_constraint,
)
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.directory_dependency import DirectoryDependency
from poetry.core.packages.file_dependency import FileDependency
from poetry.core.packages.url_dependency import URLDependency
from poetry.core.packages.utils.utils import create_nested_marker
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.semver.helpers import parse_constraint
from poetry.core.version.markers import AnyMarker
from poetry.core.version.markers import parse_marker

if groups is None:
groups = ["default"]
Expand Down Expand Up @@ -374,7 +376,7 @@ def validate(cls, config: dict, strict: bool = False) -> Dict[str, List[str]]:
"""
Checks the validity of a configuration
"""
from .json import validate_object
from poetry.core.json import validate_object

result: Dict[str, List[str]] = {"errors": [], "warnings": []}
# Schema validation errors
Expand Down
5 changes: 2 additions & 3 deletions poetry/core/masonry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from typing import Optional

from poetry.core.factory import Factory

from .builders.sdist import SdistBuilder
from .builders.wheel import WheelBuilder
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.builders.wheel import WheelBuilder


log = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions poetry/core/masonry/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class Builder:
def __init__(self, poetry: "Poetry") -> None:
from .builders.sdist import SdistBuilder
from .builders.wheel import WheelBuilder
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.builders.wheel import WheelBuilder

self._poetry = poetry

Expand Down
4 changes: 2 additions & 2 deletions poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from typing import Set
from typing import Tuple

from .builder import Builder
from .builder import BuildIncludeFile
from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.builder import BuildIncludeFile


if TYPE_CHECKING:
Expand Down
13 changes: 6 additions & 7 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
from packaging.tags import sys_tags

from poetry.core import __version__
from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.utils.helpers import escape_name
from poetry.core.masonry.utils.helpers import escape_version
from poetry.core.masonry.utils.helpers import normalize_file_permissions
from poetry.core.masonry.utils.package_include import PackageInclude
from poetry.core.semver.helpers import parse_constraint

from ..utils.helpers import escape_name
from ..utils.helpers import escape_version
from ..utils.helpers import normalize_file_permissions
from ..utils.package_include import PackageInclude
from .builder import Builder
from .sdist import SdistBuilder


if TYPE_CHECKING:
from poetry.core.poetry import Poetry # noqa
Expand Down
5 changes: 2 additions & 3 deletions poetry/core/masonry/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ def __init__(
packages: Optional[List[Dict[str, Any]]] = None,
includes: Optional[List[Dict[str, Any]]] = None,
) -> None:
from poetry.core.masonry.utils.include import Include
from poetry.core.masonry.utils.package_include import PackageInclude
from poetry.core.utils.helpers import module_name

from .include import Include
from .package_include import PackageInclude

self._name = module_name(name)
self._in_src = False
self._is_package = False
Expand Down
2 changes: 1 addition & 1 deletion poetry/core/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List
from typing import Optional

from .include import Include
from poetry.core.masonry.utils.include import Include


class PackageInclude(Include):
Expand Down
12 changes: 6 additions & 6 deletions poetry/core/packages/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import Union

from .any_constraint import AnyConstraint
from .base_constraint import BaseConstraint
from .constraint import Constraint
from .empty_constraint import EmptyConstraint
from .multi_constraint import MultiConstraint
from .union_constraint import UnionConstraint
from poetry.core.packages.constraints.any_constraint import AnyConstraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint
from poetry.core.packages.constraints.constraint import Constraint
from poetry.core.packages.constraints.empty_constraint import EmptyConstraint
from poetry.core.packages.constraints.multi_constraint import MultiConstraint
from poetry.core.packages.constraints.union_constraint import UnionConstraint


BASIC_CONSTRAINT = re.compile(r"^(!?==?)?\s*([^\s]+?)\s*$")
Expand Down
6 changes: 3 additions & 3 deletions poetry/core/packages/constraints/any_constraint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import TYPE_CHECKING

from .base_constraint import BaseConstraint
from .empty_constraint import EmptyConstraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint
from poetry.core.packages.constraints.empty_constraint import EmptyConstraint


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class AnyConstraint(BaseConstraint):
Expand Down
2 changes: 1 addition & 1 deletion poetry/core/packages/constraints/base_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class BaseConstraint:
Expand Down
12 changes: 7 additions & 5 deletions poetry/core/packages/constraints/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from typing import Any
from typing import Union

from .base_constraint import BaseConstraint
from .empty_constraint import EmptyConstraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint
from poetry.core.packages.constraints.empty_constraint import EmptyConstraint


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class Constraint(BaseConstraint):
Expand Down Expand Up @@ -83,7 +83,7 @@ def difference(
return self

def intersect(self, other: "ConstraintTypes") -> "ConstraintTypes":
from .multi_constraint import MultiConstraint
from poetry.core.packages.constraints.multi_constraint import MultiConstraint

if isinstance(other, Constraint):
if other == self:
Expand All @@ -104,7 +104,9 @@ def intersect(self, other: "ConstraintTypes") -> "ConstraintTypes":

def union(self, other: "ConstraintTypes") -> "ConstraintTypes":
if isinstance(other, Constraint):
from .union_constraint import UnionConstraint
from poetry.core.packages.constraints.union_constraint import (
UnionConstraint,
)

return UnionConstraint(self, other)

Expand Down
4 changes: 2 additions & 2 deletions poetry/core/packages/constraints/empty_constraint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import TYPE_CHECKING

from .base_constraint import BaseConstraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class EmptyConstraint(BaseConstraint):
Expand Down
6 changes: 3 additions & 3 deletions poetry/core/packages/constraints/multi_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import Any
from typing import Tuple

from .base_constraint import BaseConstraint
from .constraint import Constraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint
from poetry.core.packages.constraints.constraint import Constraint


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class MultiConstraint(BaseConstraint):
Expand Down
10 changes: 5 additions & 5 deletions poetry/core/packages/constraints/union_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from typing import Tuple
from typing import Union

from .base_constraint import BaseConstraint
from .constraint import Constraint
from .empty_constraint import EmptyConstraint
from .multi_constraint import MultiConstraint
from poetry.core.packages.constraints.base_constraint import BaseConstraint
from poetry.core.packages.constraints.constraint import Constraint
from poetry.core.packages.constraints.empty_constraint import EmptyConstraint
from poetry.core.packages.constraints.multi_constraint import MultiConstraint


if TYPE_CHECKING:
from . import ConstraintTypes # noqa
from poetry.core.packages.constraints import ConstraintTypes # noqa


class UnionConstraint(BaseConstraint):
Expand Down
35 changes: 16 additions & 19 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ def marker(self) -> "BaseMarker":

@marker.setter
def marker(self, marker: Union[str, "BaseMarker"]) -> None:
from poetry.core.packages.utils.utils import convert_markers
from poetry.core.semver.helpers import parse_constraint
from poetry.core.version.markers import BaseMarker
from poetry.core.version.markers import parse_marker

from .utils.utils import convert_markers

if not isinstance(marker, BaseMarker):
marker = parse_marker(marker)

Expand Down Expand Up @@ -301,7 +300,7 @@ def accepts(self, package: "Package") -> bool:
)

def to_pep_508(self, with_extras: bool = True) -> str:
from .utils.utils import convert_markers
from poetry.core.packages.utils.utils import convert_markers

requirement = self.base_pep_508_name

Expand Down Expand Up @@ -348,13 +347,12 @@ def to_pep_508(self, with_extras: bool = True) -> str:
def _create_nested_marker(
self, name: str, constraint: Union["BaseConstraint", "VersionTypes"]
) -> str:
from poetry.core.packages.constraints.constraint import Constraint
from poetry.core.packages.constraints.multi_constraint import MultiConstraint
from poetry.core.packages.constraints.union_constraint import UnionConstraint
from poetry.core.semver.version import Version
from poetry.core.semver.version_union import VersionUnion

from .constraints.constraint import Constraint
from .constraints.multi_constraint import MultiConstraint
from .constraints.union_constraint import UnionConstraint

if isinstance(constraint, (MultiConstraint, UnionConstraint)):
parts = []
for c in constraint.constraints:
Expand Down Expand Up @@ -482,20 +480,19 @@ def create_from_pep_508(
path is specified, this is used as the base directory if the identified dependency is
of file or directory type.
"""
from poetry.core.packages.url_dependency import URLDependency
from poetry.core.packages.utils.link import Link
from poetry.core.packages.utils.utils import is_archive_file
from poetry.core.packages.utils.utils import is_installable_dir
from poetry.core.packages.utils.utils import is_url
from poetry.core.packages.utils.utils import path_to_url
from poetry.core.packages.utils.utils import strip_extras
from poetry.core.packages.utils.utils import url_to_path
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.utils.patterns import wheel_file_re
from poetry.core.vcs.git import ParsedUrl
from poetry.core.version.requirements import Requirement

from .url_dependency import URLDependency
from .utils.link import Link
from .utils.utils import is_archive_file
from .utils.utils import is_installable_dir
from .utils.utils import is_url
from .utils.utils import path_to_url
from .utils.utils import strip_extras
from .utils.utils import url_to_path
from .vcs_dependency import VCSDependency

# Removing comments
parts = name.split(" #", 1)
name = parts[0].strip()
Expand Down Expand Up @@ -638,8 +635,8 @@ def _make_file_or_dir_dep(
Helper function to create a file or directoru dependency with the given arguments. If
path is not a file or directory that exists, `None` is returned.
"""
from .directory_dependency import DirectoryDependency
from .file_dependency import FileDependency
from poetry.core.packages.directory_dependency import DirectoryDependency
from poetry.core.packages.file_dependency import FileDependency

_path = path
if not path.is_absolute() and base:
Expand Down
Loading

0 comments on commit 2397618

Please sign in to comment.