Skip to content
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

feat: Scanning plugin entrypoints of external packages #2377

Merged
merged 16 commits into from
Aug 11, 2024

Conversation

jopemachine
Copy link
Member

@jopemachine jopemachine commented Jul 4, 2024

Fix #2359, refs #1683.

Wheel distributions

This PR implements an automated process to extract .whl files found under the {base-dir}/wheelhouse directory and add their source directories to PYTHONPATH, so that they could be loaded without additional installation steps.

Example:

  • Download a wheel package into ./wheelhouse directory.
  • Upon scanning, it will be extracted as sub-directories of ./wheelhouse.
  • The package appears in the scan result from the "python-package" source.

Tip

To distribute and install plugins that have external dependencies that the core does not use, you may utilize the pip wheel command to create a collection of wheel files and put it under the wheelhouse directory, as the plugin loader will load all of them into PYTHONPATH.

Note

When a Python wheel file is extracted, it contains:

  • The top-most package directory (For our packages, it is usually ai.)
  • {pkg-name}-{version}.dist-info/
    • entry_points.txt
    • METADATA
    • RECORDS
    • top_level.txt
    • WHEEL
  • {pkg-name}.libs/ (empty)

We may simply insert the extracted directory into sys.path to make it importable, assuming that all dependencies of the wheel is already available in the venv.

Plugin source checkouts

It also enhances the backend.ai plugin scan command (#2070) to explicitly display the plugin-checkout sources while skipping plugin-checkout sources when actually loading the plugins. Also added more detailed guides such as [agent].allowed-compute-plugins checks when the group name contains "accelerator".

You may enable the debug logging of the scan command itself by adding --debug option to the plugin subcommand, like ./backend.ai plugin --debug scan ....

Example:

  • Clone a private cuda plugin into the ./plugins directory.
  • Run ./backend.ai plugin scan backendai_accelerator_v21:
image
  • Run ./py -m pip install -e plugins/cuda.
  • Run ./backend.ai plugin scan backendai_accelerator_v21:
image

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue

📚 Documentation preview 📚: https://sorna--2377.org.readthedocs.build/en/2377/


📚 Documentation preview 📚: https://sorna-ko--2377.org.readthedocs.build/ko/2377/

Copy link

graphite-app bot commented Jul 4, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “flow:merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “flow:hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added comp:common Related to Common component size:M 30~100 LoC labels Jul 4, 2024
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @jopemachine and the rest of your teammates on Graphite Graphite

@jopemachine jopemachine added this to the 24.09 milestone Jul 4, 2024
@github-actions github-actions bot added type:feature Add new features urgency:3 Must be finished within a certain time frame. labels Jul 4, 2024
@jopemachine jopemachine changed the title feat: scanning entrypoints from external packages feat: Scanning plugin entrypoints of external packages Jul 4, 2024
@jopemachine jopemachine force-pushed the 07-04-feat_scanning_entrypoints_from_external_packages branch from fbca1c9 to 3c77df7 Compare July 8, 2024 02:06
@github-actions github-actions bot added area:docs Documentations comp:manager Related to Manager component comp:agent Related to Agent component comp:installer Related to Installer require:db-migration Automatically set when alembic migrations are added or updated size:XL 500~ LoC and removed size:M 30~100 LoC labels Jul 14, 2024
@jopemachine jopemachine force-pushed the 07-04-feat_scanning_entrypoints_from_external_packages branch from 419a7e6 to 6f0fedf Compare July 14, 2024 09:53
@github-actions github-actions bot added size:M 30~100 LoC and removed size:XL 500~ LoC labels Jul 14, 2024
@jopemachine jopemachine removed type:feature Add new features area:docs Documentations comp:installer Related to Installer require:db-migration Automatically set when alembic migrations are added or updated urgency:3 Must be finished within a certain time frame. labels Jul 14, 2024
@github-actions github-actions bot added type:feature Add new features urgency:3 Must be finished within a certain time frame. labels Jul 14, 2024
@jopemachine jopemachine removed comp:manager Related to Manager component comp:agent Related to Agent component labels Jul 14, 2024
Copy link
Member

@achimnol achimnol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um.. we need to support the scenario for developing plugins by cloning the repositories into plugins/ directory.
Do you have any better idea to it?

@jopemachine
Copy link
Member Author

Um.. we need to support the scenario for developing plugins by cloning the repositories into plugins/ directory. Do you have any better idea to it?

Even if scan_entrypoint_from_plugin_checkouts is removed from the development environment, each plugin's path under the plugins directory is added to PYTHONPATH from ./py, so it operates the same as before.

That is, all plugins under the plugins directory are still recognized as plugins, and we can install and develop plugins in an editable way through the ./scripts/install-plugin.sh script in the development environment.

@achimnol achimnol force-pushed the 07-04-feat_scanning_entrypoints_from_external_packages branch from d440a95 to 0bd1596 Compare August 8, 2024 13:23
@achimnol
Copy link
Member

achimnol commented Aug 8, 2024

I'm also considering to fix scie-based executables suffer from missing imports when executed inside the working copy, while they work fine when executed outside.

@achimnol
Copy link
Member

achimnol commented Aug 11, 2024

Um.. we need to support the scenario for developing plugins by cloning the repositories into plugins/ directory. Do you have any better idea to it?

Even if scan_entrypoint_from_plugin_checkouts is removed from the development environment, each plugin's path under the plugins directory is added to PYTHONPATH from ./py, so it operates the same as before.

That is, all plugins under the plugins directory are still recognized as plugins, and we can install and develop plugins in an editable way through the ./scripts/install-plugin.sh script in the development environment.

This is not true.

image

Expected result:

image

@achimnol achimnol force-pushed the 07-04-feat_scanning_entrypoints_from_external_packages branch from 0bd1596 to c396754 Compare August 11, 2024 03:36
@achimnol
Copy link
Member

Okay, I'm going to preserve the plugin-checkout type for debugging purpose (the CLI), while skipping it in the loader mechanism.

* It will be "overriden" by the python-package source.
* Show more detailed guides about the situation.
  - Add a message to let users run `pip install -e` when there is only
    the plugin-checkout source without the python-package source.
  - Add a message to let users check `agent.toml` when the group name
    contains "accelerator".
@achimnol achimnol added this pull request to the merge queue Aug 11, 2024
Merged via the queue into main with commit 3de6b3f Aug 11, 2024
22 checks passed
@achimnol achimnol deleted the 07-04-feat_scanning_entrypoints_from_external_packages branch August 11, 2024 13:05
@jopemachine jopemachine restored the 07-04-feat_scanning_entrypoints_from_external_packages branch August 12, 2024 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:agent Related to Agent component comp:common Related to Common component size:M 30~100 LoC type:feature Add new features type:refactor Refactor codes or add tests. urgency:3 Must be finished within a certain time frame.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Python package loader for the plugin subsystem with scie distributions and local devs
2 participants