How to write setup.py for this application structure?

I wrote an application with python (2.7). The structure looks like this:

kent$ tree myApp myApp |-- foo.py |-- gui | |-- g1.py | |-- g2.py | |-- g3.py | `-- __init__.py |-- icons | |-- a.png | `-- e.png |-- logic | |-- __init__.py | |-- l1 | | |-- __init__.py | | |-- la.py | | `-- lc.py | |-- l2 | | |-- __init__.py | | |-- ld.py | | `-- lf.py | |-- logic1.py | |-- logic2.py | `-- logic3.py |-- myApp.py `-- resources |-- x.data `-- z.data 

Now I'm going to write setup.py to distribute my application. I am new to this. After reading the py document and doing some testing. several questions arise:

  • How can I (or should I) pack my root package (myApp) under /lib/python/site-package ?

    since in my py file I am referring to resources / icons by relative path. for example, in foo.py can be icons/a.png , and in gui/g1.py can be ../icons/e.png , etc.

  • How can I pack the icons and resources directory?

    It seems that package_data and data_files will not copy these two directories to the right place.

  • Is it correct?

     packages = [''], package_dir = {'': ''}, package_data= {'': ['icons/*.*', 'resources/*.*']}, 

    after installation, my files will be:

     /usr/lib/python2.7/site-packages/icons/*.png /usr/lib/python2.7/site-packages/resources/*.data /usr/lib/python2.7/site-packages/gui/... /usr/lib/python2.7/site-packages/logic/... 
  • Is there a problem in my application structure?

    should these resources / icons / any files go to a specific python package and not to the project root? so in setup.py I can use package_data to copy them to the right place.

+6
source share
1 answer
 from ez_setup import use_setuptools use_setuptools() from setuptools import setup setup(name="somename", version="1.0", description="description string", long_description="""\ long description """, author="Foo", author_email=" bar@gmail.com ", url="http://nowhere.com", include_package_data=True, license="MIT", packages=["gui", "logic"], package_dir={ "gui": "myApp/gui", "logic": "myApp/logic", }, classifiers=[ "Development Status :: 5 - Production/Stable", "Topic :: Utilities", "License :: OSI Approved :: MIT License" ], data_files=[ ('/path/to/resources', ['resources/x.data', 'resources/y.data']), ('/path/to/icons', ['myApp/icons/a.ico', 'myApp/icons/e.ico']) ] ) 
+1
source

All Articles