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

Switch Python 3 native namespace packages for plugins #534

Closed
omry opened this issue Apr 15, 2020 · 2 comments · Fixed by #535
Closed

Switch Python 3 native namespace packages for plugins #534

omry opened this issue Apr 15, 2020 · 2 comments · Fixed by #535
Milestone

Comments

@omry
Copy link
Collaborator

omry commented Apr 15, 2020

Python 3 namespace packages

The following changes are required from plugins to be compliant with Hydra 1.0:

Hydra 0.11 used pkg_resource style packages for plugins, because they are backward compatible with Python 2.7.
Now that Hydra no longer supports Python 2.7, we can move to native namespace packages.

Doing it is quiet simple, but it's important that all plugins are going doing it, otherwise they might interfere with other plugins.

Remove hydra_plugins/__init__.py:

Previously, plugins had an hydra_plugins/__init__.py file that looked like:

# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved                                                                                                                   
# type: ignore                                                                                                                                                                           
__path__ = __import__("pkgutil").extend_path(__path__, __name__)  

Remove it.

Update your setup.py to properly package your plugin

Previously setup.py has something like:

packages=find_packages(exclude=["tests", "example"]),

Without hydra_plugins/__init__.py, setuptools find_packages() will fail to pick up your plugin package, change it to (and of course the import of find_packages to find_namespace_packages too)

packages=find_namespace_packages(include=["hydra_plugins.*"])

If you have any other packages you are including with, you can combine find_namespace_packages() with find_package():

packages=find_packages(include=["coolstuff.*"]) + find_namespace_packages(include=["hydra_plugins.*"])
@omry omry added this to the 1.0.0 milestone Apr 15, 2020
@omry omry mentioned this issue Apr 15, 2020
@omry omry closed this as completed in #535 Apr 15, 2020
@mannatsingh
Copy link

For users still wanting to use find_packages for their regular packages, the change would involve concatenating the results from both find_packages and find_namespace_packages.

packages=find_packages(exclude=["tests", "example"]),

becomes

packages=find_packages(exclude=["tests", "example"]) + find_namespace_packages(include=["hydra_plugins.*"]),

@omry
Copy link
Collaborator Author

omry commented Jun 7, 2020

Thanks @mannatsingh, I updated the issue description to cover this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants