Search code examples
pythondistutils

Can't get distutils working


I've written a Python script that uses a package that I've created. I need to package it, so I can install it on several servers, but I can't get setup.py to find my scripts.

There's two parts to my script: connections.py and a module that is imported as X.utils.printing (where X is my group name). I need to bundle both with distutils.

I've read the Python Distutils documentation about five times, and I just don't get it.

Here's what I need to do: 1) Make sure that my printing module is installed and can be imported with

from X.utils.printing import PrettyPrint as PP

2) Put connections.py in /usr/sbin/

This should be very straightforward, but it's become maddening.

Here's my current setup.py that doesn't work:

from distutils.core import setup

setup(name='connections', version='0.1.1', 
      description='Print number of IHS connections',    
      author='fandingo', author_email='fandingo@fandingo.com', 
      package_dir = {'X.utils' : 'X'}, 
      packages=['X.utils.printing'], py_modules=['printing', 'connections'])

setup.py resides and is run from a directory called 'python' and has connection-stats/ and X inside. connection-stats has connections.py inside. X has init.py, utils/init.py, and utils/printing.py.

When I try to run setup.py, I get the following output:

python setup.py bdist

running bdist running bdist_dumb

running build running build_py file

printing.py (for module printing) not

found file connections.py (for module

connections) not found error: package

directory 'X/printing' does not exist

Could someone help me fix my setup.py, so I can package my script and module?

Thanks for all the help.

Edit: I haven't made any attempt to copy connections.py to /usr/sbin/. I haven't gotten beyond distutils not finding my modules.


Edit 2: I think that I'm getting much closer, but I can't get my package hierarchy to work.

Using,

setup(name='connections', version='0.1.1', description='Print number of IHS connections',
      author='fandingo', author_email='fandingo@fanding.com',
      package_dir = {'printing' : 'X/utils'}, packages=['printing'], 
      scripts=['connection-stats/connections.py'])

I get a successful build that has connections.py in what should become /usr/sbin/ when an installation is performed. The only problem is that printing gets imported without the X.utils.printing.

I can change it to include X, but it doesn't include child packages.

setup(name='connections', version='0.1.1', 
      description='Print number of IHS connections', 
      author='fandingo', 
      author_email='fandingo@fandingo.com', 
      packages=['X'],
      scripts=['connection-stats/connections.py'])

The problem here is that X is imported, but only the init.py. utils/ isn't included, which means I don't get utils/printing.py

It's like I need some sort of recursive option, so I can add X and everything below it. Any thoughts?

Thanks,

----------------------

Edit 3:

Just about completed. I figured out that I need to explicitly list every sub-package in X. Here's the corrected setup.py

setup(
    name='connections',
    version='0.1.1',
    description='Print number of IHS connections',
    author='fandingo',
    author_email='fandingo@fandingo.com',
    package_dir = {'utils' : 'X/', 'printing' : 'X/utils/'},
    packages=['X', 'X.utils'],
    py_modules = ['printing'],
    scripts=['connection-stats/connections.py'])

The only other thing is that connections.py isn't moved to /usr/sbin/. I think that I will just add a post-install option to manually move it.


Solution

  • I think you'll want something like the following:

    from distutils.core import setup
    
    setup(name='connections',
          version='0.1.1',
          description='Print number of IHS connections',
          author='fandingo',
          author_email='fandingo@fandingo.com',
          packages=['X'],
          scripts=['connection-stats/connections.py'])
    

    UPDATE: fix packages list