blob: ce6f2e2f68ef6c3e55017c9511d42393fa348639 [file] [log] [blame]
wbondbba5d622019-09-09 01:53:00 -04001import codecs
wbond55908ac2015-07-17 16:24:30 -04002import os
3import shutil
wbondbba5d622019-09-09 01:53:00 -04004import sys
5import warnings
wbond55908ac2015-07-17 16:24:30 -04006
wbondbba5d622019-09-09 01:53:00 -04007import setuptools
8from setuptools import setup, Command
9from setuptools.command.egg_info import egg_info
wbond55908ac2015-07-17 16:24:30 -040010
wbondbba5d622019-09-09 01:53:00 -040011
12PACKAGE_NAME = 'asn1crypto'
wbondc09b87c2020-01-04 09:06:42 -050013PACKAGE_VERSION = '1.3.0'
wbondbba5d622019-09-09 01:53:00 -040014PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__))
15
16
17# setuptools 38.6.0 and newer know about long_description_content_type, but
18# distutils still complains about it, so silence the warning
19sv = setuptools.__version__
20svi = tuple(int(o) if o.isdigit() else o for o in sv.split('.'))
21if svi >= (38, 6):
22 warnings.filterwarnings(
23 'ignore',
24 "Unknown distribution option: 'long_description_content_type'",
25 module='distutils.dist'
26 )
27
28
29# Try to load the tests first from the source repository layout. If that
30# doesn't work, we assume this file is in the release package, and the tests
31# are part of the package {PACKAGE_NAME}_tests.
32if os.path.exists(os.path.join(PACKAGE_ROOT, 'tests')):
33 tests_require = []
34 test_suite = 'tests.make_suite'
35else:
36 tests_require = ['%s_tests' % PACKAGE_NAME]
37 test_suite = '%s_tests.make_suite' % PACKAGE_NAME
38
39
40# This allows us to send the LICENSE and docs when creating a sdist. Wheels
41# automatically include the LICENSE, and don't need the docs. For these
42# to be included, the command must be "python setup.py sdist".
43package_data = {}
44if sys.argv[1:] == ['sdist'] or sorted(sys.argv[1:]) == ['-q', 'sdist']:
45 package_data[PACKAGE_NAME] = [
46 '../LICENSE',
47 '../*.md',
48 '../docs/*.md',
49 ]
50
51
52# Ensures a copy of the LICENSE is included with the egg-info for
53# install and bdist_egg commands
54class EggInfoCommand(egg_info):
55 def run(self):
56 egg_info_path = os.path.join(
57 PACKAGE_ROOT,
58 '%s.egg-info' % PACKAGE_NAME
59 )
60 if not os.path.exists(egg_info_path):
61 os.mkdir(egg_info_path)
62 shutil.copy2(
63 os.path.join(PACKAGE_ROOT, 'LICENSE'),
64 os.path.join(egg_info_path, 'LICENSE')
65 )
66 egg_info.run(self)
wbondb9b75972015-06-15 09:09:17 -040067
68
wbond55908ac2015-07-17 16:24:30 -040069class CleanCommand(Command):
wbond13df68b2016-06-16 05:50:48 -040070 user_options = [
wbondec51ff42017-03-10 14:23:54 -050071 ('all', 'a', '(Compatibility with original clean command)'),
wbond13df68b2016-06-16 05:50:48 -040072 ]
wbond55908ac2015-07-17 16:24:30 -040073
74 def initialize_options(self):
wbond13df68b2016-06-16 05:50:48 -040075 self.all = False
wbond55908ac2015-07-17 16:24:30 -040076
77 def finalize_options(self):
78 pass
79
80 def run(self):
wbondbba5d622019-09-09 01:53:00 -040081 sub_folders = ['build', 'temp', '%s.egg-info' % PACKAGE_NAME]
82 if self.all:
83 sub_folders.append('dist')
84 for sub_folder in sub_folders:
85 full_path = os.path.join(PACKAGE_ROOT, sub_folder)
wbond55908ac2015-07-17 16:24:30 -040086 if os.path.exists(full_path):
87 shutil.rmtree(full_path)
wbondbba5d622019-09-09 01:53:00 -040088 for root, dirs, files in os.walk(os.path.join(PACKAGE_ROOT, PACKAGE_NAME)):
89 for filename in files:
wbondb86376f2015-07-30 11:53:55 -040090 if filename[-4:] == '.pyc':
91 os.unlink(os.path.join(root, filename))
wbondbba5d622019-09-09 01:53:00 -040092 for dirname in list(dirs):
wbondb86376f2015-07-30 11:53:55 -040093 if dirname == '__pycache__':
94 shutil.rmtree(os.path.join(root, dirname))
wbond55908ac2015-07-17 16:24:30 -040095
96
wbondbba5d622019-09-09 01:53:00 -040097readme = ''
98with codecs.open(os.path.join(PACKAGE_ROOT, 'readme.md'), 'r', 'utf-8') as f:
99 readme = f.read()
100
101
wbondb9b75972015-06-15 09:09:17 -0400102setup(
wbondbba5d622019-09-09 01:53:00 -0400103 name=PACKAGE_NAME,
104 version=PACKAGE_VERSION,
wbondb9b75972015-06-15 09:09:17 -0400105
wbond3a487a42015-10-07 12:08:07 -0400106 description=(
wbond50f78762016-03-17 11:49:22 -0400107 'Fast ASN.1 parser and serializer with definitions for private keys, '
108 'public keys, certificates, CRL, OCSP, CMS, PKCS#3, PKCS#7, PKCS#8, '
109 'PKCS#12, PKCS#5, X.509 and TSP'
wbond3a487a42015-10-07 12:08:07 -0400110 ),
wbondbba5d622019-09-09 01:53:00 -0400111 long_description=readme,
112 long_description_content_type='text/markdown',
wbondb9b75972015-06-15 09:09:17 -0400113
114 url='https://github.com/wbond/asn1crypto',
115
116 author='wbond',
117 author_email='will@wbond.net',
118
119 license='MIT',
120
121 classifiers=[
wbondfcbba292019-10-02 21:00:46 -0400122 'Development Status :: 5 - Production/Stable',
wbondb9b75972015-06-15 09:09:17 -0400123
124 'Intended Audience :: Developers',
125
126 'License :: OSI Approved :: MIT License',
127
Jon Dufresnef1f85d62018-09-18 05:54:33 -0700128 'Programming Language :: Python',
129 'Programming Language :: Python :: 2',
wbond3f4a61c2015-08-24 10:45:00 -0400130 'Programming Language :: Python :: 2.6',
wbondb9b75972015-06-15 09:09:17 -0400131 'Programming Language :: Python :: 2.7',
Jon Dufresnef1f85d62018-09-18 05:54:33 -0700132 'Programming Language :: Python :: 3',
wbondbc3f0f62015-10-20 01:07:32 -0400133 'Programming Language :: Python :: 3.2',
wbondb9b75972015-06-15 09:09:17 -0400134 'Programming Language :: Python :: 3.3',
135 'Programming Language :: Python :: 3.4',
wbondbc3f0f62015-10-20 01:07:32 -0400136 'Programming Language :: Python :: 3.5',
wbond9712e072017-01-17 06:56:15 -0500137 'Programming Language :: Python :: 3.6',
wbonde5779a42019-07-04 06:39:13 -0400138 'Programming Language :: Python :: 3.7',
wbondfcbba292019-10-02 21:00:46 -0400139 'Programming Language :: Python :: 3.8',
Jon Dufresnef1f85d62018-09-18 05:54:33 -0700140 'Programming Language :: Python :: Implementation :: CPython',
wbondbc3f0f62015-10-20 01:07:32 -0400141 'Programming Language :: Python :: Implementation :: PyPy',
142
143 'Topic :: Security :: Cryptography',
wbondb9b75972015-06-15 09:09:17 -0400144 ],
145
wbond50f78762016-03-17 11:49:22 -0400146 keywords='asn1 crypto pki x509 certificate rsa dsa ec dh',
wbondb9b75972015-06-15 09:09:17 -0400147
wbondbba5d622019-09-09 01:53:00 -0400148 packages=[PACKAGE_NAME],
149 package_data=package_data,
wbond55908ac2015-07-17 16:24:30 -0400150
wbondbba5d622019-09-09 01:53:00 -0400151 tests_require=tests_require,
152 test_suite=test_suite,
wbondd7a440c2016-03-31 05:19:12 -0400153
wbond55908ac2015-07-17 16:24:30 -0400154 cmdclass={
155 'clean': CleanCommand,
wbondbba5d622019-09-09 01:53:00 -0400156 'egg_info': EggInfoCommand,
wbond55908ac2015-07-17 16:24:30 -0400157 }
wbondb9b75972015-06-15 09:09:17 -0400158)