Advice for seeder plugin #2245
|
I've read the docs & source code of the built-in seeders but I can't quite figure out what to do. Essentially, all I need is to install a certain package/wheel when each virtual environment is created. cc @gaborbernat do you have any recommendations? |
Replies: 9 comments 1 reply
|
Bump 🙂 Does anyone have an example of this? |
|
Ah forgot about this, can you ping me again on Monday? 😁And I'll have a look and path forward. |
|
Ping! |
So my original idea was that in this case, you could extend your code from an existing seeder, and then you can do it at the end of the run method: from virtualenv.seed.embed.via_app_data.via_app_data import FromAppData
class CustomSeeder(FromAppData):
def run(self, creator):
super().run()
subprocess.run([self.exe, '-m', 'pip', 'install', 'magic'])# setup.cfg
virtualenv.seed =
custom = virtualenv_plugin.CustomSeederOne thing that's not really solved, though, is how you enable this seeder. The user would have to opt-in to use it explicitly via config/CLI args. Of course, you can always use monkey patch the default here ... but there's no official way at the moment to change the default seeder without explicit opt-in. |
|
Thanks! If I ship the wheel, is there a way to add it to the list of embedded wheels so it automatically gets installed? I tried |
|
You can extend the list of packages to install under https://github.com/pypa/virtualenv/blob/main/src/virtualenv/seed/embed/base_embed.py#L38. You might need to patch the embed file list under https://github.com/pypa/virtualenv/blob/main/src/virtualenv/seed/wheels/embed/__init__.py#L7 to get picked up. Tag me as a reviewer if you can, so can double-check how you do it looks good. |
|
Hey guys! I also need this, I need a certain package ( It seems that you guys are talking exactly about this, aren't you? Do you know how to configure virtualenv, so that it does what I need? Thank you! |
|
I don't think that plugin has been created, so you'd likely need to do so 👍 |
|
This discussion has an accepted answer with a detailed example of how to create a custom seeder plugin by extending |
So my original idea was that in this case, you could extend your code from an existing seeder, and then you can do it at the end of the run method:
One thing that's not really solved, though, is how you enable this seeder. The user would have to opt-in to use it explicitly via config/CLI args. Of course, you can always use monkey patch the default…