forked from Erotemic/ubelt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
167 lines (143 loc) · 5.86 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Installation:
pip install git+https://github.com/Erotemic/ubelt.git
Developing:
git clone https://github.com/Erotemic/ubelt.git
pip install -e ubelt
Pypi:
# Presetup
pip install twine
# First tag the source-code
VERSION=$(python -c "import setup; print(setup.version)")
echo $VERSION
git tag $VERSION -m "tarball tag $VERSION"
git push --tags origin master
# NEW API TO UPLOAD TO PYPI
# https://packaging.python.org/tutorials/distributing-packages/
# Build wheel or source distribution
python setup.py bdist_wheel --universal
# Use twine to upload. This will prompt for username and password
# If you get an error:
# 403 Client Error: Invalid or non-existent authentication information.
# simply try typing your password slower.
twine upload --username erotemic --skip-existing dist/*
# Check the url to make sure everything worked
https://pypi.org/project/ubelt/
# ---------- OLD ----------------
# Check the url to make sure everything worked
https://pypi.python.org/pypi?:action=display&name=ubelt
"""
from setuptools import setup
import sys
def parse_version(package):
"""
Statically parse the version number from __init__.py
CommandLine:
python -c "import setup; print(setup.parse_version('ubelt'))"
"""
from os.path import dirname, join
import ast
init_fpath = join(dirname(__file__), package, '__init__.py')
with open(init_fpath) as file_:
sourcecode = file_.read()
pt = ast.parse(sourcecode)
class VersionVisitor(ast.NodeVisitor):
def visit_Assign(self, node):
for target in node.targets:
if target.id == '__version__':
self.version = node.value.s
visitor = VersionVisitor()
visitor.visit(pt)
return visitor.version
def parse_description():
"""
Parse the description in the README file
CommandLine:
pandoc --from=markdown --to=rst --output=README.rst README.md
python -c "import setup; print(setup.parse_description())"
"""
from os.path import dirname, join, exists
readme_fpath = join(dirname(__file__), 'README.rst')
# This breaks on pip install, so check that it exists.
if exists(readme_fpath):
with open(readme_fpath, 'r') as f:
text = f.read()
return text
return ''
def parse_requirements(fname='requirements.txt'):
"""
Parse the package dependencies listed in a requirements file but strips
specific versioning information.
CommandLine:
python -c "import setup; print(setup.parse_requirements())"
"""
from os.path import dirname, join, exists
import re
require_fpath = join(dirname(__file__), fname)
# This breaks on pip install, so check that it exists.
if exists(require_fpath):
with open(require_fpath, 'r') as f:
packages = []
for line in f.readlines():
line = line.strip()
if line and not line.startswith('#'):
if line.startswith('-e '):
package = line.split('#egg=')[1]
packages.append(package)
else:
# Remove versioning from the package
pat = '(' + '|'.join(['>=', '==', '>']) + ')'
parts = re.split(pat, line, maxsplit=1)
parts = [p.strip() for p in parts]
package = parts[0]
if len(parts) > 1:
op, rest = parts[1:]
if ';' in rest:
# Declaring platform specific dependencies
# http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies
version, platform_deps = map(str.strip, rest.split(';'))
if not sys.version.startswith('3.4'):
# apparently this breaks in 3.4
package = package + ';' + platform_deps
# if platform_deps == 'platform_system=="Windows"':
# pass
else:
version = rest # NOQA
packages.append(package)
return packages
return []
version = parse_version('ubelt') # needs to be a global var for git tags
if __name__ == '__main__':
install_requires = parse_requirements('requirements.txt')
if sys.platform.startswith('win32'):
install_requires += parse_requirements('requirements-win32.txt')
setup(
name='ubelt',
version=version,
author='Jon Crall',
description='A "utility belt" of commonly needed utility and helper functions',
long_description=parse_description(),
install_requires=install_requires,
extras_require={
'all': parse_requirements('optional-requirements.txt')
},
author_email='[email protected]',
url='https://github.com/Erotemic/ubelt',
license='Apache 2',
packages=['ubelt'],
classifiers=[
# List of classifiers available at:
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Utilities',
# This should be interpreted as Apache License v2.0
'License :: OSI Approved :: Apache Software License',
# Supported Python versions
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
)