-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpublish.py
68 lines (56 loc) · 2.08 KB
/
publish.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
#!/usr/bin/env python3
import sys
import os
import glob
import time
import stat
import shutil
import subprocess
sys.dont_write_bytecode = True # prevent __pycache__ on importing './setup.py'
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
from setup import PACKAGE_NAME, PACKAGE_VERSION, ENVVAR_VERSION_SUFFIX
def execute(*args, module=False):
# there's no standard portable way to call Python3 explicitly
# https://docs.python.org/3/using/windows.html
shell_args = (sys.executable, *(("-m",) if module else ()), *args)
subprocess.check_call(shell_args)
def purge(skip_errors):
# shutil.rmtree fails on read-only files in Windows
# https://bugs.python.org/issue19643
def remove_readonly(func, path, *_):
os.chmod(path, stat.S_IWRITE)
func(path)
package_wildcard = "{}-{}*/".format(PACKAGE_NAME, PACKAGE_VERSION)
for folder in ("build", "dist", PACKAGE_NAME+".egg-info",
*glob.glob(package_wildcard)):
try:
shutil.rmtree(folder,
onerror=remove_readonly,
ignore_errors=skip_errors)
except FileNotFoundError:
pass
def main(args):
if "testpip" in args:
execute(
"pip", "install",
"--pre", "--force-reinstall", "--no-cache-dir",
"--index-url", "https://test.pypi.org/simple/",
"--extra-index-url", "https://pypi.org/simple",
"{}=={}.*".format(PACKAGE_NAME, PACKAGE_VERSION),
module=True
)
return
purge(False)
if "testpypi" in args:
# https://test.pypi.org/help/#file-name-reuse
# https://www.python.org/dev/peps/pep-0440/#developmental-releases
os.environ[ENVVAR_VERSION_SUFFIX] = "dev{}".format(int(time.time()))
os.environ["TWINE_REPOSITORY_URL"] = "https://test.pypi.org/legacy/"
try:
execute("setup.py", "sdist")
#execute("setup.py", "bdist_wheel")
execute("twine", "upload", "dist/*", module=True)
finally:
purge(True)
if __name__ == '__main__':
main(sys.argv)