Skip to content

Commit

Permalink
Merge pull request #2 from 6809/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jedie authored Sep 24, 2024
2 parents faa4011 + e3fa631 commit bd215ae
Show file tree
Hide file tree
Showing 46 changed files with 3,181 additions and 1,308 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .editorconfig
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
7 changes: 7 additions & 0 deletions .flake8
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
53 changes: 15 additions & 38 deletions .gitignore
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
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
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
13 changes: 13 additions & 0 deletions .pre-commit-hooks.yaml
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]
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

8 changes: 0 additions & 8 deletions MANIFEST.in

This file was deleted.

60 changes: 0 additions & 60 deletions README.creole

This file was deleted.

26 changes: 26 additions & 0 deletions README.md
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
```
119 changes: 119 additions & 0 deletions cli.py
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)
Loading

0 comments on commit bd215ae

Please sign in to comment.