-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmanage.py
More file actions
180 lines (135 loc) · 4.96 KB
/
manage.py
File metadata and controls
180 lines (135 loc) · 4.96 KB
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
#!/usr/bin/env python2.7
# coding: utf-8
"""
This script is used to manage the `yamicache` project.
"""
# Imports #####################################################################
import os
import re
import click
import requests
# import subprocess
# import SocketServer
# import SimpleHTTPServer
from pkg_resources import parse_version
from __manage import run_command
from __manage.docs import build_docs, clean_docs, serve_docs
from __manage.version import rev_version, show_versions, tag_version
# Metadata ####################################################################
__author__ = "Timothy McFadden"
__creationDate__ = "29-AUG-2017"
__license__ = "MIT"
# Globals #####################################################################
def install():
"""Install this package"""
run_command(["poetry", "install"])
def lint():
"""Run flake8 against the project"""
(text, returncode) = run_command(["flake8", "--ignore=E501", "yamicache", "tests"])
if text:
click.echo(text)
click.echo("flake8 failed")
raise click.Abort()
click.echo("...linting passed")
def clean_build():
"""Clean the build"""
run_command(["rm", "-rf", "yamicache.egg-info"])
run_command(["rm", "-rf", "build"])
def clean_dist():
"""Clean the dist"""
run_command(["rm", "-rf", "dist/*"])
def clean_all():
"""Clean all artifacts"""
clean_build()
clean_dist()
clean_docs()
def build_all():
"""Build the distribution & docs"""
build_dist()
build_docs()
def build_dist():
"""Build the distribution"""
(text, returncode) = run_command(["./build.sh"])
if returncode:
print("ERROR:", text)
return
def deploy():
"""Upload dist to pypi"""
(text, returncode) = run_command(["git", "status", "--porcelain"])
if text:
click.echo("ERROR: You have non-commited changes:\n%s" % text)
click.echo("...aborting deploy")
raise click.Abort()
if not os.path.exists("dist"):
click.echo("'dist' directory does not exist; run `build` first.")
raise click.Abort()
# Get the version in dist
tarball = next(
(
x
for x in os.listdir("dist")
if (x.startswith("yamicache") and x.endswith(".tar.gz"))
),
None,
)
if not tarball:
click.echo("Could not find tarball in `dist` directory; run `build` first.")
raise click.Abort()
match = re.search("yamicache-(?P<version>[\d\.a-z]+)\.tar\.gz", tarball)
if not match:
click.echo("Could not parse version from [%s]" % tarball)
built_version = match.group("version")
click.echo("found built version: %s" % built_version)
built_version = parse_version(built_version)
# check to see if the pypi version already exists
try:
package_json = requests.get("https://pypi.python.org/pypi/yamicache/json")
package_data = package_json.json()
pypi_version = package_data["info"]["version"]
except Exception as e:
click.echo("Error getting version from pypi: %s" % e)
raise click.Abort()
click.echo("found pypi version: %s" % pypi_version)
pypi_version = parse_version(pypi_version)
if pypi_version >= built_version:
click.echo("pypi version is >= built version; upload canceled")
raise click.Abort()
click.echo("...uploading")
# Create the CLI ##############################################################
def add_command(name, f, group, description=None, params=None):
group.add_command(
click.Command(name, callback=f, help=description or f.__doc__, params=params)
)
cli = click.Group()
cli.params.append(
click.Option(("--dry-run",), is_flag=True, help="Don't actually execute anything")
)
add_command("lint", lint, cli)
add_command("deploy", deploy, cli)
add_command("install", install, cli)
show_group = click.Group("show", help="Display project info")
add_command("version", show_versions, show_group)
cli.add_command(show_group)
build_group = click.Group("build", help="Build artifacts")
add_command("docs", build_docs, build_group, "Build the docs")
add_command("dist", build_dist, build_group)
add_command("all", build_all, build_group)
cli.add_command(build_group)
clean_group = click.Group("clean", help="Remove artifacts")
add_command("docs", clean_docs, clean_group)
add_command("dist", clean_dist, clean_group)
add_command("all", clean_all, clean_group)
cli.add_command(clean_group)
docs_group = click.Group("docs", help="HTML Documentation")
add_command("build", build_docs, docs_group)
add_command("serve", serve_docs, docs_group)
add_command("clean", clean_docs, docs_group)
cli.add_command(docs_group)
ver_group = click.Group("ver", help="Version control")
add_command("show", show_versions, ver_group)
add_command("rev", rev_version, ver_group)
add_command("tag", tag_version, ver_group)
cli.add_command(ver_group)
###############################################################################
if __name__ == "__main__":
cli()