I'm looking to package and upload a library I have to PyPI in the next few days, but I'm a little unsure about my approach to the namespace.
I have a few otherwise unrelated projects with a similar approach and wanted to give them all the same namespace. For example:
abc.seo
abc.ajax
abc.ecommerce
The problem is that I'm not sure if it's possible for two separate packages (eg eggs) to co-exist with the same parent namespace. Is this approach problematic, or is there a way around it? What's the best approach?
The libraries should not be packaged together, they are too unrelated. I would like to get it right before uploading so as to avoid painful namespace changes after making an "official" release.
(NB abc
is not the real name, I wanted my question to be free from advertising)
UPDATE
I went with the following, to be nice to the people without setuptools installed:
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
With the following in setup.py
:
setup(
...
namespace_packages = ['rollyourown'],
...
In Python, a namespace package allows you to spread Python code among several projects. This is useful when you want to release related libraries as separate downloads.
Follow the below steps to create a package in PythonCreate a directory and include a __init__.py file in it to tell Python that the current directory is a package. Include other sub-packages or files you want. Next, access them with the valid import statements.
In the __init__.py file of a package __all__ is a list of strings with the names of public modules or other objects. Those features are available to wildcard imports. As with modules, __all__ customizes the * when wildcard-importing from the package.
In each project base directory, create the following structure:
/setup.py
/abc/__init__.py
/abc/seo/
/abc/__init__.py
contains :
__import__('pkg_resources').declare_namespace(__name__)
setup.py
contains :
setup(...,
packages: ['abc', 'abc.seo'],
namespace_packages = ['abc']
...
)
Reference documentation: namespace packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With