diff --git a/pyproject.toml b/pyproject.toml index 1204d0418..e75917379 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,7 +120,7 @@ ignore_missing_imports = true [tool.vendoring] destination = "src/poetry/core/_vendor/" requirements = "src/poetry/core/_vendor/vendor.txt" -namespace = "" +namespace = "poetry.core._vendor" protected-files = ["vendor.txt"] patches-dir = "vendors/patches" diff --git a/src/poetry/core/__init__.py b/src/poetry/core/__init__.py index 8a2867f0f..afc8c67a3 100644 --- a/src/poetry/core/__init__.py +++ b/src/poetry/core/__init__.py @@ -1,15 +1,6 @@ from __future__ import annotations -import sys - -from pathlib import Path - # this cannot presently be replaced with importlib.metadata.version as when building # itself, poetry-core is not available as an installed distribution. __version__ = "1.9.0" - -__vendor_site__ = (Path(__file__).parent / "_vendor").as_posix() - -if __vendor_site__ not in sys.path: - sys.path.insert(0, __vendor_site__) diff --git a/src/poetry/core/_vendor/fastjsonschema/__init__.py b/src/poetry/core/_vendor/fastjsonschema/__init__.py index b0b8849e9..9f9e785e1 100644 --- a/src/poetry/core/_vendor/fastjsonschema/__init__.py +++ b/src/poetry/core/_vendor/fastjsonschema/__init__.py @@ -78,7 +78,7 @@ .. code-block:: python - import fastjsonschema + from poetry.core._vendor import fastjsonschema point_schema = { "type": "object", @@ -132,7 +132,7 @@ def validate(definition, data, handlers={}, formats={}, use_default=True, use_fo .. code-block:: python - import fastjsonschema + from poetry.core._vendor import fastjsonschema fastjsonschema.validate({'type': 'string'}, 'hello') # same as: compile({'type': 'string'})('hello') @@ -151,7 +151,7 @@ def compile(definition, handlers={}, formats={}, use_default=True, use_formats=T .. code-block:: python - import fastjsonschema + from poetry.core._vendor import fastjsonschema validate = fastjsonschema.compile({'type': 'string'}) validate('hello') @@ -224,7 +224,7 @@ def compile_to_code(definition, handlers={}, formats={}, use_default=True, use_f .. code-block:: python - import fastjsonschema + from poetry.core._vendor import fastjsonschema code = fastjsonschema.compile_to_code({'type': 'string'}) with open('your_file.py', 'w') as f: diff --git a/src/poetry/core/_vendor/lark/ast_utils.py b/src/poetry/core/_vendor/lark/ast_utils.py index a5460f35d..587627fc4 100644 --- a/src/poetry/core/_vendor/lark/ast_utils.py +++ b/src/poetry/core/_vendor/lark/ast_utils.py @@ -6,7 +6,7 @@ import types from typing import Optional, Callable -from lark import Transformer, v_args +from poetry.core._vendor.lark import Transformer, v_args class Ast: """Abstract class diff --git a/src/poetry/core/_vendor/lark/load_grammar.py b/src/poetry/core/_vendor/lark/load_grammar.py index 362a845d2..e9b07e69e 100644 --- a/src/poetry/core/_vendor/lark/load_grammar.py +++ b/src/poetry/core/_vendor/lark/load_grammar.py @@ -861,7 +861,7 @@ def __call__(self, base_path: Union[None, str, PackageResource], grammar_path: s raise IOError('Cannot find grammar in given paths') from err -stdlib_loader = FromPackageLoader('lark', IMPORT_PATHS) +stdlib_loader = FromPackageLoader('poetry.core._vendor.lark', IMPORT_PATHS) diff --git a/src/poetry/core/_vendor/lark/parsers/lalr_interactive_parser.py b/src/poetry/core/_vendor/lark/parsers/lalr_interactive_parser.py index d5a2152f3..9dbb6569e 100644 --- a/src/poetry/core/_vendor/lark/parsers/lalr_interactive_parser.py +++ b/src/poetry/core/_vendor/lark/parsers/lalr_interactive_parser.py @@ -4,8 +4,8 @@ from copy import copy import warnings -from lark.exceptions import UnexpectedToken -from lark.lexer import Token, LexerThread +from poetry.core._vendor.lark.exceptions import UnexpectedToken +from poetry.core._vendor.lark.lexer import Token, LexerThread ###{standalone diff --git a/src/poetry/core/_vendor/lark/parsers/lalr_parser.py b/src/poetry/core/_vendor/lark/parsers/lalr_parser.py index 6ae2a04fd..65ce55dfa 100644 --- a/src/poetry/core/_vendor/lark/parsers/lalr_parser.py +++ b/src/poetry/core/_vendor/lark/parsers/lalr_parser.py @@ -9,7 +9,7 @@ from .lalr_analysis import LALR_Analyzer, IntParseTable, ParseTableBase from .lalr_interactive_parser import InteractiveParser -from lark.exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedToken +from poetry.core._vendor.lark.exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedToken from .lalr_parser_state import ParserState, ParseConf ###{standalone diff --git a/src/poetry/core/_vendor/lark/parsers/lalr_parser_state.py b/src/poetry/core/_vendor/lark/parsers/lalr_parser_state.py index 350569769..ae7566d5c 100644 --- a/src/poetry/core/_vendor/lark/parsers/lalr_parser_state.py +++ b/src/poetry/core/_vendor/lark/parsers/lalr_parser_state.py @@ -4,7 +4,7 @@ from ..common import ParserCallbacks from .lalr_analysis import Shift, ParseTableBase, StateT -from lark.exceptions import UnexpectedToken +from poetry.core._vendor.lark.exceptions import UnexpectedToken ###{standalone diff --git a/src/poetry/core/_vendor/lark/tools/__init__.py b/src/poetry/core/_vendor/lark/tools/__init__.py index c6995c690..954fdcf0f 100644 --- a/src/poetry/core/_vendor/lark/tools/__init__.py +++ b/src/poetry/core/_vendor/lark/tools/__init__.py @@ -5,7 +5,7 @@ from typing import Optional import warnings -from lark import Lark, logger +from poetry.core._vendor.lark import Lark, logger try: from interegular import logger as interegular_logger has_interegular = True diff --git a/src/poetry/core/_vendor/lark/tools/nearley.py b/src/poetry/core/_vendor/lark/tools/nearley.py index 1fc27d565..6c0b3fa82 100644 --- a/src/poetry/core/_vendor/lark/tools/nearley.py +++ b/src/poetry/core/_vendor/lark/tools/nearley.py @@ -6,7 +6,7 @@ import argparse -from lark import Lark, Transformer, v_args +from poetry.core._vendor.lark import Lark, Transformer, v_args nearley_grammar = r""" start: (ruledef|directive)+ diff --git a/src/poetry/core/_vendor/lark/tools/serialize.py b/src/poetry/core/_vendor/lark/tools/serialize.py index eb28824b7..c993a5f51 100644 --- a/src/poetry/core/_vendor/lark/tools/serialize.py +++ b/src/poetry/core/_vendor/lark/tools/serialize.py @@ -1,9 +1,9 @@ import sys import json -from lark.grammar import Rule -from lark.lexer import TerminalDef -from lark.tools import lalr_argparser, build_lalr +from poetry.core._vendor.lark.grammar import Rule +from poetry.core._vendor.lark.lexer import TerminalDef +from poetry.core._vendor.lark.tools import lalr_argparser, build_lalr import argparse diff --git a/src/poetry/core/_vendor/lark/tools/standalone.py b/src/poetry/core/_vendor/lark/tools/standalone.py index 9940ccbf5..a28b8a645 100644 --- a/src/poetry/core/_vendor/lark/tools/standalone.py +++ b/src/poetry/core/_vendor/lark/tools/standalone.py @@ -42,12 +42,12 @@ from functools import partial from argparse import ArgumentParser -import lark -from lark.tools import lalr_argparser, build_lalr, make_warnings_comments +from poetry.core._vendor import lark +from poetry.core._vendor.lark.tools import lalr_argparser, build_lalr, make_warnings_comments -from lark.grammar import Rule -from lark.lexer import TerminalDef +from poetry.core._vendor.lark.grammar import Rule +from poetry.core._vendor.lark.lexer import TerminalDef _dir = path.dirname(__file__) _larkdir = path.join(_dir, path.pardir) diff --git a/src/poetry/core/_vendor/lark/tree.py b/src/poetry/core/_vendor/lark/tree.py index 438837ebe..258a82a4c 100644 --- a/src/poetry/core/_vendor/lark/tree.py +++ b/src/poetry/core/_vendor/lark/tree.py @@ -100,7 +100,7 @@ def __rich__(self, parent:Optional['rich.tree.Tree']=None) -> 'rich.tree.Tree': Example: :: from rich import print - from lark import Tree + from poetry.core._vendor.lark import Tree tree = Tree('root', ['node1', 'node2']) print(tree) diff --git a/src/poetry/core/_vendor/lark/tree_templates.py b/src/poetry/core/_vendor/lark/tree_templates.py index 6ec7323f4..7f4ab6f02 100644 --- a/src/poetry/core/_vendor/lark/tree_templates.py +++ b/src/poetry/core/_vendor/lark/tree_templates.py @@ -6,8 +6,8 @@ from typing import Union, Optional, Mapping, Dict, Tuple, Iterator -from lark import Tree, Transformer -from lark.exceptions import MissingVariableError +from poetry.core._vendor.lark import Tree, Transformer +from poetry.core._vendor.lark.exceptions import MissingVariableError Branch = Union[Tree[str], str] TreeOrCode = Union[Tree[str], str] diff --git a/src/poetry/core/constraints/version/patterns.py b/src/poetry/core/constraints/version/patterns.py index d1187e55d..438215e76 100644 --- a/src/poetry/core/constraints/version/patterns.py +++ b/src/poetry/core/constraints/version/patterns.py @@ -2,7 +2,7 @@ import re -from packaging.version import VERSION_PATTERN +from poetry.core._vendor.packaging.version import VERSION_PATTERN COMPLETE_VERSION = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE) diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index 5e74991e3..bb526f251 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -9,14 +9,14 @@ from typing import List from typing import Union -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.utils.helpers import combine_unicode from poetry.core.utils.helpers import readme_content_type if TYPE_CHECKING: - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName from poetry.core.packages.dependency import Dependency from poetry.core.packages.dependency_group import DependencyGroup diff --git a/src/poetry/core/json/__init__.py b/src/poetry/core/json/__init__.py index 035dd9066..6bb49e01d 100644 --- a/src/poetry/core/json/__init__.py +++ b/src/poetry/core/json/__init__.py @@ -7,9 +7,8 @@ from typing import TYPE_CHECKING from typing import Any -import fastjsonschema - -from fastjsonschema.exceptions import JsonSchemaException +from poetry.core._vendor import fastjsonschema +from poetry.core._vendor.fastjsonschema.exceptions import JsonSchemaException SCHEMA_DIR = Path(__file__).parent / "schemas" diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 21cd20387..3febe7dda 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -19,7 +19,7 @@ from typing import TYPE_CHECKING from typing import TextIO -import packaging.tags +import poetry.core._vendor.packaging.tags from poetry.core import __version__ from poetry.core.constraints.version import parse_constraint @@ -34,7 +34,7 @@ if TYPE_CHECKING: from collections.abc import Iterator - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName from poetry.core.poetry import Poetry @@ -399,14 +399,14 @@ def _get_sys_tags(self) -> list[str]: from pathlib import Path spec = importlib.util.spec_from_file_location( - "packaging", Path(r"{packaging.__file__}") + "packaging", Path(r"{poetry.core._vendor.packaging.__file__}") ) packaging = importlib.util.module_from_spec(spec) sys.modules[spec.name] = packaging spec = importlib.util.spec_from_file_location( - "packaging.tags", Path(r"{packaging.tags.__file__}") + "packaging.tags", Path(r"{poetry.core._vendor.packaging.tags.__file__}") ) packaging_tags = importlib.util.module_from_spec(spec) spec.loader.exec_module(packaging_tags) @@ -432,7 +432,7 @@ def tag(self) -> str: # poetry-core is not run in the build environment # -> this is probably not a PEP 517 build but a poetry build return self._get_sys_tags()[0] - sys_tag = next(packaging.tags.sys_tags()) + sys_tag = next(poetry.core._vendor.packaging.tags.sys_tags()) tag = (sys_tag.interpreter, sys_tag.abi, sys_tag.platform) else: platform = "any" diff --git a/src/poetry/core/masonry/metadata.py b/src/poetry/core/masonry/metadata.py index 0c18c1051..6c31fa8c4 100644 --- a/src/poetry/core/masonry/metadata.py +++ b/src/poetry/core/masonry/metadata.py @@ -6,7 +6,7 @@ if TYPE_CHECKING: - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName from poetry.core.packages.package import Package diff --git a/src/poetry/core/masonry/utils/helpers.py b/src/poetry/core/masonry/utils/helpers.py index 2532ed282..2d377fb0b 100644 --- a/src/poetry/core/masonry/utils/helpers.py +++ b/src/poetry/core/masonry/utils/helpers.py @@ -6,7 +6,7 @@ if TYPE_CHECKING: - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName DistributionName = NewType("DistributionName", str) diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index ef6185e65..64e3dbe05 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -10,7 +10,7 @@ from typing import Sequence from typing import TypeVar -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint from poetry.core.constraints.version import parse_constraint @@ -25,7 +25,7 @@ if TYPE_CHECKING: from collections.abc import Iterable - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName from poetry.core.constraints.version import VersionConstraint from poetry.core.packages.directory_dependency import DirectoryDependency diff --git a/src/poetry/core/packages/dependency_group.py b/src/poetry/core/packages/dependency_group.py index 9afa692e4..9c21fc776 100644 --- a/src/poetry/core/packages/dependency_group.py +++ b/src/poetry/core/packages/dependency_group.py @@ -31,7 +31,7 @@ def add_dependency(self, dependency: Dependency) -> None: self._dependencies.append(dependency) def remove_dependency(self, name: str) -> None: - from packaging.utils import canonicalize_name + from poetry.core._vendor.packaging.utils import canonicalize_name name = canonicalize_name(name) diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index f75dad7b3..63adb92e9 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -25,7 +25,7 @@ from collections.abc import Iterator from pathlib import Path - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName from poetry.core.constraints.version import Version from poetry.core.constraints.version import VersionConstraint diff --git a/src/poetry/core/packages/specification.py b/src/poetry/core/packages/specification.py index 995ecf153..22b50a2fb 100644 --- a/src/poetry/core/packages/specification.py +++ b/src/poetry/core/packages/specification.py @@ -5,13 +5,13 @@ from typing import TYPE_CHECKING from typing import TypeVar -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name if TYPE_CHECKING: from collections.abc import Iterable - from packaging.utils import NormalizedName + from poetry.core._vendor.packaging.utils import NormalizedName T = TypeVar("T", bound="PackageSpecification") @@ -27,7 +27,7 @@ def __init__( source_subdirectory: str | None = None, features: Iterable[str] | None = None, ) -> None: - from packaging.utils import canonicalize_name + from poetry.core._vendor.packaging.utils import canonicalize_name # Attributes must be immutable for clone() to be safe! # (For performance reasons, clone only creates a copy instead of a deep copy). diff --git a/src/poetry/core/utils/_compat.py b/src/poetry/core/utils/_compat.py index c8f45dffe..2b95cf554 100644 --- a/src/poetry/core/utils/_compat.py +++ b/src/poetry/core/utils/_compat.py @@ -8,7 +8,7 @@ if sys.version_info < (3, 11): # compatibility for python <3.11 - import tomli as tomllib + import poetry.core._vendor.tomli as tomllib else: import tomllib diff --git a/src/poetry/core/utils/helpers.py b/src/poetry/core/utils/helpers.py index 7306973f5..72a9b744b 100644 --- a/src/poetry/core/utils/helpers.py +++ b/src/poetry/core/utils/helpers.py @@ -13,7 +13,7 @@ from typing import TYPE_CHECKING from typing import Any -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name if TYPE_CHECKING: diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 2001cc384..02c22b570 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -13,7 +13,7 @@ from typing import TypeVar from typing import Union -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.constraints.generic import BaseConstraint from poetry.core.constraints.generic import Constraint @@ -32,7 +32,7 @@ from collections.abc import Iterable from collections.abc import Mapping - from lark import Tree + from poetry.core._vendor.lark import Tree class InvalidMarker(ValueError): @@ -965,7 +965,7 @@ def parse_marker(marker: str) -> BaseMarker: def _compact_markers( tree_elements: Tree, tree_prefix: str = "", top_level: bool = True ) -> BaseMarker: - from lark import Token + from poetry.core._vendor.lark import Token # groups is a disjunction of conjunctions # eg [[A, B], [C, D]] represents "(A and B) or (C and D)" diff --git a/src/poetry/core/version/parser.py b/src/poetry/core/version/parser.py index 085cfa384..234be0ca3 100644 --- a/src/poetry/core/version/parser.py +++ b/src/poetry/core/version/parser.py @@ -7,8 +7,8 @@ if TYPE_CHECKING: from pathlib import Path - from lark import Lark - from lark import Tree + from poetry.core._vendor.lark import Lark + from poetry.core._vendor.lark import Tree class Parser: @@ -21,7 +21,7 @@ def __init__( self._lark: Lark | None = None def parse(self, text: str, **kwargs: Any) -> Tree: - from lark import Lark + from poetry.core._vendor.lark import Lark if self._lark is None: self._lark = Lark.open( diff --git a/src/poetry/core/version/pep440/parser.py b/src/poetry/core/version/pep440/parser.py index 914086e13..8363947da 100644 --- a/src/poetry/core/version/pep440/parser.py +++ b/src/poetry/core/version/pep440/parser.py @@ -6,7 +6,7 @@ from typing import TYPE_CHECKING from typing import TypeVar -from packaging.version import VERSION_PATTERN +from poetry.core._vendor.packaging.version import VERSION_PATTERN from poetry.core.version.exceptions import InvalidVersion from poetry.core.version.pep440 import Release diff --git a/src/poetry/core/version/requirements.py b/src/poetry/core/version/requirements.py index 8058ade10..a88c2f18f 100644 --- a/src/poetry/core/version/requirements.py +++ b/src/poetry/core/version/requirements.py @@ -29,8 +29,8 @@ class Requirement: """ def __init__(self, requirement_string: str) -> None: - from lark import UnexpectedCharacters - from lark import UnexpectedToken + from poetry.core._vendor.lark import UnexpectedCharacters + from poetry.core._vendor.lark import UnexpectedToken try: parsed = _parser.parse(requirement_string) diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index bd1908450..ef0557348 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -14,7 +14,7 @@ import pytest -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.factory import Factory from poetry.core.masonry.builders.sdist import SdistBuilder diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index eb134f4ee..0cd4ff0ce 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -6,7 +6,7 @@ import pytest -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.constraints.version.exceptions import ParseConstraintError from poetry.core.packages.dependency import Dependency diff --git a/tests/packages/test_vcs_dependency.py b/tests/packages/test_vcs_dependency.py index 6b78b874b..a393993b7 100644 --- a/tests/packages/test_vcs_dependency.py +++ b/tests/packages/test_vcs_dependency.py @@ -4,7 +4,7 @@ import pytest -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.packages.vcs_dependency import VCSDependency diff --git a/tests/test_factory.py b/tests/test_factory.py index 3d34787e2..6e720d6c4 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -7,7 +7,7 @@ import pytest -from packaging.utils import canonicalize_name +from poetry.core._vendor.packaging.utils import canonicalize_name from poetry.core.constraints.version import parse_constraint from poetry.core.factory import Factory diff --git a/vendors/patches/lark.patch b/vendors/patches/lark.patch new file mode 100644 index 000000000..bae4d5aed --- /dev/null +++ b/vendors/patches/lark.patch @@ -0,0 +1,10 @@ +diff --git a/src/poetry/core/_vendor/lark/load_grammar.py b/src/poetry/core/_vendor/lark/load_grammar.py +index 362a845..e9b07e6 100644 +--- a/src/poetry/core/_vendor/lark/load_grammar.py ++++ b/src/poetry/core/_vendor/lark/load_grammar.py +@@ -861,7 +861,7 @@ class FromPackageLoader: + raise IOError('Cannot find grammar in given paths') from err + + +-stdlib_loader = FromPackageLoader('lark', IMPORT_PATHS) ++stdlib_loader = FromPackageLoader('poetry.core._vendor.lark', IMPORT_PATHS)