Python 2.7 package install with multiple modules and packaged namespaces

荒凉一梦 提交于 2020-01-16 10:31:49

问题


I want to keep multiple python modules in the same repo so it's easier to manage them, and work on them simultaneously.

The modules are packaged namespace packages, so I can't have the roots at the same level, and there are 4 of them, and might be more later.

Here's the structure I have:

repo/
  modules/
    foo_a/
      setup.py
      VERSION
      foo/
        __init__.py
        a/
    foo_b/
      setup.py
      VERSION
      foo/
        __init__.py
        b/

The VERSION files are separate and track different versions. And the __init__.py files above are the special type described here.

Currently I automatically build the respective module when the VERSION file in it changes.


What I want is to be able to install the entire package with all namespace packages from the root of the repo. So I can just do pip install .. Either this would install everything as a single package (foo_all) or individually install each module.

The usecase for this, is that most people use all modules and they want something easy to install, but sometimes I just want to be able to install one of the modules.

The key thing is that you can run:

pip install repo

and then these Python commands succeed.

from foo import a
from foo import b

Any ideas on how to do this?

I've seen the setuptools.find_namespace_packages() function, but that looks like it's only Python3, and I'm not entirely sure it's what I need anyway. I can't upgrade to Python3 because it's for a client and it's dependent on a Python2 API, which is incredibly frustrating.

Also seen the package_dir option for setuptools.setup(), but that's for if all the packages are just in a different folder. I can't put all the package in a different folder because the individual files would overlap (setup.py, VERSION, foo/)


回答1:


Probably distribute foo.a and foo.b as independent projects alongside a empty foo project that has the other two as install_requires.

The whole setup is described in the Python Packaging User Guide on "Packaging namespace packages".



来源:https://stackoverflow.com/questions/58016376/python-2-7-package-install-with-multiple-modules-and-packaged-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!