From 2725cd10b47969630cade5924852a663f1ad45d1 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Mon, 31 Aug 2020 14:26:14 +0200 Subject: [PATCH] [WIP] automating release --- .gitignore | 3 ++ compress.sh | 5 +- dev-requirements.txt | 2 + dodo.py | 107 +++++++++++++++++++++++++++++++++++++------ setup.py | 4 ++ zerobin/VERSION | 1 + zerobin/__init__.py | 2 +- 7 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 setup.py create mode 100644 zerobin/VERSION diff --git a/.gitignore b/.gitignore index abb1c3e..640b8f2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,12 +7,15 @@ *_index *.orig *.swp +*.old # binaries *.pyc *.pyo +*.pyz +*.zip __pycache__ .mypy* *.db diff --git a/compress.sh b/compress.sh index 36e3bf4..97e3753 100755 --- a/compress.sh +++ b/compress.sh @@ -1,5 +1,7 @@ #! /bin/bash +export PYTHONWARNINGS=ignore::FutureWarning # scss prints future warnings + python -c "import scss" || { echo >&2 "Error: this script requires the scss python module. pip install -r dev-requirements.txt" exit 1 @@ -23,15 +25,12 @@ echo "Compressing CSS..." echo $'\n''/* Prettify */' >>$CSS_OUTPUT python -m scss $CSSDIR'prettify.css' >>$CSS_OUTPUT -rm $CSSDIR'prettify.min.css' echo $'\n''/* Desert prettify theme */' >>$CSS_OUTPUT python -m scss $CSSDIR'desert.css' >>$CSS_OUTPUT -rm $CSSDIR'desert.min.css' echo $'\n''/* Bootswatch bootstrap theme */' >>$CSS_OUTPUT python -m scss $CSSDIR'bootswatch.4.5.css' >>$CSS_OUTPUT -rm $CSSDIR'bootswatch.4.5.min.css' echo $'\n''/* Our own CSS */' >>$CSS_OUTPUT python -m scss $CSSDIR'style.css' >>$CSS_OUTPUT diff --git a/dev-requirements.txt b/dev-requirements.txt index 084bdeb..6226864 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,2 +1,4 @@ doit==0.32.0 pyScss==1.3.7 +twine==3.2.0 +GitPython==3.1.7 diff --git a/dodo.py b/dodo.py index e6c47e0..8212cba 100644 --- a/dodo.py +++ b/dodo.py @@ -1,37 +1,69 @@ +import re +import sys + from pathlib import Path +from fnmatch import fnmatch + +import doit +from doit.tools import PythonInteractiveAction + +from git import Repo import zerobin +try: + from local_dodo import * +except ImportError: + pass + ROOT = Path(__file__).absolute().parent SOURCE_DIR = ROOT / "zerobin/" DIST_DIR = ROOT / "dist" +ZEROBIN_VERSION = (SOURCE_DIR / "VERSION").read_text().strip() -def source_files(extensions=None): +DOIT_CONFIG = { + "default_tasks": ["task_compress"], + "action_string_formatting": "new", +} + +REPO = Repo(".") + + +def source_files(extensions=None, exclude=()): + exclude_filter = ["*.pyc", ".*"] + exclude_filter.extend(exclude) extensions = extensions or [".*"] for ext in extensions: for file in SOURCE_DIR.rglob(f"*{ext}"): - if ( - not file.suffix.endswith("pyc") - and not file.is_dir() - and not "/." in str(file) + if not ( + file.is_dir() + or any(fnmatch(file, pattern) for pattern in exclude_filter) ): yield file -def generate_manifest(): - extensions = " ".join(set(f"*{f.suffix}" for f in source_files())) - (ROOT / "MANIFEST.in").write_text(f"recursive-include zerobin {extensions}") +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], + } def task_compress(): + main_js = str(SOURCE_DIR / "static/js/main.min.js") + main_css = str(SOURCE_DIR / "static/css/style.min.css") return { - "targets": [ - str(SOURCE_DIR / "static/js/main.min.js"), - str(SOURCE_DIR / "static/css/style.min.css"), - ], - "file_dep": list(str(f) for f in source_files([".css", ".js"])), + "targets": [main_js, main_css], + "file_dep": list( + str(f) for f in source_files([".css", ".js"], exclude=[main_css, main_js]) + ), "actions": [str(ROOT / "compress.sh")], } @@ -39,8 +71,53 @@ def task_compress(): def task_build(): return { - "targets": [DIST_DIR / f"zerobin-{zerobin.__version__}-py3-none-any.whl"], + "targets": [DIST_DIR / f"zerobin-{ZEROBIN_VERSION}-py3-none-any.whl"], "file_dep": list(str(f) for f in source_files() if ".min." not in str(f)), - "actions": [task_compress, generate_manifest, "python setup.py bdist_wheel",], + "task_dep": ["compress", "generate_manifest"], + "actions": ["python setup.py bdist_wheel"], + } + + +def task_publish_to_pypi(): + return { + "task_dep": ["build"], + "file_dep": [DIST_DIR / f"zerobin-{ZEROBIN_VERSION}-py3-none-any.whl"], + "actions": ["twine upload ./dist/*.whl"], + } + + +def task_release(): + pass + + +def task_bump_version(): + def bump(): + + if REPO.active_branch.name != "master": + sys.exit("You must be on the branch master to do that") + + print("Current version is:", ZEROBIN_VERSION) + action = 0 + 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): ") + + new_version = list(ZEROBIN_VERSION.split(".")) + 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") + + print(f"""REPO.create_tag("v" + {new_version})""") + + return { + "actions": [PythonInteractiveAction(bump),], } diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ecd37c5 --- /dev/null +++ b/setup.py @@ -0,0 +1,4 @@ +from setuptools import setup + +setup() + diff --git a/zerobin/VERSION b/zerobin/VERSION new file mode 100644 index 0000000..21e8796 --- /dev/null +++ b/zerobin/VERSION @@ -0,0 +1 @@ +1.0.3 diff --git a/zerobin/__init__.py b/zerobin/__init__.py index 1200bdc..6e88dfd 100644 --- a/zerobin/__init__.py +++ b/zerobin/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -__version__ = "1.0.3" +__version__ = (Path(__file__).parent / "VERSION").read_text().strip() ROOT_DIR = Path(__file__).absolute().parent