-
Notifications
You must be signed in to change notification settings - Fork 0
Installer plugin demo #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
c1202e2
30328da
d269374
aa16bec
1da7003
7d79088
3941353
f64a857
4ecead5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,16 +500,12 @@ def from_cli( | |
| # environment spec plugin. The core conda cli commands are not | ||
| # ready for that yet. So, use this old way of reading specs from | ||
| # files. | ||
| for fpath in args.file: | ||
| try: | ||
| specs.extend( | ||
| [spec for spec in specs_from_url(fpath) if spec != EXPLICIT_MARKER] | ||
| ) | ||
| except UnicodeError: | ||
| raise CondaError( | ||
| "Error reading file, file should be a text file containing packages\n" | ||
| "See `conda create --help` for details." | ||
| ) | ||
| file_envs = [] | ||
| for path in args.file: | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for the purposes of demoing |
||
| # parse the file | ||
| spec_hook = context.plugin_manager.get_environment_specifier(path) | ||
| file_env = spec_hook.environment_spec(path).env | ||
| file_envs.append(file_env) | ||
|
|
||
| # Add default packages if required. If the default package is already | ||
| # present in the list of specs, don't add it (this will override any | ||
|
|
@@ -538,11 +534,13 @@ def from_cli( | |
| "Cannot mix specifications with conda package filenames" | ||
| ) | ||
|
|
||
| return Environment( | ||
| cli_env = Environment( | ||
| name=args.name, | ||
| prefix=context.target_prefix, | ||
| platform=context.subdir, | ||
| requested_packages=requested_packages, | ||
| explicit_packages=explicit_packages, | ||
| config=EnvironmentConfig.from_context(), | ||
| ) | ||
|
|
||
| return Environment.merge(cli_env, *file_envs) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (C) 2012 Anaconda, Inc | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| """Register the built-in env_installer hook implementations.""" | ||
|
|
||
| from . import pip, uv | ||
|
|
||
| #: The list of env_installer plugins for easier registration with pluggy | ||
| plugins = [pip, uv] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright (C) 2012 Anaconda, Inc | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| """Register the pip installer for conda env files.""" | ||
|
|
||
| from .. import CondaInstaller, hookimpl | ||
|
|
||
|
|
||
| @hookimpl | ||
| def conda_installers(): | ||
| from ...env.installers.pip import dry_run as pip_dry_run | ||
| from ...env.installers.pip import install as pip_install | ||
|
|
||
| # In this demo, swap the meaning of "pip" and "pypi" | ||
| yield CondaInstaller( | ||
| name="pypi_pip", | ||
| types=("pip","pypi"), | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
| install=pip_install, | ||
| dry_run=pip_dry_run, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (C) 2012 Anaconda, Inc | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| """Register the pip installer for conda env files.""" | ||
|
|
||
| from .. import CondaInstaller, hookimpl | ||
| from ...models.environment import EnvironmentConfig | ||
|
|
||
| def uv_install(prefix: str, specs: list[str], *args, **kwargs) -> dict: | ||
| print("pretending to install stuff with uv") | ||
| for spec in specs: | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clearly not actually implementing an install with uv. It's helpful to have this output for visual confirmation that the right plugins are getting invoked. |
||
| print(f" - {spec}") | ||
| return {} | ||
|
|
||
|
|
||
| def uv_dry_run(prefix: str, specs: list[str], *args, **kwargs) -> dict: | ||
| print("pretending to (dry-run) install stuff with uv") | ||
| for spec in specs: | ||
| print(f" - {spec}") | ||
| return {} | ||
|
|
||
|
|
||
| @hookimpl | ||
| def conda_installers(): | ||
| yield CondaInstaller( | ||
| name="pypi_uv", | ||
| types=("uv", "pip", "pypi"), | ||
| install=uv_install, | ||
| dry_run=uv_dry_run, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installing conda packages does not touch the plugin system.