-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev
- Loading branch information
Showing
46 changed files
with
3,181 additions
and
1,308 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# see https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.py] | ||
max_line_length = 119 | ||
|
||
[{Makefile,**.mk}] | ||
indent_style = tab | ||
insert_final_newline = false | ||
|
||
[{*.yaml,*.yml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Move to pyproject.toml after: https://github.com/PyCQA/flake8/issues/234 | ||
# | ||
[flake8] | ||
exclude = .*, dist, htmlcov | ||
#ignore = E402 | ||
max-line-length = 119 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,15 @@ | ||
*.py[cod] | ||
*.rom | ||
*~ | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info/* | ||
/dist/* | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
lib | ||
lib64 | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
/htmlcov/* | ||
.tox | ||
nosetests.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
.project | ||
.pydevproject | ||
.idea/* | ||
.settings/* | ||
.* | ||
*.egg-info | ||
__pycache__ | ||
/dist/ | ||
/build/ | ||
/coverage.* | ||
*.orig | ||
|
||
!.github | ||
!.editorconfig | ||
!.flake8 | ||
!.gitignore | ||
!.pre-commit-config.yaml | ||
!.pre-commit-hooks.yaml | ||
!.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# pre-commit plugin configuration | ||
# See https://pre-commit.com for more information | ||
default_install_hook_types: | ||
- pre-commit | ||
- post-rewrite | ||
- pre-push | ||
|
||
repos: | ||
- repo: https://github.com/jedie/cli-base-utilities | ||
rev: v0.11.0 | ||
hooks: | ||
- id: update-readme-history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# https://pre-commit.com/#creating-new-hooks | ||
- id: update-readme-history | ||
name: cli-base-utilities | ||
description: >- | ||
Update history in README.md from git log. | ||
entry: "python -m cli_base update-readme-history -v" | ||
language: python | ||
language_version: python3 | ||
require_serial: true | ||
pass_filenames: false | ||
always_run: true | ||
verbose: true | ||
stages: [pre-commit, post-rewrite, pre-push] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Dragon/CoCO Python Library | ||
|
||
[![tests](https://github.com/6809/dragonlib/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/6809/dragonlib/actions/workflows/tests.yml) | ||
[![codecov](https://codecov.io/github/jedie/dragonlib/branch/main/graph/badge.svg)](https://app.codecov.io/github/jedie/dragonlib) | ||
[![dragonlib @ PyPi](https://img.shields.io/pypi/v/dragonlib?label=dragonlib%20%40%20PyPi)](https://pypi.org/project/dragonlib/) | ||
[![Python Versions](https://img.shields.io/pypi/pyversions/dragonlib)](https://github.com/6809/dragonlib/blob/main/pyproject.toml) | ||
[![License GPL-3.0-or-later](https://img.shields.io/pypi/l/dragonlib)](https://github.com/6809/dragonlib/blob/main/LICENSE) | ||
|
||
Python Modules/Tools Open source (GPL v3 or later) for 6809 based homecomputer like: | ||
|
||
* [Dragon 32](http://en.wikipedia.org/wiki/Dragon_32) | ||
* [Tandy TRS-80 Color Computer](http://en.wikipedia.org/wiki/TRS-80_Color_Computer) (CoCo) | ||
|
||
Used in: | ||
|
||
* [DragonPy](https://github.com/jedie/DragonPy) - Emulator for 6809 CPU based system like Dragon 32 / CoCo written in Python: | ||
* [DwLoadServer](https://github.com/DWLOAD/DwLoadServer) - DWLOAD server implemented in Python | ||
|
||
|
||
## Start hacking | ||
|
||
```shell | ||
~$ git clone https://github.com/6809/dragonlib.git | ||
~$ cd dragonlib | ||
~/dragonlib$ ./dev-cli.py --help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
bootstrap CLI | ||
~~~~~~~~~~~~~ | ||
Just call this file, and the magic happens ;) | ||
""" | ||
|
||
import hashlib | ||
import shlex | ||
import subprocess | ||
import sys | ||
import venv | ||
from pathlib import Path | ||
|
||
|
||
def print_no_pip_error(): | ||
print('Error: Pip not available!') | ||
print('Hint: "apt-get install python3-venv"\n') | ||
|
||
|
||
try: | ||
from ensurepip import version | ||
except ModuleNotFoundError as err: | ||
print(err) | ||
print('-' * 100) | ||
print_no_pip_error() | ||
raise | ||
else: | ||
if not version(): | ||
print_no_pip_error() | ||
sys.exit(-1) | ||
|
||
|
||
assert sys.version_info >= (3, 9), f'Python version {sys.version_info} is too old!' | ||
|
||
|
||
if sys.platform == 'win32': # wtf | ||
# Files under Windows, e.g.: .../.venv/Scripts/python.exe | ||
BIN_NAME = 'Scripts' | ||
FILE_EXT = '.exe' | ||
else: | ||
# Files under Linux/Mac and all other than Windows, e.g.: .../.venv/bin/python3 | ||
BIN_NAME = 'bin' | ||
FILE_EXT = '' | ||
|
||
BASE_PATH = Path(__file__).parent | ||
VENV_PATH = BASE_PATH / '.venv-app' | ||
BIN_PATH = VENV_PATH / BIN_NAME | ||
PYTHON_PATH = BIN_PATH / f'python3{FILE_EXT}' | ||
PIP_PATH = BIN_PATH / f'pip{FILE_EXT}' | ||
PIP_SYNC_PATH = BIN_PATH / f'pip-sync{FILE_EXT}' | ||
|
||
DEP_LOCK_PATH = BASE_PATH / 'requirements.txt' | ||
DEP_HASH_PATH = VENV_PATH / '.dep_hash' | ||
|
||
# script file defined in pyproject.toml as [console_scripts] | ||
# (Under Windows: ".exe" not added!) | ||
PROJECT_SHELL_SCRIPT = BIN_PATH / 'dragonlib_app' | ||
|
||
|
||
def get_dep_hash(): | ||
"""Get SHA512 hash from lock file content.""" | ||
return hashlib.sha512(DEP_LOCK_PATH.read_bytes()).hexdigest() | ||
|
||
|
||
def store_dep_hash(): | ||
"""Generate .venv/.dep_hash""" | ||
DEP_HASH_PATH.write_text(get_dep_hash()) | ||
|
||
|
||
def venv_up2date(): | ||
"""Is existing .venv is up-to-date?""" | ||
if DEP_HASH_PATH.is_file(): | ||
return DEP_HASH_PATH.read_text() == get_dep_hash() | ||
return False | ||
|
||
|
||
def verbose_check_call(*popen_args): | ||
print(f'\n+ {shlex.join(str(arg) for arg in popen_args)}\n') | ||
return subprocess.check_call(popen_args) | ||
|
||
|
||
def main(argv): | ||
assert DEP_LOCK_PATH.is_file(), f'File not found: "{DEP_LOCK_PATH}" !' | ||
|
||
# Create virtual env in ".venv/": | ||
if not PYTHON_PATH.is_file(): | ||
print(f'Create virtual env here: {VENV_PATH.absolute()}') | ||
builder = venv.EnvBuilder(symlinks=True, upgrade=True, with_pip=True) | ||
builder.create(env_dir=VENV_PATH) | ||
|
||
if not PROJECT_SHELL_SCRIPT.is_file() or not venv_up2date(): | ||
# Update pip | ||
verbose_check_call(PYTHON_PATH, '-m', 'pip', 'install', '-U', 'pip') | ||
|
||
# Install pip-tools | ||
verbose_check_call(PYTHON_PATH, '-m', 'pip', 'install', '-U', 'pip-tools') | ||
|
||
# install requirements via "pip-sync" | ||
verbose_check_call(PIP_SYNC_PATH, str(DEP_LOCK_PATH)) | ||
|
||
# install project | ||
verbose_check_call(PIP_PATH, 'install', '--no-deps', '-e', '.') | ||
store_dep_hash() | ||
|
||
# Call our entry point CLI: | ||
try: | ||
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:]) | ||
except subprocess.CalledProcessError as err: | ||
sys.exit(err.returncode) | ||
except KeyboardInterrupt: | ||
print('Bye!') | ||
sys.exit(130) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |
Oops, something went wrong.