forked from jambonrose/django-improved-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·190 lines (159 loc) · 6.3 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
"""
====================
Django Improved User
====================
:website: https://github.com/jambonsw/django-improved-user/
:copyright: Copyright 2018 JamBon Software
:license: Simplified BSD, see LICENSE for details.
"""
from distutils.command.check import check as CheckCommand
from operator import attrgetter
from os.path import abspath, dirname, join
from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand
HERE = abspath(dirname(__file__))
def load_file_contents(file_path, as_list=True):
"""Load file as string or list"""
abs_file_path = join(HERE, file_path)
with open(abs_file_path, encoding='utf-8') as file_pointer:
if as_list:
return file_pointer.read().splitlines()
return file_pointer.read()
LONG_DESCRIPTION = (
load_file_contents('README.rst', as_list=False)
.split('.. end-badges')[1] # remove badge icons at top
.lstrip() # remove any extraneous spaces before title
)
class CustomCheckCommand(CheckCommand):
"""Customized distutils check command"""
# https://github.com/python/cpython/blob/master/Lib/distutils/command/check.py
user_options = CheckCommand.user_options + [
('disable-metadata', None, "don't check meta-data"),
('enforce-email', 'e', 'Ensure that all author/maintainer use email'),
]
negative_opt = {'disable-metadata': 'metadata'}
def initialize_options(self):
"""Setup superclass and new options"""
super().initialize_options()
self.enforce_email = 0 # pylint:disable=attribute-defined-outside-init
def check_metadata(self):
"""
Ensures that all required elements of meta-data are supplied.
Specifically: name, version, URL, author or maintainer
Warns if any are missing.
If enforce-email option is true, author and/or maintainer must
specify an email.
"""
metadata = self.distribution.metadata
missing = []
for attr in ('name', 'version', 'url'):
if not (hasattr(metadata, attr) and getattr(metadata, attr)):
missing.append(attr)
# https://www.python.org/dev/peps/pep-0345/
# author or maintainer must be specified
# author is preferred; if identifcal, specify only author
if not metadata.author and not metadata.maintainer:
missing.append('author')
if self.enforce_email:
missing.append('author_email')
else:
# one or both of author or maintainer specified
if (metadata.author and self.enforce_email
and not metadata.author_email):
missing.append('author_email')
if (metadata.maintainer and self.enforce_email
and not metadata.maintainer_email):
missing.append('maintainer_email')
if (metadata.author and metadata.maintainer
and metadata.author == metadata.maintainer):
self.warn(
'Maintainer should be omitted if identical to Author.\n'
'See https://www.python.org/dev/peps/pep-0345/'
'#maintainer-email-optional')
if (metadata.author_email and metadata.maintainer_email
and metadata.author_email == metadata.maintainer_email):
self.warn(
'Maintainer Email should be omitted if'
"identical to Author's.\n"
'See https://www.python.org/dev/peps/pep-0345/'
'#maintainer-email-optional')
if missing:
self.warn('missing required meta-data: %s' % ', '.join(missing))
class CustomTestCommand(TestCommand):
"""Customized setuptools test command"""
# https://github.com/pypa/setuptools/blob/master/setuptools/command/test.py
# https://github.com/python/cpython/blob/master/Lib/distutils/cmd.py
description = 'run project tests'
command_consumes_arguments = True
user_options = []
def initialize_options(self):
"""Explicitly set all instance vars"""
self.args = [] # pylint: disable=attribute-defined-outside-init
def finalize_options(self):
"""Needed by Superclass"""
def run(self):
installed_dists = self.install_dists(self.distribution)
if self.dry_run:
self.announce('skipping tests (dry run)')
return
paths = map(attrgetter('location'), installed_dists)
with self.paths_on_pythonpath(paths):
with self.project_on_sys_path():
self.run_tests()
def run_tests(self):
from runtests import (
check_missing_migrations, configure_django, run_test_suite,
)
configure_django()
check_missing_migrations()
run_test_suite(*self.args)
setup(
name='django-improved-user',
version='1.0.1',
description=(
'A custom Django user model for best practices email-based login.'
),
long_description=LONG_DESCRIPTION,
url='https://github.com/jambonsw/django-improved-user/',
packages=find_packages('src'),
package_dir={'': 'src'},
install_requires=[
'django>=1.8,!=1.9.*,!=1.10.*',
],
extras_require={
'factory': [
'factory_boy>=2.9',
'Faker>=0.8',
'python-dateutil>=2.6',
],
},
zip_safe=False,
cmdclass={
'check': CustomCheckCommand,
'test': CustomTestCommand,
},
author=(
'Russell Keith-Magee, '
'Andrew Pinkham'
),
license='BSD License',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Topic :: Software Development :: Libraries',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3 :: Only',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
],
)