juc500 정상동작
This commit is contained in:
Vendored
BIN
Binary file not shown.
vendor/python-windows/Lib/site-packages/virtualenv/run/plugin/__pycache__/activators.cpython-311.pyc
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from argparse import ArgumentTypeError
|
||||
from collections import OrderedDict
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .base import ComponentBuilder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
from python_discovery import PythonInfo
|
||||
|
||||
from virtualenv.activation.activator import Activator
|
||||
from virtualenv.config.cli.parser import VirtualEnvConfigParser, VirtualEnvOptions
|
||||
|
||||
|
||||
class ActivationSelector(ComponentBuilder):
|
||||
def __init__(self, interpreter: PythonInfo, parser: VirtualEnvConfigParser) -> None:
|
||||
self.default = None
|
||||
possible = OrderedDict(
|
||||
(k, v)
|
||||
for k, v in self.options("virtualenv.activate").items()
|
||||
if v.supports(interpreter) # ty: ignore[unresolved-attribute]
|
||||
)
|
||||
super().__init__(interpreter, parser, "activators", possible)
|
||||
self.parser.description = "options for activation scripts"
|
||||
self.active = None
|
||||
|
||||
def add_selector_arg_parse(self, name: str, choices: Sequence[str]) -> None:
|
||||
self.default = ",".join(choices)
|
||||
self.parser.add_argument(
|
||||
f"--{name}",
|
||||
default=self.default,
|
||||
metavar="comma_sep_list",
|
||||
required=False,
|
||||
help="activators to generate - default is all supported",
|
||||
type=self._extract_activators,
|
||||
)
|
||||
|
||||
def _extract_activators(self, entered_str: str) -> list[str]:
|
||||
elements = [e.strip() for e in entered_str.split(",") if e.strip()]
|
||||
missing = [e for e in elements if e not in self.possible]
|
||||
if missing:
|
||||
msg = f"the following activators are not available {','.join(missing)}"
|
||||
raise ArgumentTypeError(msg)
|
||||
return elements
|
||||
|
||||
def handle_selected_arg_parse(self, options: VirtualEnvOptions) -> None: # ty: ignore[invalid-method-override]
|
||||
selected_activators = (
|
||||
self._extract_activators(self.default) if options.activators is self.default else options.activators
|
||||
)
|
||||
self.active = {k: v for k, v in self.possible.items() if k in selected_activators}
|
||||
self.parser.add_argument(
|
||||
"--prompt",
|
||||
dest="prompt",
|
||||
metavar="prompt",
|
||||
help=(
|
||||
"provides an alternative prompt prefix for this environment "
|
||||
"(value of . means name of the current working directory)"
|
||||
),
|
||||
default=None,
|
||||
)
|
||||
for activator in self.active.values():
|
||||
activator.add_parser_arguments(self.parser, self.interpreter) # ty: ignore[unresolved-attribute]
|
||||
|
||||
def create(self, options: VirtualEnvOptions) -> list[Activator]:
|
||||
assert self.active is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
return [activator_class(options) for activator_class in self.active.values()]
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ActivationSelector",
|
||||
]
|
||||
@@ -0,0 +1,81 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
from importlib.metadata import entry_points
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
from python_discovery import PythonInfo
|
||||
|
||||
from virtualenv.config.cli.parser import VirtualEnvConfigParser, VirtualEnvOptions
|
||||
|
||||
|
||||
class PluginLoader:
|
||||
_OPTIONS = None
|
||||
_ENTRY_POINTS = None
|
||||
|
||||
@classmethod
|
||||
def entry_points_for(cls, key: str) -> OrderedDict[str, type]:
|
||||
if sys.version_info >= (3, 10):
|
||||
selected = list(cls.entry_points().select(group=key)) # ty: ignore[unresolved-attribute]
|
||||
else:
|
||||
selected = list(cls.entry_points().get(key, [])) # ty: ignore[unresolved-attribute]
|
||||
# Third-party packages may register entry points with the same name as virtualenv's
|
||||
# built-ins (e.g. xonsh's own `virtualenv.activate.xonsh`). Sort so built-ins are
|
||||
# inserted last into the OrderedDict, making them win on name collision.
|
||||
selected.sort(key=lambda e: e.value.startswith("virtualenv."))
|
||||
return OrderedDict((e.name, e.load()) for e in selected)
|
||||
|
||||
@staticmethod
|
||||
def entry_points() -> object:
|
||||
if PluginLoader._ENTRY_POINTS is None:
|
||||
PluginLoader._ENTRY_POINTS = entry_points()
|
||||
return PluginLoader._ENTRY_POINTS
|
||||
|
||||
|
||||
class ComponentBuilder(PluginLoader):
|
||||
def __init__(
|
||||
self, interpreter: PythonInfo, parser: VirtualEnvConfigParser, name: str, possible: dict[str, type]
|
||||
) -> None:
|
||||
self.interpreter = interpreter
|
||||
self.name = name
|
||||
self._impl_class = None
|
||||
self.possible = possible
|
||||
self.parser = parser.add_argument_group(title=name)
|
||||
self.add_selector_arg_parse(name, list(self.possible))
|
||||
|
||||
@classmethod
|
||||
def options(cls, key: str) -> OrderedDict[str, type]:
|
||||
if cls._OPTIONS is None:
|
||||
cls._OPTIONS = cls.entry_points_for(key)
|
||||
return cls._OPTIONS
|
||||
|
||||
def add_selector_arg_parse(self, name: str, choices: Sequence[str]) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def handle_selected_arg_parse(self, options: VirtualEnvOptions) -> str:
|
||||
selected = getattr(options, self.name)
|
||||
if selected not in self.possible:
|
||||
msg = f"No implementation for {self.interpreter}"
|
||||
raise RuntimeError(msg)
|
||||
self._impl_class = self.possible[selected]
|
||||
self.populate_selected_argparse(selected, options.app_data)
|
||||
return selected
|
||||
|
||||
def populate_selected_argparse(self, selected: str, app_data: object) -> None:
|
||||
self.parser.description = f"options for {self.name} {selected}"
|
||||
assert self._impl_class is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
self._impl_class.add_parser_arguments(self.parser, self.interpreter, app_data) # ty: ignore[unresolved-attribute]
|
||||
|
||||
def create(self, options: VirtualEnvOptions) -> object:
|
||||
assert self._impl_class is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
return self._impl_class(options, self.interpreter)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ComponentBuilder",
|
||||
"PluginLoader",
|
||||
]
|
||||
@@ -0,0 +1,98 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict, defaultdict
|
||||
from typing import TYPE_CHECKING, NamedTuple
|
||||
|
||||
from virtualenv.create.describe import Describe
|
||||
from virtualenv.create.via_global_ref.builtin.builtin_way import VirtualenvBuiltin
|
||||
|
||||
from .base import ComponentBuilder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
from python_discovery import PythonInfo
|
||||
|
||||
from virtualenv.config.cli.parser import VirtualEnvConfigParser, VirtualEnvOptions
|
||||
from virtualenv.create.creator import Creator, CreatorMeta
|
||||
|
||||
|
||||
class CreatorInfo(NamedTuple):
|
||||
key_to_class: dict[str, type[Creator]]
|
||||
key_to_meta: dict[str, CreatorMeta]
|
||||
describe: type[Describe] | None
|
||||
builtin_key: str
|
||||
|
||||
|
||||
class CreatorSelector(ComponentBuilder):
|
||||
def __init__(self, interpreter: PythonInfo, parser: VirtualEnvConfigParser) -> None:
|
||||
creators, self.key_to_meta, self.describe, self.builtin_key = self.for_interpreter(interpreter)
|
||||
super().__init__(interpreter, parser, "creator", creators) # ty: ignore[invalid-argument-type]
|
||||
|
||||
@classmethod
|
||||
def for_interpreter(cls, interpreter: PythonInfo) -> CreatorInfo:
|
||||
key_to_class, key_to_meta, builtin_key, describe = OrderedDict(), {}, None, None
|
||||
errors = defaultdict(list)
|
||||
for key, creator_class in cls.options("virtualenv.create").items():
|
||||
if key == "builtin":
|
||||
msg = "builtin creator is a reserved name"
|
||||
raise RuntimeError(msg)
|
||||
meta = creator_class.can_create(interpreter) # ty: ignore[unresolved-attribute]
|
||||
if meta:
|
||||
if meta.error:
|
||||
errors[meta.error].append(creator_class)
|
||||
else:
|
||||
if "builtin" not in key_to_class and issubclass(creator_class, VirtualenvBuiltin):
|
||||
builtin_key = key
|
||||
key_to_class["builtin"] = creator_class
|
||||
key_to_meta["builtin"] = meta
|
||||
key_to_class[key] = creator_class
|
||||
key_to_meta[key] = meta
|
||||
if describe is None and issubclass(creator_class, Describe) and creator_class.can_describe(interpreter):
|
||||
describe = creator_class
|
||||
if not key_to_meta:
|
||||
if errors:
|
||||
rows = [f"{k} for creators {', '.join(i.__name__ for i in v)}" for k, v in errors.items()]
|
||||
raise RuntimeError("\n".join(rows))
|
||||
msg = f"No virtualenv implementation for {interpreter}"
|
||||
raise RuntimeError(msg)
|
||||
return CreatorInfo(
|
||||
key_to_class=key_to_class,
|
||||
key_to_meta=key_to_meta,
|
||||
describe=describe,
|
||||
builtin_key=builtin_key or "",
|
||||
)
|
||||
|
||||
def add_selector_arg_parse(self, name: str, choices: Sequence[str]) -> None:
|
||||
# prefer the built-in venv if present, otherwise fallback to first defined type
|
||||
choices = sorted(choices, key=lambda a: 0 if a == "builtin" else 1)
|
||||
default_value = self._get_default(choices)
|
||||
self.parser.add_argument(
|
||||
f"--{name}",
|
||||
choices=choices,
|
||||
default=default_value,
|
||||
required=False,
|
||||
help=f"create environment via{'' if self.builtin_key is None else f' (builtin = {self.builtin_key})'}",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_default(choices: list[str]) -> str:
|
||||
return next(iter(choices))
|
||||
|
||||
def populate_selected_argparse(self, selected: str, app_data: object) -> None:
|
||||
self.parser.description = f"options for {self.name} {selected}"
|
||||
assert self._impl_class is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
self._impl_class.add_parser_arguments(self.parser, self.interpreter, self.key_to_meta[selected], app_data) # ty: ignore[unresolved-attribute]
|
||||
|
||||
def create(self, options: VirtualEnvOptions) -> Creator:
|
||||
options.meta = self.key_to_meta[getattr(options, self.name)]
|
||||
assert self._impl_class is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
if not issubclass(self._impl_class, Describe):
|
||||
options.describe = self.describe(options, self.interpreter) # ty: ignore[call-non-callable, invalid-argument-type]
|
||||
return super().create(options) # ty: ignore[invalid-return-type]
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CreatorInfo",
|
||||
"CreatorSelector",
|
||||
]
|
||||
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .base import PluginLoader
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from virtualenv.config.cli.parser import VirtualEnvConfigParser
|
||||
from virtualenv.discovery.discover import Discover
|
||||
|
||||
|
||||
class Discovery(PluginLoader):
|
||||
"""Discovery plugins."""
|
||||
|
||||
|
||||
def get_discover(parser: VirtualEnvConfigParser, args: list[str] | None) -> Discover:
|
||||
discover_types = Discovery.entry_points_for("virtualenv.discovery")
|
||||
discovery_parser = parser.add_argument_group(
|
||||
title="discovery",
|
||||
description="discover and provide a target interpreter",
|
||||
)
|
||||
choices = _get_default_discovery(discover_types)
|
||||
# prefer the builtin if present, otherwise fallback to first defined type
|
||||
choices = sorted(choices, key=lambda a: 0 if a == "builtin" else 1)
|
||||
try:
|
||||
default_discovery = next(iter(choices))
|
||||
except StopIteration as e:
|
||||
msg = "No discovery plugin found. Try reinstalling virtualenv to fix this issue."
|
||||
raise RuntimeError(msg) from e
|
||||
discovery_parser.add_argument(
|
||||
"--discovery",
|
||||
choices=choices,
|
||||
default=default_discovery,
|
||||
required=False,
|
||||
help="interpreter discovery method",
|
||||
)
|
||||
options, _ = parser.parse_known_args(args)
|
||||
discovery = options.discovery
|
||||
if discovery not in discover_types:
|
||||
available = ", ".join(sorted(discover_types))
|
||||
msg = (
|
||||
f"discovery {discovery!r} is not available. "
|
||||
f"Available discovery methods: {available}. "
|
||||
f"Is the plugin installed?"
|
||||
)
|
||||
raise RuntimeError(msg)
|
||||
discover_class = discover_types[discovery]
|
||||
discover_class.add_parser_arguments(discovery_parser) # ty: ignore[unresolved-attribute]
|
||||
options, _ = parser.parse_known_args(args, namespace=options)
|
||||
return discover_class(options)
|
||||
|
||||
|
||||
def _get_default_discovery(discover_types: dict[str, type]) -> list[str]:
|
||||
return list(discover_types.keys())
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Discovery",
|
||||
"get_discover",
|
||||
]
|
||||
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .base import ComponentBuilder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
from python_discovery import PythonInfo
|
||||
|
||||
from virtualenv.config.cli.parser import VirtualEnvConfigParser, VirtualEnvOptions
|
||||
from virtualenv.seed.seeder import Seeder
|
||||
|
||||
|
||||
class SeederSelector(ComponentBuilder):
|
||||
def __init__(self, interpreter: PythonInfo, parser: VirtualEnvConfigParser) -> None:
|
||||
possible = self.options("virtualenv.seed")
|
||||
super().__init__(interpreter, parser, "seeder", possible)
|
||||
|
||||
def add_selector_arg_parse(self, name: str, choices: Sequence[str]) -> None:
|
||||
self.parser.add_argument(
|
||||
f"--{name}",
|
||||
choices=choices,
|
||||
default=self._get_default(),
|
||||
required=False,
|
||||
help="seed packages install method",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"--no-seed",
|
||||
"--without-pip",
|
||||
help="do not install seed packages",
|
||||
action="store_true",
|
||||
dest="no_seed",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_default() -> str:
|
||||
return "app-data"
|
||||
|
||||
def handle_selected_arg_parse(self, options: VirtualEnvOptions) -> str:
|
||||
return super().handle_selected_arg_parse(options)
|
||||
|
||||
def create(self, options: VirtualEnvOptions) -> Seeder:
|
||||
assert self._impl_class is not None # noqa: S101 # Set by handle_selected_arg_parse
|
||||
seeder = self._impl_class(options)
|
||||
if seeder.enabled and (reason := seeder.cannot_seed(self.interpreter)) is not None:
|
||||
raise RuntimeError(reason)
|
||||
return seeder
|
||||
|
||||
|
||||
__all__ = [
|
||||
"SeederSelector",
|
||||
]
|
||||
Reference in New Issue
Block a user