|
| 1 | +"""Virtual seed plugin""" |
| 2 | + |
| 3 | +import argparse |
| 4 | +import typing |
| 5 | + |
| 6 | +from virtualenv.config.cli.parser import VirtualEnvOptions |
| 7 | +from virtualenv.seed.embed.via_app_data.via_app_data import FromAppData |
| 8 | +from virtualenv.seed.wheels import Version |
| 9 | + |
| 10 | + |
| 11 | +class FromagerSeeder(FromAppData): |
| 12 | + """Custom virtualenv seeder to install build command""" |
| 13 | + |
| 14 | + extra_packages: typing.ClassVar[dict[str, Version]] = {"build": Version.bundle} |
| 15 | + |
| 16 | + def __init__(self, options: VirtualEnvOptions) -> None: |
| 17 | + for distribution, default in self.extra_packages.items(): |
| 18 | + setattr(self, f"no_{distribution}", False) |
| 19 | + setattr(self, f"{distribution}_version", default) |
| 20 | + |
| 21 | + super().__init__(options) |
| 22 | + if not self.download: |
| 23 | + raise argparse.ArgumentError( |
| 24 | + None, "--download is required to install extra packages" |
| 25 | + ) |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def distributions(cls) -> dict[str, Version]: |
| 29 | + dist = super().distributions() |
| 30 | + dist.update(cls.extra_packages) |
| 31 | + return dist |
| 32 | + |
| 33 | + @classmethod |
| 34 | + def add_parser_arguments( |
| 35 | + cls, parser: argparse.ArgumentParser, interpreter, app_data |
| 36 | + ) -> None: |
| 37 | + super().add_parser_arguments(parser, interpreter, app_data) |
| 38 | + # virtualenv no longer installs setuptool and wheels for |
| 39 | + # Python >= 3.12. force installation |
| 40 | + for action in parser._actions: |
| 41 | + if action.dest in {"setuptools", "wheel"}: |
| 42 | + action.default = Version.bundle |
0 commit comments