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