2020-08-31 15:26:14 +03:00
|
|
|
import sys
|
2020-08-31 18:25:18 +03:00
|
|
|
import subprocess
|
2020-08-31 15:26:14 +03:00
|
|
|
|
2020-08-18 14:26:29 +03:00
|
|
|
from pathlib import Path
|
2020-08-31 15:26:14 +03:00
|
|
|
from fnmatch import fnmatch
|
|
|
|
|
|
|
|
from doit.tools import PythonInteractiveAction
|
|
|
|
|
|
|
|
try:
|
|
|
|
from local_dodo import *
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2020-08-18 14:26:29 +03:00
|
|
|
ROOT = Path(__file__).absolute().parent
|
|
|
|
SOURCE_DIR = ROOT / "zerobin/"
|
|
|
|
DIST_DIR = ROOT / "dist"
|
|
|
|
|
2020-08-31 15:26:14 +03:00
|
|
|
ZEROBIN_VERSION = (SOURCE_DIR / "VERSION").read_text().strip()
|
|
|
|
|
|
|
|
DOIT_CONFIG = {
|
|
|
|
"default_tasks": ["task_compress"],
|
|
|
|
"action_string_formatting": "new",
|
|
|
|
}
|
|
|
|
|
2020-08-31 16:58:53 +03:00
|
|
|
|
2020-08-31 18:25:18 +03:00
|
|
|
def git(*args, **kwargs):
|
|
|
|
return subprocess.check_output(
|
|
|
|
["git", *args], stderr=subprocess.STDOUT, universal_newlines=True,
|
2020-08-31 16:58:53 +03:00
|
|
|
).rstrip("\n")
|
2020-08-31 15:26:14 +03:00
|
|
|
|
2020-08-18 14:26:29 +03:00
|
|
|
|
2020-08-31 15:26:14 +03:00
|
|
|
def source_files(extensions=None, exclude=()):
|
|
|
|
exclude_filter = ["*.pyc", ".*"]
|
|
|
|
exclude_filter.extend(exclude)
|
2020-08-18 14:26:29 +03:00
|
|
|
extensions = extensions or [".*"]
|
|
|
|
for ext in extensions:
|
|
|
|
for file in SOURCE_DIR.rglob(f"*{ext}"):
|
2020-08-31 15:26:14 +03:00
|
|
|
if not (
|
|
|
|
file.is_dir()
|
|
|
|
or any(fnmatch(file, pattern) for pattern in exclude_filter)
|
2020-08-18 14:26:29 +03:00
|
|
|
):
|
|
|
|
yield file
|
|
|
|
|
|
|
|
|
2020-08-31 15:26:14 +03:00
|
|
|
def task_generate_manifest():
|
|
|
|
def generate():
|
|
|
|
globs = " ".join(set(f"*{f.suffix}" for f in source_files()))
|
|
|
|
globs += " VERSION"
|
|
|
|
(ROOT / "MANIFEST.in").write_text(f"recursive-include zerobin {globs}")
|
|
|
|
|
|
|
|
return {
|
|
|
|
"targets": [ROOT / "MANIFEST.in"],
|
|
|
|
"actions": [generate],
|
|
|
|
}
|
2020-08-18 14:26:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
def task_compress():
|
2020-08-31 15:26:14 +03:00
|
|
|
main_js = str(SOURCE_DIR / "static/js/main.min.js")
|
|
|
|
main_css = str(SOURCE_DIR / "static/css/style.min.css")
|
2020-08-18 14:26:29 +03:00
|
|
|
return {
|
2020-08-31 15:26:14 +03:00
|
|
|
"targets": [main_js, main_css],
|
|
|
|
"file_dep": list(
|
|
|
|
str(f) for f in source_files([".css", ".js"], exclude=[main_css, main_js])
|
|
|
|
),
|
2020-08-18 14:26:29 +03:00
|
|
|
"actions": [str(ROOT / "compress.sh")],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def task_build():
|
|
|
|
|
|
|
|
return {
|
2020-08-31 15:26:14 +03:00
|
|
|
"targets": [DIST_DIR / f"zerobin-{ZEROBIN_VERSION}-py3-none-any.whl"],
|
2020-08-18 14:26:29 +03:00
|
|
|
"file_dep": list(str(f) for f in source_files() if ".min." not in str(f)),
|
2020-08-31 15:26:14 +03:00
|
|
|
"task_dep": ["compress", "generate_manifest"],
|
|
|
|
"actions": ["python setup.py bdist_wheel"],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def task_publish_to_pypi():
|
2020-08-31 18:25:18 +03:00
|
|
|
|
2020-08-31 15:26:14 +03:00
|
|
|
return {
|
|
|
|
"task_dep": ["build"],
|
2020-08-31 18:25:18 +03:00
|
|
|
"actions": ["echo twine upload ./dist/*.whl"],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def task_build_pyz():
|
|
|
|
return {
|
|
|
|
"actions": ["shiv zerobin -o dist/zerobin.pyz -c zerobin"],
|
2020-08-31 15:26:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def task_bump_version():
|
|
|
|
def bump():
|
|
|
|
|
2020-08-31 16:58:53 +03:00
|
|
|
if git("branch", "--show-current") != "master":
|
2020-08-31 15:26:14 +03:00
|
|
|
sys.exit("You must be on the branch master to do that")
|
|
|
|
|
2020-08-31 17:20:59 +03:00
|
|
|
git("fetch", "origin", "master")
|
2020-08-31 17:30:05 +03:00
|
|
|
if git("rev-parse", "@{u}") != git("merge-base", "@", "@{u}"):
|
2020-08-31 16:58:53 +03:00
|
|
|
sys.exit("Cannot push a new version, you need to pull first")
|
|
|
|
|
|
|
|
git_status = git("status", "--porcelain=1").split("\n")
|
|
|
|
if not all(
|
|
|
|
line.startswith(" ") for line in git_status if not line.startswith("?")
|
|
|
|
):
|
|
|
|
sys.exit("Cannot commit the new version: you have changes to be commited.")
|
|
|
|
|
2020-08-31 15:26:14 +03:00
|
|
|
print("Current version is:", ZEROBIN_VERSION)
|
2020-08-31 16:58:53 +03:00
|
|
|
action = "0"
|
2020-08-31 15:26:14 +03:00
|
|
|
while action not in "123":
|
|
|
|
|
|
|
|
print("What kind of version is it?\n")
|
|
|
|
print("1) Major")
|
|
|
|
print("2) Minor")
|
|
|
|
print("3) Fix")
|
|
|
|
action = input("Enter 1, 2 or 3 (Ctrl + C to quit): ")
|
|
|
|
|
2020-08-31 16:58:53 +03:00
|
|
|
new_version = list(map(int, ZEROBIN_VERSION.split(".")))
|
2020-08-31 15:26:14 +03:00
|
|
|
action = int(action) - 1
|
|
|
|
new_version[action] += 1
|
|
|
|
new_version = ".".join(map(str, new_version))
|
|
|
|
|
|
|
|
print("The new version will be:", new_version)
|
|
|
|
if input("Ok? [y/N] ").strip().lower() != "y":
|
|
|
|
sys.exit("The version has NOT been bumped")
|
|
|
|
|
2020-08-31 16:58:53 +03:00
|
|
|
print("- Updating VERSION file")
|
|
|
|
(SOURCE_DIR / "VERSION").write_text(new_version)
|
|
|
|
print("- Commiting VERSION file")
|
2020-08-31 18:25:18 +03:00
|
|
|
git("add", "zerobin/VERSION")
|
|
|
|
git(
|
|
|
|
"commit", "-m", f"Bumping to version {new_version}",
|
|
|
|
)
|
2020-08-31 16:58:53 +03:00
|
|
|
print(f"- Adding v{new_version} tag")
|
|
|
|
git("tag", f"v{new_version}")
|
|
|
|
print("- Pushing tag")
|
|
|
|
git("push", "origin", "master", "--tag")
|
2020-08-31 15:26:14 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
"actions": [PythonInteractiveAction(bump),],
|
2020-08-18 14:26:29 +03:00
|
|
|
}
|
|
|
|
|
2020-08-31 16:58:53 +03:00
|
|
|
|
|
|
|
def task_release_to_pypi():
|
2020-08-31 17:04:40 +03:00
|
|
|
return {"task_dep": ["bump_version", "publish_to_pypi"], "actions": []}
|