forked from Nekmo/best-browsable-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
142 lines (114 loc) · 4.36 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Improves the browsable api of Django Rest Framework
"""
import copy
import os
import glob
from itertools import chain
from setuptools import setup, find_packages
AUTHOR = "Nekmo"
EMAIL = '[email protected]'
URL = 'https://github.com/Nekmo/best-browsable-api/'
PACKAGE_NAME = 'best-browsable-api'
PACKAGE_DOWNLOAD_URL = 'https://github.com/Nekmo/best-browsable-api/archive/master.zip'
MODULE = 'best_browsable_api'
REQUIREMENT_FILE = 'requirements.txt'
STATUS_LEVEL = 3 # 1:Planning 2:Pre-Alpha 3:Alpha 4:Beta 5:Production/Stable 6:Mature 7:Inactive
KEYWORDS = ['browsable-api', 'api', 'django', 'django', 'drf', 'django-rest-framework']
LICENSE = 'MIT license'
CLASSIFIERS = [ # https://github.com/github/choosealicense.com/tree/gh-pages/_licenses
'License :: OSI Approved :: MIT License',
# 'License :: OSI Approved :: BSD License',
# 'License :: OSI Approved :: ISC License (ISCL)',
# 'License :: OSI Approved :: Apache Software License',
# 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
] # https://pypi.python.org/pypi?%3Aaction=list_classifiers
NATURAL_LANGUAGE = 'English'
PLATFORMS = [
# 'universal',
'linux',
# 'macosx',
# 'solaris',
# 'irix',
# 'win'
# 'bsd'
# 'ios'
# 'android'
]
PYTHON_VERSIONS = ['3.4-3.8']
def read_requirement_file(path):
with open(path) as f:
return f.readlines()
def get_package_version(module_name):
return __import__(module_name).__version__
def get_packages(directory):
# Search modules and submodules to install (module, module.submodule, module.submodule2...)
packages_list = find_packages(directory)
# Prevent include symbolic links
for package in tuple(packages_list):
path = os.path.join(directory, package.replace('.', '/'))
if not os.path.exists(path) or os.path.islink(path):
packages_list.remove(package)
return packages_list
def get_python_versions(string_range):
if '-' not in string_range:
return [string_range]
return ['{0:.1f}'.format(version * 0.1) for version
in range(*[int(x * 10) + (1 * i) for i, x in enumerate(map(float, string_range.split('-')))])]
def get_python_classifiers(versions):
for version in range(2, 4):
if not next(iter(filter(lambda x: int(float(x)) != version, versions.copy())), False):
versions.add('{} :: Only'.format(version))
break
return ['Programming Language :: Python :: %s' % version for version in versions]
def get_platform_classifiers(platform):
parts = {
'linux': ('POSIX', 'Linux'),
'win': ('Microsoft', 'Windows'),
'solaris': ('POSIX', 'SunOS/Solaris'),
'aix': ('POSIX', 'Linux'),
'unix': ('Unix',),
'bsd': ('POSIX', 'BSD')
}[platform]
return ['Operating System :: {}'.format(' :: '.join(parts[:i+1]))
for i in range(len(parts))]
# paths
here = os.path.abspath(os.path.dirname(__file__))
readme = glob.glob('{}/{}*'.format(here, 'README'))[0]
scripts = [os.path.join('scripts', os.path.basename(script)) for script in glob.glob('{}/scripts/*'.format(here))]
# Package data
packages = get_packages(here)
modules = list(filter(lambda x: '.' not in x, packages))
module = MODULE if MODULE else modules[0]
python_versions = set(chain(*[get_python_versions(versions) for versions in PYTHON_VERSIONS])) - {2.8, 2.9}
status_name = ['Planning', 'Pre-Alpha', 'Alpha', 'Beta',
'Production/Stable', 'Mature', 'Inactive'][STATUS_LEVEL - 1]
# Classifiers
classifiers = copy.copy(CLASSIFIERS)
classifiers.extend(get_python_classifiers(python_versions))
classifiers.extend(chain(*[get_platform_classifiers(platform) for platform in PLATFORMS]))
classifiers.extend([
'Natural Language :: {}'.format(NATURAL_LANGUAGE),
'Development Status :: {} - {}'.format(STATUS_LEVEL, status_name),
])
setup(
name=PACKAGE_NAME,
version=get_package_version(module),
packages=packages,
provides=modules,
scripts=scripts,
include_package_data=True,
description=__doc__,
long_description=open(readme, 'r').read(),
keywords=KEYWORDS,
download_url=PACKAGE_DOWNLOAD_URL,
author=AUTHOR,
author_email=EMAIL,
url=URL,
classifiers=classifiers,
platforms=PLATFORMS,
install_requires=read_requirement_file(REQUIREMENT_FILE),
# entry_points={},
zip_safe=False,
)