简体   繁体   English

如何为这个应用程序结构编写setup.py?

[英]how to write setup.py for this application structure?

I have written an application with python (2.7). 我用python(2.7)编写了一个应用程序。 The structure looks like: 结构如下:

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 am about to write a setup.py to distribute my application. 现在我要编写一个setup.py来分发我的应用程序。 I am new to this. 我是新来的。 After reading the py doc and doing some testing. 阅读py文档并做一些测试后。 a few questions come up: 提出几个问题:

  1. how can I (or should I) package my root package (myApp) under /lib/python/site-package ? 我怎么能(或应该)在/lib/python/site-package下打包我的root包(myApp)?

    since in my py file, I reference resources/icons by relative path. 因为在我的py文件中,我通过相对路径引用资源/图标。 for example, in foo.py there could be icons/a.png and in gui/g1.py there could be ../icons/e.png and so on 例如,在foo.py中可能有icons/a.png ,在gui/g1.py中可能有../icons/e.png等等

  2. how can I package icons and resources directory? 我该如何打包iconsresources目录?

    It seems that package_data and data_files won't copy the two directories to right place. 似乎package_datadata_files不会data_files两个目录复制到正确的位置。

  3. is this the right way? 这是正确的方法吗?

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

    after install, 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/... 
  4. Is there problem of my application structure? 我的申请结构有问题吗?

    should those resources/icons/whatever files go to certain python package, not under the project root? 那些资源/图标/任何文件应该转到某个python包,而不是项目根目录下? so that in setup.py I can use package_data to copy them to right place. 所以在setup.py中我可以使用package_data将它们复制到正确的位置。

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'])
      ]
      )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM