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 testasTestCommand
|
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 | withio. open (filename,encoding = encoding)asf: |
22 | long_description =
read( 'README.txt' , 'CHANGES.txt' ) |
24 | class PyTest(TestCommand):
|
25 | def
finalize_options( self ): |
26 | TestCommand.finalize_options( self ) |
32 | errcode = pytest.main( self .test_args) |
37 | version = sandman.__version__, |
38 | url = 'http://github.com/jeffknupp/sandman/' , |
39 | license = 'ApacheSoftwareLicense' , |
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 = 'AutomatedRESTAPIsforexistingdatabase-drivensystems' , |
49 | long_description = long_description, |
51 | include_package_data = True , |
53 | test_suite = 'sandman.test.test_sandman' , |
55 | 'ProgrammingLanguage::Python' , |
56 | 'DevelopmentStatus::4-Beta' , |
57 | 'NaturalLanguage::English' , |
58 | 'Environment::WebEnvironment' , |
59 | 'IntendedAudience::Developers' , |
60 | 'License::OSIApproved::ApacheSoftwareLicense' , |
61 | 'OperatingSystem::OSIndependent' , |
62 | 'Topic::SoftwareDevelopment::Libraries::PythonModules' , |
63 | 'Topic::SoftwareDevelopment::Libraries::ApplicationFrameworks' , |
64 | 'Topic::Internet::WWW/HTTP::DynamicContent' , | (感谢ChristianHeimes的建议让setup.py更符合人们的语言习惯。反过来,也让我借用其它的项目一目了然了。)大多数内容浅显易懂,可以从setuptools文档查看到,所以我只会触及"有趣"的部分。使用sandman.__version__和gettinglong_description方法(尽管我也记不住是哪一个,但是却可以从其它项目的setup.py中获得)来减少我们需要写的引用代码。相反,维护项目的版本有三个地方(setup.py,包自身的__version__,以及文档),我们也可以使用包的version来填充setup里面的version参数
| |