Skip to content

Commit

Permalink
Update project setup + Use humanize from MC6809
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Sep 24, 2024
1 parent fdd42fa commit e56151b
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 430 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.11", "3.10", "3.9"]
python-version: ["3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand All @@ -26,7 +26,7 @@ jobs:
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
- name: 'Set up Python ${{ matrix.python-version }}'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
# https://github.com/marketplace/actions/setup-python
with:
python-version: '${{ matrix.python-version }}'
Expand Down Expand Up @@ -63,9 +63,13 @@ jobs:
run: |
./cli.py download-roms
- name: 'Safety'
- name: 'dev CLI help'
run: |
./dev-cli.py --help
- name: 'Run pip-audit'
run: |
./dev-cli.py safety
./dev-cli.py pip-audit
- name: 'Run tests with Python v${{ matrix.python-version }}'
env:
Expand All @@ -75,7 +79,7 @@ jobs:
./dev-cli.py coverage
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
# https://github.com/marketplace/actions/codecov
with:
fail_ci_if_error: false
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ download-roms Download/Test only ROM files │
│ editor Run only the BASIC editor │
│ gui <<< **start this** - Start the DragonPy tkinter starter GUI │
│ log-list List all exiting loggers and exit. │
│ run Run a machine emulation │
│ version Print version and exit │
│ download-roms Download/Test only ROM files │
│ editor Run only the BASIC editor │
│ gui <<< **start this** - Start the DragonPy tkinter starter GUI │
│ log-list List all exiting loggers and exit. │
│ run Run a machine emulation │
│ update-readme-history Update project history base on git commits/tags in README.md │
│ version Print version and exit │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```
[comment]: <> (✂✂✂ auto generated main help end ✂✂✂)
Expand Down Expand Up @@ -184,8 +185,8 @@ Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
│ fix-code-style Fix code style of all cli_base source code files via darker │
│ install Run pip-sync and install 'cli_base' via pip as editable. │
│ mypy Run Mypy (configured in pyproject.toml) │
│ pip-audit Run pip-audit check against current requirements files │
│ publish Build and upload this project to PyPi │
│ safety Run safety check against current requirements files │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
Expand Down Expand Up @@ -465,6 +466,9 @@ To make a new release, do this:

[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [v0.9.3](https://github.com/jedie/DragonPy/compare/v0.9.2...v0.9.3)
* 2024-09-24 - Update project setup + Use humanize from MC6809
* 2024-09-24 - Update requirements
* [v0.9.2](https://github.com/jedie/DragonPy/compare/v0.9.1...v0.9.2)
* 2024-04-16 - Bugfix packaging
* 2024-04-16 - Update requirements and apply manageproject updates
Expand All @@ -485,6 +489,9 @@ To make a new release, do this:
* 2023-08-05 - Split CLI and dev-CLI + remove Python 3.9 support
* 2023-03-07 - update requirements
* 2023-03-07 - Update README

<details><summary>Expand older history entries ...</summary>

* [v0.8.0](https://github.com/jedie/DragonPy/compare/v0.7.0...v0.8.0)
* 2023-03-07 - Update README.md
* 2023-03-06 - Migrate to pip-tools via https://github.com/jedie/manageprojects
Expand Down Expand Up @@ -514,9 +521,6 @@ To make a new release, do this:
* 2022-01-30 - remove nose test from CLI
* 2022-01-30 - Use dev-shell
* 2022-01-30 - Cache pip+roms

<details><summary>Expand older history entries ...</summary>

* [v0.7.0](https://github.com/jedie/DragonPy/compare/v0.6.0...v0.7.0)
* 2020-10-01 - update README
* 2020-10-01 - Update windows tk work-a-round: https://github.com/pypa/virtualenv/issues/93
Expand Down
13 changes: 8 additions & 5 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def print_no_pip_error():
BIN_NAME = 'Scripts'
FILE_EXT = '.exe'
else:
# Files under Linux/Mac and all other than Windows, e.g.: .../.venv/bin/python
# 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'python{FILE_EXT}'
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}'

Expand Down Expand Up @@ -87,17 +87,17 @@ def main(argv):

# Create virtual env in ".venv/":
if not PYTHON_PATH.is_file():
print('Create virtual env here:', VENV_PATH.absolute())
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')

if not PIP_SYNC_PATH.is_file():
# Install pip-tools
verbose_check_call(PYTHON_PATH, '-m', 'pip', 'install', '-U', 'pip-tools')

if not PROJECT_SHELL_SCRIPT.is_file() or not venv_up2date():
# install requirements via "pip-sync"
verbose_check_call(PIP_SYNC_PATH, str(DEP_LOCK_PATH))

Expand All @@ -110,6 +110,9 @@ def main(argv):
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__':
Expand Down
11 changes: 8 additions & 3 deletions dev-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def print_no_pip_error():
BIN_NAME = 'Scripts'
FILE_EXT = '.exe'
else:
# Files under Linux/Mac and all other than Windows, e.g.: .../.venv/bin/python
# 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'
BIN_PATH = VENV_PATH / BIN_NAME
PYTHON_PATH = BIN_PATH / f'python{FILE_EXT}'
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}'

Expand Down Expand Up @@ -87,9 +87,11 @@ def main(argv):

# Create virtual env in ".venv/":
if not PYTHON_PATH.is_file():
print('Create virtual env here:', VENV_PATH.absolute())
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')

Expand All @@ -110,6 +112,9 @@ def main(argv):
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__':
Expand Down
2 changes: 1 addition & 1 deletion dragonpy/Dragon32/MC6821_PIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from dragonpy import constants
from dragonpy.utils.bits import is_bit_set, set_bit
from dragonpy.utils.humanize import byte2bit_string
from MC6809.utils.humanize import byte2bit_string


log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion dragonpy/Dragon32/mem_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from MC6809.core.memory_info import BaseMemoryInfo

from dragonpy.utils.humanize import nice_hex
from MC6809.utils.humanize import nice_hex


log = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion dragonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from dragonpy.vectrex.machine import run_Vectrex


__version__ = '0.9.2'
# See https://packaging.python.org/en/latest/specifications/version-specifiers/
__version__ = '0.9.3'
__author__ = 'Jens Diemer <[email protected]>'


Expand Down
27 changes: 27 additions & 0 deletions dragonpy/cli_app/update_readme_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

import rich_click as click
from cli_base.cli_tools import git_history
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE, setup_logging
from rich import print # noqa

from dragonpy.cli_app import cli


@cli.command()
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def update_readme_history(verbosity: int):
"""
Update project history base on git commits/tags in README.md
Will be exited with 1 if the README.md was updated otherwise with 0.
Also, callable via e.g.:
python -m cli_base update-readme-history -v
"""
setup_logging(verbosity=verbosity)
updated = git_history.update_readme_history(verbosity=verbosity)
exit_code = 1 if updated else 0
if verbosity:
print(f'{exit_code=}')
sys.exit(exit_code)
21 changes: 9 additions & 12 deletions dragonpy/cli_dev/packaging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sys
from pathlib import Path

import click
from cli_base.cli_tools.dev_tools import run_unittest_cli
from cli_base.cli_tools.subprocess_utils import verbose_check_call
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE
from cli_base.run_pip_audit import run_pip_audit
from manageprojects.utilities.publish import publish_package

import dragonpy
Expand All @@ -19,11 +22,12 @@ def install():


@cli.command()
def safety():
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def pip_audit(verbosity: int):
"""
Run safety check against current requirements files
Run pip-audit check against current requirements files
"""
verbose_check_call('safety', 'check', '-r', 'requirements.dev.txt')
run_pip_audit(base_path=PACKAGE_ROOT, verbosity=verbosity)


@cli.command()
Expand All @@ -40,14 +44,7 @@ def update():
CUSTOM_COMPILE_COMMAND='./dev-cli.py update',
)

pip_compile_base = [
bin_path / 'pip-compile',
'--verbose',
'--allow-unsafe', # https://pip-tools.readthedocs.io/en/latest/#deprecations
'--resolver=backtracking', # https://pip-tools.readthedocs.io/en/latest/#deprecations
'--upgrade',
'--generate-hashes',
]
pip_compile_base = [bin_path / 'pip-compile', '--verbose', '--upgrade']

# Only "prod" dependencies:
verbose_check_call(
Expand All @@ -68,7 +65,7 @@ def update():
extra_env=extra_env,
)

verbose_check_call(bin_path / 'safety', 'check', '-r', 'requirements.dev.txt')
run_pip_audit(base_path=PACKAGE_ROOT)

# Install new dependencies in current .venv:
verbose_check_call(bin_path / 'pip-sync', 'requirements.dev.txt')
Expand Down
5 changes: 2 additions & 3 deletions dragonpy/core/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
from tkinter import font as TkFont
from tkinter import messagebox, scrolledtext

from dragonlib.utils.auto_shift import invert_shift

import dragonpy
from basic_editor.editor import EditorWindow
from dragonlib.utils.auto_shift import invert_shift
from dragonpy.core.gui_starter import MultiStatusBar
from dragonpy.Dragon32.gui_config import BaseTkinterGUIConfig, RuntimeCfg
from dragonpy.Dragon32.keyboard_map import add_to_input_queue, inkey_from_tk_event
from dragonpy.Dragon32.MC6847 import MC6847_TextModeCanvas
from dragonpy.utils.humanize import get_python_info, locale_format_number
from MC6809.utils.humanize import get_python_info, locale_format_number


log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion dragonpy/core/gui_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from dragonpy import constants
from dragonpy.constants import VERBOSITY_DEFAULT, VERBOSITY_DICT2, VERBOSITY_STRINGS
from dragonpy.core.configs import machine_dict
from dragonpy.utils.humanize import get_python_info
from MC6809.core.bechmark import run_benchmark
from MC6809.utils.humanize import get_python_info


DEFAULT_LOOPS = 5
Expand Down
2 changes: 1 addition & 1 deletion dragonpy/sbc09/create_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from MC6809.components.MC6809data.MC6809_data_utils import MC6809OP_DATA_DICT

from dragonpy.sbc09.mem_info import SBC09MemInfo
from dragonpy.utils.humanize import cc_value2txt
from MC6809.utils.humanize import cc_value2txt


def proc_killer(proc, timeout):
Expand Down
19 changes: 3 additions & 16 deletions dragonpy/tests/test_readme_history.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
from unittest import TestCase

from bx_py_utils.auto_doc import assert_readme_block
from cli_base.cli_tools.git_history import get_git_history

import dragonpy
from dragonpy.cli_dev import PACKAGE_ROOT
from cli_base.cli_tools import git_history


class ReadmeHistoryTestCase(TestCase):
def test_readme_history(self):
git_history = get_git_history(
current_version=dragonpy.__version__,
add_author=False,
)
history = '\n'.join(git_history)
assert_readme_block(
readme_path=PACKAGE_ROOT / 'README.md',
text_block=f'\n{history}\n',
start_marker_line='[comment]: <> (✂✂✂ auto generated history start ✂✂✂)',
end_marker_line='[comment]: <> (✂✂✂ auto generated history end ✂✂✂)',
)
updated = git_history.update_readme_history(verbosity=2)
self.assertFalse(updated, 'README.md was not updated: Commit changes!')
Loading

0 comments on commit e56151b

Please sign in to comment.