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

Switch to in-tree vendoring instead of patching the sys.path #753

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions src/poetry/core/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)
8 changes: 4 additions & 4 deletions src/poetry/core/_vendor/fastjsonschema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

.. code-block:: python

import fastjsonschema
from poetry.core._vendor import fastjsonschema

point_schema = {
"type": "object",
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/parsers/lalr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/parsers/lalr_parser_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/tools/nearley.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)+
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/core/_vendor/lark/tools/serialize.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/_vendor/lark/tools/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/_vendor/lark/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/_vendor/lark/tree_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/constraints/version/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/poetry/core/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/masonry/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core._vendor.packaging.utils import NormalizedName


DistributionName = NewType("DistributionName", str)
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/packages/dependency_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/core/packages/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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).
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 @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)"
Expand Down
Loading
Loading