Python setup.py - how to include shared library

Viewed 691

New to python packaging (but not python) so please excuse if questions are all over the place.

Trying to package a python module ( project-A ) which uses bunch of common scripts from another directory ( lib).

Hitting a wall on how to include this lib directory in the final package artifact.

The setup.py , working directory structure and how i plan the final package installation structure are shown below .

Few more questions -

  • The relative location of lib changes between my work-directory and installed package . Is there a way to import in both cases without changing the code ?
  • Is this structure better or should i move everything related to project_A under its own directory , that way each project will have its own setup.py, MANIFEST, conf directory, etc.. ( location of lib would remain the same, not sure if each package should have its own tests directory )
  • release=subprocess.check_output fails if someone runs this outside a git repo. Is there a way to add a default value in such cases ?
  • An example i came across had lib moved to /usr/lib/python3.4/site-packages/project_A/_lib . Liked this approach. any idea how to achieve this in setup.py

setup.py ( currently creates two packages )

setup(
    name='project_A',
    version='0.15',
    # release is not supported in bdist rpm
    #release=subprocess.check_output(["git", "rev-list", "--count", "--first-parent", "HEAD"]).rstrip(),
    # if creating outside git
    release="0.0.1",
    author='foo',
    author_email='hello@world.com',
    url='http://www.hello.com',
    long_description="README.txt",
    #install_requires=['bottle','requests','supervisor'],  # currently not working
    #dependency_links = ['https://pypi.python.org/packages/source/b/bottle/bottle-0.12.8.tar.gz'],
    packages=['project_A'],
    include_package_data=True,
    package_data={'images' : ['hello.gif']},
    data_files=[
                #('/etc/init.d/', ['project_Actl']),  # some startup script
                ('/var/log/project_A',[]),
                ('/etc/project_A/conf/',['conf/project_A.conf'])
                ],
    description="Hello World testing setuptools",
    tests_require=['pytest'],
    cmdclass = {
                'test': PyTest,
                'clean': CleanCommand
                }

)

Project-A installation directory -

/usr/lib/python3.4/site-packages/project_A
|
|____project_A/
| |
| |____project_A.py
|
|____lib
| | 
| |______init__.py
| |____parseArguments.py
| |____setupLogger.py
| |____cleanup.py


Python workspace directory -

. 
|____setup.py
|
|____MANIFEST.in
|
|____README.md
|
|____project_A/
| |
| |____project_A.py
|
|____project_B/
| |
| |____project_B.py
|
|____conf/
| |
| |____project_A.conf
| |____project_B.conf
|
|____lib
| | 
| |______init__.py
| |____parseArguments.py
| |____setupLogger.py
| |____cleanup.py
|
|
|____images/
| |____hello.gif
|
|____tests
| |
| |____project_A
| | |____test_B_example.py
|
| |____project_B
| | |____test_A_example.py
0 Answers
Related