无法通过setuptools在egg中包含静态包文件

时间:2011-07-27 18:30:49

标签: python setuptools pyramid

我正在尝试Pyramid教程示例,它内置的setup.py文件出现,用于将静态文件添加到egg文件中,但实际上并没有发生。我已经做了一些搜索和玩弄设置,但我无法得到理想的行为。

  1. 有一个MANIFEST.in文件,它包含一行:include *.ini
  2. include_package_data设置为True
  3. package_data包含条目:{ '' : ['*.ini'] }'
  4. 我改变的设置似乎并不重要,似乎没有效果。我应该提一下SOURCES.txt文件中列出了所需的文件。

    我想要包含的文件位于发行版目录的根目录(setup.py所在的位置)。

    我在这里似乎缺少什么?

2 个答案:

答案 0 :(得分:6)

金字塔的顶级.ini文件是“非包数据文件”,即它们所在的目录中没有__init__.py。这意味着它们将不会包含在使用setup.py bdist_egg生成的egg存档中,即使您的条件1和2已满足。

要包含此类“非包裹数据文件”,我认为最简洁的方法是将它们data_files添加到setup(),例如

setup(
    ...
    data_files=[
        ('', [
            'development.ini',
            'production.ini',
        ]),
    ],
    zip_safe=False,
    ...
)

然后,这些文件将包含在顶级的egg存档中,可通过以下方式检索:

import os
import pkg_resources

dist = pkg_resources.get_distribution('MyApp')
config_file = os.path.join(dist.location, 'production.ini')

答案 1 :(得分:1)

不确定那里发生了什么,但如果我在新建的金字塔脚手架上做“setup.py sdist”,这就是我要去的地方。

创建项目:

[chrism@thinko env26]$ bin/paster create -t pyramid_routesalchemy MyApp
Selected and implied templates:
  pyramid#pyramid_routesalchemy  pyramid SQLAlchemy project using url dispatch (no traversal)

Variables:
  egg:      MyApp
  package:  myapp
  project:  MyApp
Creating template pyramid_routesalchemy
Creating directory ./MyApp
  Recursing into +package+
    Creating ./MyApp/myapp/
    Copying __init__.py_tmpl to ./MyApp/myapp/__init__.py
    Copying models.py to ./MyApp/myapp/models.py
    Recursing into static
      Creating ./MyApp/myapp/static/
      Copying favicon.ico to ./MyApp/myapp/static/favicon.ico
      Copying footerbg.png to ./MyApp/myapp/static/footerbg.png
      Copying headerbg.png to ./MyApp/myapp/static/headerbg.png
      Copying ie6.css to ./MyApp/myapp/static/ie6.css
      Copying middlebg.png to ./MyApp/myapp/static/middlebg.png
      Copying pylons.css to ./MyApp/myapp/static/pylons.css
      Copying pyramid-small.png to ./MyApp/myapp/static/pyramid-small.png
      Copying pyramid.png to ./MyApp/myapp/static/pyramid.png
      Copying transparent.gif to ./MyApp/myapp/static/transparent.gif
    Recursing into templates
      Creating ./MyApp/myapp/templates/
      Copying mytemplate.pt_tmpl to ./MyApp/myapp/templates/mytemplate.pt
    Copying tests.py_tmpl to ./MyApp/myapp/tests.py
    Copying views.py_tmpl to ./MyApp/myapp/views.py
  Copying CHANGES.txt_tmpl to ./MyApp/CHANGES.txt
  Copying MANIFEST.in_tmpl to ./MyApp/MANIFEST.in
  Copying README.txt_tmpl to ./MyApp/README.txt
  Copying development.ini_tmpl to ./MyApp/development.ini
  Copying production.ini_tmpl to ./MyApp/production.ini
  Copying setup.cfg_tmpl to ./MyApp/setup.cfg
  Copying setup.py_tmpl to ./MyApp/setup.py
Welcome to Pyramid.  Sorry for the convenience.
Running /home/chrism/projects/pyramid/env26/bin/python setup.py egg_info

运行sdist:

[chrism@thinko env26]$ cd MyApp/
[chrism@thinko MyApp]$ ../bin/python setup.py sdist
running sdist
running egg_info
writing requirements to MyApp.egg-info/requires.txt
writing MyApp.egg-info/PKG-INFO
writing top-level names to MyApp.egg-info/top_level.txt
writing dependency_links to MyApp.egg-info/dependency_links.txt
writing entry points to MyApp.egg-info/entry_points.txt
writing requirements to MyApp.egg-info/requires.txt
writing MyApp.egg-info/PKG-INFO
writing top-level names to MyApp.egg-info/top_level.txt
writing dependency_links to MyApp.egg-info/dependency_links.txt
writing entry points to MyApp.egg-info/entry_points.txt
writing paster_plugins to MyApp.egg-info/paster_plugins.txt
reading manifest file 'MyApp.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.rst'
warning: no files found matching '*.jpg' under directory 'myapp'
warning: no files found matching '*.txt' under directory 'myapp'
warning: no files found matching '*.mak' under directory 'myapp'
w    arning: no files found matching '*.mako' under directory 'myapp'
warning: no files found matching '*.js' under directory 'myapp'
warning: no files found matching '*.html' under directory 'myapp'
warning: no files found matching '*.xml' under directory 'myapp'
writing manifest file 'MyApp.egg-info/SOURCES.txt'
warning: sdist: missing required meta-data: url
warning: sdist: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied
creating MyApp-0.0
creating MyApp-0.0/MyApp.egg-info
creating MyApp-0.0/myapp
creating MyApp-0.0/myapp/static
creating MyApp-0.0/myapp/templates
making hard links in MyApp-0.0...
hard linking CHANGES.txt -> MyApp-0.0
hard linking MANIFEST.in -> MyApp-0.0
hard linking README.txt -> MyApp-0.0
hard linking development.ini -> MyApp-0.0
hard linking production.ini -> MyApp-0.0
hard linking setup.cfg -> MyApp-0.0
hard linking setup.py -> MyApp-0.0
hard linking MyApp.egg-info/PKG-INFO -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/SOURCES.txt -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/dependency_links.txt -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/entry_points.txt -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/not-zip-safe -> MyApp-0.0/MyApp.egg-info
h    ard linking MyApp.egg-info/paster_plugins.txt -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/requires.txt -> MyApp-0.0/MyApp.egg-info
hard linking MyApp.egg-info/top_level.txt -> MyApp-0.0/MyApp.egg-info
hard linking myapp/__init__.py -> MyApp-0.0/myapp
hard linking myapp/models.py -> MyApp-0.0/myapp
hard linking myapp/tests.py -> MyApp-0.0/myapp
hard linking myapp/views.py -> MyApp-0.0/myapp
hard linking myapp/static/favicon.ico -> MyApp-0.0/myapp/static
hard linking myapp/static/footerbg.png -> MyApp-0.0/myapp/static
hard linking myapp/static/headerbg.png -> MyApp-0.0/myapp/static
hard linking myapp/static/ie6.css -> MyApp-0.0/myapp/static
hard linking myapp/static/middlebg.png -> MyApp-0.0/myapp/static
hard linking myapp/static/pylons.css -> MyApp-0.0/myapp/static
hard linking myapp/static/pyramid-small.png -> MyApp-0.0/myapp/static
hard linking myapp/static/pyramid.png -> MyApp-0.0/myapp/static
hard linking myapp/static/transparent.gif -> MyApp-0.0/myapp/static
hard linking myapp/templates/mytemplate.pt -> MyApp-0.0/myapp/templates
copying setup.cfg -> MyApp-0.0
Writing MyApp-0.0/setup.cfg
creating dist
tar -cf dist/MyApp-0.0.tar MyApp-0.0
gzip -f9 dist/MyApp-0.0.tar
removing 'MyApp-0.0' (and everything under it)

在scaffold中创建的.ini文件将放入生成的tarball中:

[chrism@thinko MyApp]$ tar tvzf dist/MyApp-0.0.tar.gz 
drwxr-xr-x chrism/chrism     0 2011-07-28 16:08 MyApp-0.0/
-rw-r--r-- chrism/chrism  1162 2011-07-28 16:07 MyApp-0.0/setup.py
-rw-r--r-- chrism/chrism    16 2011-07-28 16:07 MyApp-0.0/README.txt
-rw-r--r-- chrism/chrism    28 2011-07-28 16:07 MyApp-0.0/CHANGES.txt
-rw-r--r-- chrism/chrism  1457 2011-07-28 16:07 MyApp-0.0/production.ini
drwxr-xr-x chrism/chrism     0 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/
-rw-r--r-- chrism/chrism     1 2011-07-28 16:07 MyApp-0.0/MyApp.egg-info/not-zip-safe
-rw-r--r-- chrism/chrism   649 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/SOURCES.txt
-rw-r--r-- chrism/chrism     6 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/top_level.txt
-rw-r--r-- chrism/chrism    73 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/requires.txt
-rw-r--r-- chrism/chrism   514 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/PKG-INFO
-rw-r--r-- chrism/chrism     8 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/paster_plugins.txt
-rw-r--r-- chrism/chrism    56 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/entry_points.txt
-rw-r--r-- chrism/chrism     1 2011-07-28 16:08 MyApp-0.0/MyApp.egg-info/dependency_links.txt
-rw-r--r-- chrism/chrism   514 2011-07-28 16:08 MyApp-0.0/PKG-INFO
drwxr-xr-x chrism/chrism     0 2011-07-28 16:08 MyApp-0.0/myapp/
drwxr-xr-x chrism/chrism     0 2011-07-28 16:08 MyApp-0.0/myapp/templates/
-rw-r--r-- chrism/chrism  3446 2011-07-28 16:07 MyApp-0.0/myapp/templates/mytemplate.pt
-rw-r--r-- chrism/chrism   682 2011-07-28 16:07 MyApp-0.0/myapp/tests.py
-rw-r--r-- chrism/chrism   237 2011-07-28 16:07 MyApp-0.0/myapp/views.py
-rw-r--r-- chrism/chrism  1088 2011-07-28 16:07 MyApp-0.0/myapp/models.py
drwxr-xr-x chrism/chrism     0 2011-07-28 16:08 MyApp-0.0/myapp/static/
-rw-r--r-- chrism/chrism   203 2011-07-28 16:07 MyApp-0.0/myapp/static/headerbg.png
-rw-r--r-- chrism/chrism  2797 2011-07-28 16:07 MyApp-0.0/myapp/static/middlebg.png
-rw-r--r-- chrism/chrism    49 2011-07-28 16:07 MyApp-0.0/myapp/static/transparent.gif
-rw-r--r-- chrism/chrism 33055 2011-07-28 16:07 MyApp-0.0/myapp/static/pyramid.png
-rw-r--r-- chrism/chrism  4387 2011-07-28 16:07 MyApp-0.0/myapp/static/pylons.css
-rw-r--r-- chrism/chrism  1406 2011-07-28 16:07 MyApp-0.0/myapp/static/favicon.ico
-rw-r--r-- chrism/chrism  7044 2011-07-28 16:07 MyApp-0.0/myapp/static/pyramid-small.png
-rw-r--r-- chrism/chrism   758 2011-07-28 16:07 MyApp-0.0/myapp/static/ie6.css
-rw-r--r-- chrism/chrism   333 2011-07-28 16:07 MyApp-0.0/myapp/static/footerbg.png
-rw-r--r-- chrism/chrism   616 2011-07-28 16:07 MyApp-0.0/myapp/__init__.py
-rw-r--r-- chrism/chrism   533 2011-07-28 16:08 MyApp-0.0/setup.cfg
-rw-r--r-- chrism/chrism  1123 2011-07-28 16:07 MyApp-0.0/development.ini
-rw-r--r-- chrism/chrism   128 2011-07-28 16:07 MyApp-0.0/MANIFEST.in