diff --git a/src/virtualenv/seed/embed/base_embed.py b/src/virtualenv/seed/embed/base_embed.py index c794e834d..b745eaa1c 100644 --- a/src/virtualenv/seed/embed/base_embed.py +++ b/src/virtualenv/seed/embed/base_embed.py @@ -13,6 +13,13 @@ PERIODIC_UPDATE_ON_BY_DEFAULT = True +def _parse_basic_req(line): + parts = line.split("==") + if len(parts) == 1: + return (line, None) + return (parts[0], parts[1]) + + @add_metaclass(ABCMeta) class BaseEmbed(Seeder): def __init__(self, options): @@ -30,6 +37,7 @@ def __init__(self, options): self.no_wheel = options.no_wheel self.app_data = options.app_data self.periodic_update = not options.no_periodic_update + self.seed_package = options.seed_package if not self.distribution_to_versions(): self.enabled = False @@ -43,11 +51,14 @@ def distributions(cls): } def distribution_to_versions(self): - return { - distribution: getattr(self, "{}_version".format(distribution)) - for distribution in self.distributions() - if getattr(self, "no_{}".format(distribution)) is False - } + distributions = dict(self.seed_package) + for distribution in self.distributions(): + if getattr(self, "no_{}".format(distribution)): + distributions.pop(distribution, None) + else: + version = getattr(self, "{}_version".format(distribution)) + distributions[distribution] = version + return distributions @classmethod def add_parser_arguments(cls, parser, interpreter, app_data): @@ -98,6 +109,15 @@ def add_parser_arguments(cls, parser, interpreter, app_data): help="disable the periodic (once every 14 days) update of the embedded wheels", default=not PERIODIC_UPDATE_ON_BY_DEFAULT, ) + parser.add_argument( + "--seed-package", + metavar="package[==version]", + dest="seed_package", + nargs="+", + type=_parse_basic_req, + help="a list of extra packages to install", + default=[], + ) def __unicode__(self): result = self.__class__.__name__ diff --git a/src/virtualenv/seed/wheels/embed/__init__.py b/src/virtualenv/seed/wheels/embed/__init__.py index 74a691b18..b2d8b395c 100644 --- a/src/virtualenv/seed/wheels/embed/__init__.py +++ b/src/virtualenv/seed/wheels/embed/__init__.py @@ -50,8 +50,10 @@ def get_embed_wheel(distribution, for_py_version): - path = BUNDLE_FOLDER / (BUNDLE_SUPPORT.get(for_py_version, {}) or BUNDLE_SUPPORT[MAX]).get(distribution) - return Wheel.from_path(path) + wheel_name = (BUNDLE_SUPPORT.get(for_py_version, {}) or BUNDLE_SUPPORT[MAX]).get(distribution) + if wheel_name is None: + return None + return Wheel.from_path(BUNDLE_FOLDER / wheel_name) __all__ = (