diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3f9d94..9e76598 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,12 @@ jobs: strategy: matrix: + # 2023-09 тесты 3.12.0-rc.2 не проходили на windows-latest, + # поэтому пока отключены + os: [ ubuntu-latest, macos-latest, windows-latest ] - python-version: [ 3.7, 3.8, 3.9, '3.10', '3.11', '3.12' ] + + python-version: [ 3.7, 3.8, 3.9, '3.10', '3.11' ] steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 5677459..2af54c1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Generic badge](https://img.shields.io/badge/Maturity-Experimental-red.svg) ](#) -[![Generic badge](https://img.shields.io/badge/Python-3.7..3.12-blue.svg)](#) +[![Generic badge](https://img.shields.io/badge/Python-3.7–3.11-blue.svg)](#) [![Generic badge](https://img.shields.io/badge/OS-Linux%20|%20macOS%20|%20Windows-blue.svg)](#) # [dmk: dark matter keeper](https://github.com/rtmigo/dmk_py#readme) diff --git a/dmk/_constants.py b/dmk/_constants.py index 644b02d..2d2d391 100644 --- a/dmk/_constants.py +++ b/dmk/_constants.py @@ -4,3 +4,4 @@ __version__ = "0.7.0" __copyright__ = "2021-2022 Artem IG " +__build_timestamp__ = "0000-00-00 00:00" diff --git a/do.py b/do.py new file mode 100644 index 0000000..cce3cc9 --- /dev/null +++ b/do.py @@ -0,0 +1,112 @@ +import datetime +import os +import re +import shutil +import subprocess +import sys +from pathlib import Path + +import PyInstaller.__main__ as compile +import click +import neatest +from chkpkg import Package + + +@click.group() +def app(): + pass + + +@app.command() +def test(): + _test() + + +def _test(): + neatest.run(warnings=neatest.Warnings.fail) + + +@app.command() +def test_pkg(): + with Package() as pkg: + pkg.run_shell_code('dmk --version') + print("\nPackage is OK!") + + +@app.command() +def run(): + subprocess.call([sys.executable, "_run.py"]) + + +@app.command() +def lint(): + _lint() + + +def _lint(): + print("Running mypy...") + if subprocess.call(['mypy', 'dmk', + '--ignore-missing-imports']) != 0: + exit(1) + + +# def _get_git_commit(): +# return subprocess.check_output("git log --pretty=format:'%h' -n 1".split()) + + +def _replace_build_date(fn: Path): + now = datetime.datetime.now().isoformat(sep=" ", timespec="seconds") + text = fn.read_text() + new_text = re.sub( + r'__build_timestamp__.+', + f'__build_timestamp__ = "{now}"', + text) + print(new_text) + assert new_text != text, "timestamp not changed" + fn.write_text(new_text) + + +# def _replace_git_commit(fn: Path): +# now = datetime.datetime.now().isoformat(sep=" ", timespec="seconds") +# text = fn.read_text() +# text = re.sub( +# r'__prev_commit__.+$', +# f'__prev_prev_commit__ = "{now}"', +# text) +# print(text) +# fn.write_text(text) + + +@app.command() +def install(): + """Build PyInstaller executable and copy it to ~/.local/bin""" + name = "dmk" + project_dir = Path(__file__).parent + + _test() + _lint() + + _replace_build_date(Path("dmk/_constants.py")) + # exit() + + compile.run([ + "--clean", "--onefile", "-y", + "--collect-all", "dmk", + "--name", name, "_run.py" + ]) + + exe = project_dir / "dist" / name + print(f"Exe size: {exe.stat().st_size / 1024 / 1024:.0f} MiB") + + os.remove(project_dir / "dmk.spec") + shutil.rmtree(project_dir / "build") + target = Path(os.path.expanduser("~/.local/bin")) / name + if target.parent.exists(): + print(f"Copying to {target}") + shutil.move(exe, target) + else: + print(f"{target.parent} does not exist") + + +if __name__ == "__main__": + app()