1#!/usr/bin/env python3 2import codecs 3from glob import glob 4import os 5from os.path import join 6import re 7 8from setuptools import setup, find_packages 9 10# setup.py should not import non-stdlib modules, other than setuptools, at 11# module level, since this requires them to be installed to run any setup.py 12# command. (e.g. 'setup.py install' should not require installing py2exe.) 13 14# setup.py should not import from our local source (pip needs to be able to 15# import setup.py before our dependencies have been installed) 16 17NAME = 'cbeams' 18 19def read_file(filename): 20 with codecs.open(filename, 'r', 'utf-8') as fp: 21 return fp.read() 22 23def read_description(filename): 24 ''' 25 Read given textfile and return (2nd_para, 3rd_para to end) 26 ''' 27 text = read_file(filename) 28 paras = text.split('\n\n') 29 description = paras[1].replace('\n', ' ') 30 long_description = '\n\n'.join(paras[2:]) 31 return description, long_description 32 33def find_value(source, identifier): 34 ''' 35 Manually parse the given source, looking for lines of the form: 36 <identifier> = '<value>' 37 Returns the value. We do this rather than import the file directly because 38 its dependencies will not be present when setuptools runs this setup.py 39 before installing our dependencies, to find out what they are. 40 ''' 41 regex = r"^%s\s*=\s*['\"]([^'\"]*)['\"]$" % (identifier,) 42 match = re.search(regex, source, re.M) 43 if not match: 44 raise RuntimeError( 45 "Can't find '%s' in source:\n%s" % (identifier, source) 46 ) 47 return match.group(1) 48 49def get_version(): 50 return find_value(read_file(join(NAME, '__init__.py')), '__version__') 51 52def get_package_data(topdir, excluded=frozenset()): 53 retval = [] 54 for dirname, subdirs, _ in os.walk(join(NAME, topdir)): 55 for subdir in excluded: 56 if subdir in subdirs: 57 subdirs.remove(subdir) 58 retval.append(join(dirname[len(NAME) + 1:], '*.*')) 59 return retval 60 61def get_data_files(dest, source): 62 retval = [] 63 for dirname, _, __ in os.walk(source): 64 retval.append( 65 (join(dest, dirname[len(source)+1:]), glob(join(dirname, '*.*'))) 66 ) 67 return retval 68 69def get_sdist_config(): 70 description, long_description = read_description('README.md') 71 return dict( 72 name=NAME, 73 version=get_version(), 74 description=description, 75 #description_content_type="text/markdown", 76 long_description=long_description, 77 long_description_content_type="text/markdown", 78 url='http://pypi.python.org/pypi/%s/' % (NAME,), 79 author='Jonathan Hartley', 80 author_email='tartley@tartley.com', 81 keywords='console blessings ansi terminal animation', 82 entry_points={ 83 'console_scripts': ['{0}={0}.__main__:main'.format(NAME)], 84 'gui_scripts': [], 85 }, 86 # Application dependencies, pinned: 87 install_requires=[ 88 'docopt>=0.6.1', 89 'blessings>=1.6', 90 ], 91 packages=find_packages(exclude=['*.tests']), 92 #include_package_data=True, 93 #package_data={ 94 #'package.subpackage': ['globs'], 95 #NAME: get_package_data('data') 96 #}, 97 #exclude_package_data={ 98 #'package.subpackage': ['globs'] 99 #}, 100 #data_files=[ 101 # ('install-dir', ['files-relative-to-setup.py']), 102 #], 103 # see classifiers: 104 # http://pypi.python.org/pypi?:action=list_classifiers 105 classifiers=[ 106 #'Development Status :: 1 - Planning', 107 #'Development Status :: 2 - Pre-Alpha', 108 #'Development Status :: 3 - Alpha', 109 'Development Status :: 4 - Beta', 110 #'Development Status :: 5 - Production/Stable', 111 #'Development Status :: 6 - Mature', 112 #'Development Status :: 7 - Inactive', 113 'Environment :: Console', 114 #'Environment :: MacOS X', 115 #'Environment :: No Input/Output (Daemon)', 116 #'Environment :: Web Environment', 117 #'Environment :: Win32 (MS Windows)', 118 #'Environment :: X11 Applications', 119 'Intended Audience :: Developers', 120 #'Intended Audience :: End Users/Desktop', 121 'License :: OSI Approved :: BSD License', 122 'Natural Language :: English', 123 #'Operating System :: Microsoft :: Windows :: Windows 7', 124 #'Operating System :: MacOS :: MacOS X', 125 'Operating System :: POSIX :: Linux', 126 'Operating System :: OS Independent', 127 'Programming Language :: Python :: 3', 128 'Programming Language :: Python :: 3.4', 129 'Programming Language :: Python :: 3.5', 130 'Programming Language :: Python :: Implementation :: CPython', 131 'Topic :: Games/Entertainment', 132 ], 133 zip_safe=True, 134 ) 135 136 137def main(): 138 setup(**get_sdist_config()) 139 140 141if __name__ == '__main__': 142 main() 143 144