1import codecs 2import os 3import shutil 4import sys 5import warnings 6 7import setuptools 8from setuptools import setup, Command 9from setuptools.command.egg_info import egg_info 10 11 12PACKAGE_NAME = 'asn1crypto' 13PACKAGE_VERSION = '1.4.0' 14TEST_PACKAGE_NAME = '%s_tests' % PACKAGE_NAME 15TESTS_ROOT = os.path.dirname(os.path.abspath(__file__)) 16 17 18# setuptools 38.6.0 and newer know about long_description_content_type, but 19# distutils still complains about it, so silence the warning 20sv = setuptools.__version__ 21svi = tuple(int(o) if o.isdigit() else o for o in sv.split('.')) 22if svi >= (38, 6): 23 warnings.filterwarnings( 24 'ignore', 25 "Unknown distribution option: 'long_description_content_type'", 26 module='distutils.dist' 27 ) 28 29 30# Older versions of distutils would take a glob pattern and return dirs 31# and then would complain that it couldn't copy a dir like a file, so we 32# have to build an explicit list of file names 33data_files = [] 34fixtures_dir = os.path.join(TESTS_ROOT, 'fixtures') 35for root, dirs, files in os.walk(fixtures_dir): 36 for filename in files: 37 data_files.append(os.path.join(root, filename)[len(TESTS_ROOT) + 1:]) 38package_data = { 39 TEST_PACKAGE_NAME: data_files 40} 41# This allows us to send the LICENSE when creating a sdist. Wheels 42# automatically include the license, and don't need the docs. For these 43# to be included, the command must be "python setup.py sdist". 44if sys.argv[1:] == ['sdist'] or sorted(sys.argv[1:]) == ['-q', 'sdist']: 45 package_data[TEST_PACKAGE_NAME].extend([ 46 'LICENSE', 47 'readme.md', 48 ]) 49 50 51# Ensures a copy of the LICENSE is included with the egg-info for 52# install and bdist_egg commands 53class EggInfoCommand(egg_info): 54 def run(self): 55 egg_info_path = os.path.join( 56 TESTS_ROOT, 57 '%s.egg-info' % TEST_PACKAGE_NAME 58 ) 59 if not os.path.exists(egg_info_path): 60 os.mkdir(egg_info_path) 61 shutil.copy2( 62 os.path.join(TESTS_ROOT, 'LICENSE'), 63 os.path.join(egg_info_path, 'LICENSE') 64 ) 65 egg_info.run(self) 66 67 68class CleanCommand(Command): 69 user_options = [ 70 ('all', 'a', '(Compatibility with original clean command)'), 71 ] 72 73 def initialize_options(self): 74 self.all = False 75 76 def finalize_options(self): 77 pass 78 79 def run(self): 80 sub_folders = ['build', 'temp', '%s.egg-info' % TEST_PACKAGE_NAME] 81 if self.all: 82 sub_folders.append('dist') 83 for sub_folder in sub_folders: 84 full_path = os.path.join(TESTS_ROOT, sub_folder) 85 if os.path.exists(full_path): 86 shutil.rmtree(full_path) 87 for root, dirs, files in os.walk(TESTS_ROOT): 88 for filename in files: 89 if filename[-4:] == '.pyc': 90 os.unlink(os.path.join(root, filename)) 91 for dirname in list(dirs): 92 if dirname == '__pycache__': 93 shutil.rmtree(os.path.join(root, dirname)) 94 95 96readme = '' 97with codecs.open(os.path.join(TESTS_ROOT, 'readme.md'), 'r', 'utf-8') as f: 98 readme = f.read() 99 100 101setup( 102 name=TEST_PACKAGE_NAME, 103 version=PACKAGE_VERSION, 104 105 description=( 106 'Test suite for asn1crypto, separated due to file size' 107 ), 108 long_description=readme, 109 long_description_content_type='text/markdown', 110 111 url='https://github.com/wbond/asn1crypto', 112 113 author='wbond', 114 author_email='[email protected]', 115 116 license='MIT', 117 118 classifiers=[ 119 'Development Status :: 5 - Production/Stable', 120 121 'Intended Audience :: Developers', 122 123 'License :: OSI Approved :: MIT License', 124 125 'Programming Language :: Python', 126 'Programming Language :: Python :: 2', 127 'Programming Language :: Python :: 2.6', 128 'Programming Language :: Python :: 2.7', 129 'Programming Language :: Python :: 3', 130 'Programming Language :: Python :: 3.2', 131 'Programming Language :: Python :: 3.3', 132 'Programming Language :: Python :: 3.4', 133 'Programming Language :: Python :: 3.5', 134 'Programming Language :: Python :: 3.6', 135 'Programming Language :: Python :: 3.7', 136 'Programming Language :: Python :: 3.8', 137 'Programming Language :: Python :: Implementation :: CPython', 138 'Programming Language :: Python :: Implementation :: PyPy', 139 140 'Topic :: Security :: Cryptography', 141 ], 142 143 keywords='asn1 crypto pki x509 certificate rsa dsa ec dh', 144 packages=[TEST_PACKAGE_NAME], 145 package_dir={TEST_PACKAGE_NAME: '.'}, 146 package_data=package_data, 147 148 install_requires=[ 149 '%s==%s' % (PACKAGE_NAME, PACKAGE_VERSION), 150 ], 151 152 cmdclass={ 153 'clean': CleanCommand, 154 'egg_info': EggInfoCommand, 155 } 156) 157