forked from albertz/background-zmq-ipython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
146 lines (116 loc) · 4.02 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
"""
Usage:
Create ~/.pypirc with info:
[distutils]
index-servers =
pypi
[pypi]
repository: https://upload.pypi.org/legacy/
username: ...
password: ...
(Not needed anymore) Registering the project: python3 setup.py register
New release: python3 setup.py sdist upload
I had some trouble at some point, and this helped:
pip3 install --user twine
python3 setup.py sdist
twine upload dist/background_zmq_ipython-*
See also MANIFEST.in for included files.
For debugging this script:
python3 setup.py sdist
pip3 install --user dist/...*.tar.gz -v
(Without -v, all stdout/stderr from here will not be shown.)
"""
from distutils.core import setup
import time
from pprint import pprint
import os
import sys
from subprocess import Popen, check_output, PIPE
def debug_print_file(fn):
print("%s:" % fn)
if not os.path.exists(fn):
print("<does not exist>")
return
if os.path.isdir(fn):
print("<dir:>")
pprint(os.listdir(fn))
return
print(open(fn).read())
def parse_pkg_info(fn):
"""
:param str fn:
:rtype: dict[str,str]
"""
res = {}
for ln in open(fn).read().splitlines():
if not ln or not ln[:1].strip():
continue
key, value = ln.split(": ", 1)
res[key] = value
return res
def git_commit_rev(commit="HEAD", git_dir="."):
if commit is None:
commit = "HEAD"
return check_output(["git", "rev-parse", "--short", commit], cwd=git_dir).decode("utf8").strip()
def git_is_dirty(git_dir="."):
proc = Popen(["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], cwd=git_dir, stdout=PIPE)
proc.communicate()
if proc.returncode == 0:
return False
if proc.returncode == 1:
return True
raise Exception("unexpected return code %i" % proc.returncode)
def git_commit_date(commit="HEAD", git_dir="."):
out = check_output(["git", "show", "-s", "--format=%ci", commit], cwd=git_dir).decode("utf8")
out = out.strip()[:-6].replace(":", "").replace("-", "").replace(" ", ".")
return out
def git_head_version(git_dir="."):
commit_date = git_commit_date(git_dir=git_dir) # like "20190202.154527"
# rev = git_commit_rev(git_dir=git_dir)
# is_dirty = git_is_dirty(git_dir=git_dir)
# Make this distutils.version.StrictVersion compatible.
return "1.%s" % commit_date
if os.path.exists("PKG-INFO"):
print("Found existing PKG-INFO.")
info = parse_pkg_info("PKG-INFO")
version = info["Version"]
print("Version via PKG-INFO:", version)
else:
try:
version = git_head_version()
print("Version via Git:", version)
except Exception as exc:
print("Exception while getting Git version:", exc)
sys.excepthook(*sys.exc_info())
version = time.strftime("1.%Y%m%d.%H%M%S", time.gmtime())
print("Version via current time:", version)
if os.environ.get("DEBUG", "") == "1":
debug_print_file(".")
debug_print_file("PKG-INFO")
setup(
name='background_zmq_ipython',
version=version,
packages=['background_zmq_ipython'],
package_dir={'background_zmq_ipython': ''},
description='Background ZMQ IPython/Jupyter kernel',
author='Albert Zeyer',
author_email='[email protected]',
url='https://github.com/albertz/background-zmq-ipython',
license='2-clause BSD license',
long_description=open('README.rst').read(),
install_requires=open('requirements.txt').read().splitlines(),
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
]
)