wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 1 | import codecs |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 2 | import os |
| 3 | import shutil |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 4 | import sys |
| 5 | import warnings |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 6 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 7 | import setuptools |
| 8 | from setuptools import setup, Command |
| 9 | from setuptools.command.egg_info import egg_info |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 10 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 11 | |
| 12 | PACKAGE_NAME = 'asn1crypto' |
wbond | c09b87c | 2020-01-04 09:06:42 -0500 | [diff] [blame] | 13 | PACKAGE_VERSION = '1.3.0' |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 14 | PACKAGE_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 |
| 19 | sv = setuptools.__version__ |
| 20 | svi = tuple(int(o) if o.isdigit() else o for o in sv.split('.')) |
| 21 | if 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. |
| 32 | if os.path.exists(os.path.join(PACKAGE_ROOT, 'tests')): |
| 33 | tests_require = [] |
| 34 | test_suite = 'tests.make_suite' |
| 35 | else: |
| 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". |
| 43 | package_data = {} |
| 44 | if 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 |
| 54 | class 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) |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 67 | |
| 68 | |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 69 | class CleanCommand(Command): |
wbond | 13df68b | 2016-06-16 05:50:48 -0400 | [diff] [blame] | 70 | user_options = [ |
wbond | ec51ff4 | 2017-03-10 14:23:54 -0500 | [diff] [blame] | 71 | ('all', 'a', '(Compatibility with original clean command)'), |
wbond | 13df68b | 2016-06-16 05:50:48 -0400 | [diff] [blame] | 72 | ] |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 73 | |
| 74 | def initialize_options(self): |
wbond | 13df68b | 2016-06-16 05:50:48 -0400 | [diff] [blame] | 75 | self.all = False |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 76 | |
| 77 | def finalize_options(self): |
| 78 | pass |
| 79 | |
| 80 | def run(self): |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 81 | 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) |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 86 | if os.path.exists(full_path): |
| 87 | shutil.rmtree(full_path) |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 88 | for root, dirs, files in os.walk(os.path.join(PACKAGE_ROOT, PACKAGE_NAME)): |
| 89 | for filename in files: |
wbond | b86376f | 2015-07-30 11:53:55 -0400 | [diff] [blame] | 90 | if filename[-4:] == '.pyc': |
| 91 | os.unlink(os.path.join(root, filename)) |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 92 | for dirname in list(dirs): |
wbond | b86376f | 2015-07-30 11:53:55 -0400 | [diff] [blame] | 93 | if dirname == '__pycache__': |
| 94 | shutil.rmtree(os.path.join(root, dirname)) |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 95 | |
| 96 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 97 | readme = '' |
| 98 | with codecs.open(os.path.join(PACKAGE_ROOT, 'readme.md'), 'r', 'utf-8') as f: |
| 99 | readme = f.read() |
| 100 | |
| 101 | |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 102 | setup( |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 103 | name=PACKAGE_NAME, |
| 104 | version=PACKAGE_VERSION, |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 105 | |
wbond | 3a487a4 | 2015-10-07 12:08:07 -0400 | [diff] [blame] | 106 | description=( |
wbond | 50f7876 | 2016-03-17 11:49:22 -0400 | [diff] [blame] | 107 | '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' |
wbond | 3a487a4 | 2015-10-07 12:08:07 -0400 | [diff] [blame] | 110 | ), |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 111 | long_description=readme, |
| 112 | long_description_content_type='text/markdown', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 113 | |
| 114 | url='https://github.com/wbond/asn1crypto', |
| 115 | |
| 116 | author='wbond', |
| 117 | author_email='will@wbond.net', |
| 118 | |
| 119 | license='MIT', |
| 120 | |
| 121 | classifiers=[ |
wbond | fcbba29 | 2019-10-02 21:00:46 -0400 | [diff] [blame] | 122 | 'Development Status :: 5 - Production/Stable', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 123 | |
| 124 | 'Intended Audience :: Developers', |
| 125 | |
| 126 | 'License :: OSI Approved :: MIT License', |
| 127 | |
Jon Dufresne | f1f85d6 | 2018-09-18 05:54:33 -0700 | [diff] [blame] | 128 | 'Programming Language :: Python', |
| 129 | 'Programming Language :: Python :: 2', |
wbond | 3f4a61c | 2015-08-24 10:45:00 -0400 | [diff] [blame] | 130 | 'Programming Language :: Python :: 2.6', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 131 | 'Programming Language :: Python :: 2.7', |
Jon Dufresne | f1f85d6 | 2018-09-18 05:54:33 -0700 | [diff] [blame] | 132 | 'Programming Language :: Python :: 3', |
wbond | bc3f0f6 | 2015-10-20 01:07:32 -0400 | [diff] [blame] | 133 | 'Programming Language :: Python :: 3.2', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 134 | 'Programming Language :: Python :: 3.3', |
| 135 | 'Programming Language :: Python :: 3.4', |
wbond | bc3f0f6 | 2015-10-20 01:07:32 -0400 | [diff] [blame] | 136 | 'Programming Language :: Python :: 3.5', |
wbond | 9712e07 | 2017-01-17 06:56:15 -0500 | [diff] [blame] | 137 | 'Programming Language :: Python :: 3.6', |
wbond | e5779a4 | 2019-07-04 06:39:13 -0400 | [diff] [blame] | 138 | 'Programming Language :: Python :: 3.7', |
wbond | fcbba29 | 2019-10-02 21:00:46 -0400 | [diff] [blame] | 139 | 'Programming Language :: Python :: 3.8', |
Jon Dufresne | f1f85d6 | 2018-09-18 05:54:33 -0700 | [diff] [blame] | 140 | 'Programming Language :: Python :: Implementation :: CPython', |
wbond | bc3f0f6 | 2015-10-20 01:07:32 -0400 | [diff] [blame] | 141 | 'Programming Language :: Python :: Implementation :: PyPy', |
| 142 | |
| 143 | 'Topic :: Security :: Cryptography', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 144 | ], |
| 145 | |
wbond | 50f7876 | 2016-03-17 11:49:22 -0400 | [diff] [blame] | 146 | keywords='asn1 crypto pki x509 certificate rsa dsa ec dh', |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 147 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 148 | packages=[PACKAGE_NAME], |
| 149 | package_data=package_data, |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 150 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 151 | tests_require=tests_require, |
| 152 | test_suite=test_suite, |
wbond | d7a440c | 2016-03-31 05:19:12 -0400 | [diff] [blame] | 153 | |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 154 | cmdclass={ |
| 155 | 'clean': CleanCommand, |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 156 | 'egg_info': EggInfoCommand, |
wbond | 55908ac | 2015-07-17 16:24:30 -0400 | [diff] [blame] | 157 | } |
wbond | b9b7597 | 2015-06-15 09:09:17 -0400 | [diff] [blame] | 158 | ) |