setuptools - How to create a nested package space for python packages? -


i'm restructuring python libraries our company developing various groups. avoid polluting top level module namespace i'd group under top level 'companyname' package, we'll have 'coname.utils', 'coname.qa', 'coname.api', , on. several of these expected distributed our product, or publicly installable. 'qa' purely internal.

google similar. e.g., protobuf library available "google.protobuf" in module path. however, it's not particularly clean: .pth file installed protobuf package looks this:

import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie , sys.modules.setdefault('google', types.moduletype('google'));mp = (m or []) , m.__dict__.setdefault('__path__',[]);(p not in mp) , mp.append(p) 

i think fool import engine because there's no __init__.py in "google" directory. but... not elegant.

is there established way of achieving this? don't mind making of "coname-*" packages require "coname-top" package __init__.py in there. i'm as-yet unsure how convince setuptools treat package not @ top of module tree, nor if it's possible create sub-packages 1 tree.

to clarify, i'm asking how set above coname-qa can distributed , installed separately coname-api, example. reasonable both depend on coname-tools.

  1. the directory needs package. add init.py file make package, step being simple directory.

  2. the directory b needs subpackage of a. add init.py file.

  3. the directory test should package. hard if necessary or not. it's idea every directory of python modules formal package.

  4. in order import, package needs on sys.path; built pythonpath environment variable. default installed site-packages , current working directory (effectively) 2 places package can found.

that means must either installed, or, current working directory must package 1 level above a.

or, need set pythonpath environment variable include a.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -