setup.py应该放在你的项目的根目录。setup.py中最重要的一部分就是调用setuptools.setup,这里面包含了此包所需的所有元信息。这里就是sandman的setup.py的所有内容
01
|
from __future__ import print_function
|
02
|
from setuptools import setup, find_packages
|
03
|
from setuptools.command.test import test as TestCommand
|
11
|
here = os.path.abspath(os.path.dirname(__file__))
|
13
|
def read(*filenames, **kwargs):
|
14
|
encoding = kwargs.get('encoding', 'utf-8')
|
15
|
sep = kwargs.get('sep', '\n')
|
17
|
for filename in filenames:
|
18
|
with io.open(filename, encoding=encoding) as f:
|
22
|
long_description = read('README.txt', 'CHANGES.txt')
|
24
|
class PyTest(TestCommand):
|
25
|
def finalize_options(self):
|
26
|
TestCommand.finalize_options(self)
|
28
|
self.test_suite = True
|
32
|
errcode = pytest.main(self.test_args)
|
37
|
version=sandman.__version__,
|
38
|
url='http://github.com/jeffknupp/sandman/',
|
39
|
license='Apache Software License',
|
41
|
tests_require=['pytest'],
|
42
|
install_requires=['Flask>=0.10.1',
|
43
|
'Flask-SQLAlchemy>=1.0',
|
46
|
cmdclass={'test': PyTest},
|
47
|
author_email='jeff@jeffknupp.com',
|
48
|
description='Automated REST APIs for existing database-driven systems',
|
49
|
long_description=long_description,
|
51
|
include_package_data=True,
|
53
|
test_suite='sandman.test.test_sandman',
|
55
|
'Programming Language :: Python',
|
56
|
'Development Status :: 4 - Beta',
|
57
|
'Natural Language :: English',
|
58
|
'Environment :: Web Environment',
|
59
|
'Intended Audience :: Developers',
|
60
|
'License :: OSI Approved :: Apache Software License',
|
61
|
'Operating System :: OS Independent',
|
62
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
63
|
'Topic :: Software Development :: Libraries :: Application Frameworks',
|
64
|
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
67
|
'testing': ['pytest'],
|
(感谢Christian Heimes的建议让setup.py更符合人们的语言习惯。反过来,也让我借用其它的项目一目了然了。)
大多数内容浅显易懂,可以从setuptools文档查看到,所以我只会触及"有趣"的部分。使用sandman.__version__和gettinglong_description方法(尽管我也记不住是哪一个,但是却可以从其它项目的setup.py中获得)来减少我们需要写的引用代码。相反,维护项目的版本有三个地方(setup.py, 包自身的__version__, 以及文档),我们也可以使用包的version来填充setup里面的version参数
|
|