Skip to content

Commit

Permalink
Merge pull request #30 from 6809/req_update_20231129-16
Browse files Browse the repository at this point in the history
Update requirements
  • Loading branch information
jedie authored Jan 17, 2024
2 parents 32010fd + f46add2 commit 6e6a786
Show file tree
Hide file tree
Showing 19 changed files with 779 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ max_line_length = 119
indent_style = tab
insert_final_newline = false

[*.yml]
[{*.yaml,*.yml}]
indent_size = 2
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.12", "3.11", "3.10", "3.9"]
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
steps:
- name: Checkout
run: |
Expand All @@ -34,7 +31,7 @@ jobs:
with:
python-version: '${{ matrix.python-version }}'
cache: 'pip' # caching pip dependencies
cache-dependency-path: '**/requirements.dev.txt'
cache-dependency-path: '**/requirements.*.txt'

- name: 'Bootstrap app venv'
# The first CLI call will create the .venv
Expand All @@ -59,6 +56,9 @@ jobs:
./dev-cli.py safety
- name: 'Run tests with Python v${{ matrix.python-version }}'
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
run: |
./dev-cli.py coverage
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.egg-info
__pycache__
/dist/
/build/
/coverage.*
*.orig

Expand Down
16 changes: 13 additions & 3 deletions MC6809/cli/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

import rich_click as click
from bx_py_utils.path import assert_is_file
from rich import print # noqa
from cli_base.cli_tools.version_info import print_version
from rich.console import Console
from rich.traceback import install as rich_traceback_install
from rich_click import RichGroup

import MC6809
from MC6809 import __version__, constants
from MC6809 import constants
from MC6809.core.bechmark import run_benchmark


Expand Down Expand Up @@ -96,7 +98,15 @@ def profile(loops, multiply):


def main():
print(f'[bold][green]MC6809[/green] v[cyan]{__version__}')
print_version(MC6809)

console = Console()
rich_traceback_install(
width=console.size.width, # full terminal width
show_locals=True,
suppress=[click],
max_frames=2,
)

# Execute Click CLI:
cli.name = './cli.py'
Expand Down
150 changes: 57 additions & 93 deletions MC6809/cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@

import rich_click as click
from bx_py_utils.path import assert_is_file
from cli_base.cli_tools import code_style
from cli_base.cli_tools.dev_tools import run_coverage, run_tox, run_unittest_cli
from cli_base.cli_tools.subprocess_utils import verbose_check_call
from cli_base.cli_tools.test_utils.snapshot import UpdateTestSnapshotFiles
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE
from cli_base.cli_tools.version_info import print_version
from manageprojects.utilities import code_style
from manageprojects.utilities.publish import publish_package
from rich import print # noqa; noqa
from rich.console import Console
from rich.traceback import install as rich_traceback_install
from rich_click import RichGroup

import MC6809
from MC6809 import constants
from MC6809.constants import BASE_PATH


logger = logging.getLogger(__name__)


PACKAGE_ROOT = Path(MC6809.__file__).parent.parent
assert_is_file(PACKAGE_ROOT / 'pyproject.toml')
PACKAGE_ROOT = BASE_PATH.parent
assert_is_file(PACKAGE_ROOT / 'pyproject.toml') # Exists only in cloned git repo


OPTION_ARGS_DEFAULT_TRUE = dict(is_flag=True, show_default=True, default=True)
OPTION_ARGS_DEFAULT_FALSE = dict(is_flag=True, show_default=True, default=False)
Expand Down Expand Up @@ -59,31 +65,15 @@ def cli():


@click.command()
@click.option('--verbose/--no-verbose', **OPTION_ARGS_DEFAULT_FALSE)
def mypy(verbose: bool = True):
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def mypy(verbosity: int):
"""Run Mypy (configured in pyproject.toml)"""
verbose_check_call('mypy', '.', cwd=PACKAGE_ROOT, verbose=verbose, exit_on_error=True)
verbose_check_call('mypy', '.', cwd=PACKAGE_ROOT, verbose=verbosity > 0, exit_on_error=True)


cli.add_command(mypy)


@click.command()
@click.option('--verbose/--no-verbose', **OPTION_ARGS_DEFAULT_FALSE)
def coverage(verbose: bool = True):
"""
Run and show coverage.
"""
verbose_check_call('coverage', 'run', verbose=verbose, exit_on_error=True)
verbose_check_call('coverage', 'combine', '--append', verbose=verbose, exit_on_error=True)
verbose_check_call('coverage', 'report', '--fail-under=30', verbose=verbose, exit_on_error=True)
verbose_check_call('coverage', 'xml', verbose=verbose, exit_on_error=True)
verbose_check_call('coverage', 'json', verbose=verbose, exit_on_error=True)


cli.add_command(coverage)


@click.command()
def install():
"""
Expand Down Expand Up @@ -163,7 +153,7 @@ def publish():
"""
Build and upload this project to PyPi
"""
_run_unittest_cli(verbose=False, exit_after_run=False) # Don't publish a broken state
run_unittest_cli(verbose=False, exit_after_run=False) # Don't publish a broken state

publish_package(
module=MC6809,
Expand All @@ -177,116 +167,79 @@ def publish():

@click.command()
@click.option('--color/--no-color', **OPTION_ARGS_DEFAULT_TRUE)
@click.option('--verbose/--no-verbose', **OPTION_ARGS_DEFAULT_FALSE)
def fix_code_style(color: bool = True, verbose: bool = False):
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def fix_code_style(color: bool, verbosity: int):
"""
Fix code style of all MC6809 source code files via darker
"""
code_style.fix(package_root=PACKAGE_ROOT, color=color, verbose=verbose)
code_style.fix(package_root=PACKAGE_ROOT, darker_color=color, darker_verbose=verbosity > 0)


cli.add_command(fix_code_style)


@click.command()
@click.option('--color/--no-color', **OPTION_ARGS_DEFAULT_TRUE)
@click.option('--verbose/--no-verbose', **OPTION_ARGS_DEFAULT_FALSE)
def check_code_style(color: bool = True, verbose: bool = False):
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def check_code_style(color: bool, verbosity: int):
"""
Check code style by calling darker + flake8
"""
code_style.check(package_root=PACKAGE_ROOT, color=color, verbose=verbose)
code_style.check(package_root=PACKAGE_ROOT, darker_color=color, darker_verbose=verbosity > 0)


cli.add_command(check_code_style)


@click.command()
def update_test_snapshot_files():
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def update_test_snapshot_files(verbosity: int):
"""
Update all test snapshot files (by remove and recreate all snapshot files)
"""

def iter_snapshot_files():
yield from PACKAGE_ROOT.rglob('*.snapshot.*')

removed_file_count = 0
for item in iter_snapshot_files():
item.unlink()
removed_file_count += 1
print(f'{removed_file_count} test snapshot files removed... run tests...')

# Just recreate them by running tests:
_run_unittest_cli(
extra_env=dict(
RAISE_SNAPSHOT_ERRORS='0', # Recreate snapshot files without error
),
verbose=False,
exit_after_run=False,
)

new_files = len(list(iter_snapshot_files()))
print(f'{new_files} test snapshot files created, ok.\n')
with UpdateTestSnapshotFiles(root_path=PACKAGE_ROOT, verbose=verbosity > 0):
# Just recreate them by running tests:
run_unittest_cli(
extra_env=dict(
RAISE_SNAPSHOT_ERRORS='0', # Recreate snapshot files without error
),
verbose=verbosity > 1,
exit_after_run=False,
)


cli.add_command(update_test_snapshot_files)


def _run_unittest_cli(extra_env=None, verbose=True, exit_after_run=True):
@click.command() # Dummy command
def test():
"""
Call the origin unittest CLI and pass all args to it.
Run unittests
"""
if extra_env is None:
extra_env = dict()
run_unittest_cli()

extra_env.update(
dict(
PYTHONUNBUFFERED='1',
PYTHONWARNINGS='always',
)
)

args = sys.argv[2:]
if not args:
if verbose:
args = ('--verbose', '--locals', '--buffer')
else:
args = ('--locals', '--buffer')

verbose_check_call(
sys.executable,
'-m',
'unittest',
*args,
timeout=15 * 60,
extra_env=extra_env,
)
if exit_after_run:
sys.exit(0)
cli.add_command(test)


@click.command() # Dummy command
def test():
def coverage():
"""
Run unittests
Run tests and show coverage report.
"""
_run_unittest_cli()
run_coverage()


cli.add_command(test)


def _run_tox():
verbose_check_call(sys.executable, '-m', 'tox', *sys.argv[2:])
sys.exit(0)
cli.add_command(coverage)


@click.command() # Dummy "tox" command
def tox():
"""
Run tox
"""
_run_tox()
run_tox()


cli.add_command(tox)
Expand All @@ -305,13 +258,24 @@ def version():
def main():
print_version(MC6809)

console = Console()
rich_traceback_install(
width=console.size.width, # full terminal width
show_locals=True,
suppress=[click],
max_frames=2,
)

if len(sys.argv) >= 2:
# Check if we just pass a command call
# Check if we can just pass a command call to origin CLI:
command = sys.argv[1]
if command == 'test':
_run_unittest_cli()
elif command == 'tox':
_run_tox()
command_map = {
'test': run_unittest_cli,
'tox': run_tox,
'coverage': run_coverage,
}
if real_func := command_map.get(command):
real_func(argv=sys.argv, exit_after_run=True)

# Execute Click CLI:
cli()
2 changes: 1 addition & 1 deletion MC6809/components/cpu_utils/Instruction_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def generate_code(f):
write_to_memory = mnemonic_data["write_to_memory"]
needs_ea = mnemonic_data["needs_ea"]
register = mnemonic_data["register"]
for op_code, op_data in list(mnemonic_data["ops"].items()):
for op_code, op_data in list(mnemonic_data["ops"].items()): # noqa: B007
addr_mode = op_data["addr_mode"]
# print(hex(op_code),

Expand Down
6 changes: 3 additions & 3 deletions MC6809/components/cpu_utils/instruction_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
def opcode(*opcodes):
"""A decorator for opcodes"""
def decorator(func):
setattr(func, "_is_opcode", True)
setattr(func, "_opcodes", opcodes)
func._is_opcode = True
func._opcodes = opcodes
return func
return decorator

Expand All @@ -44,7 +44,7 @@ def collect_ops(self):
continue

try:
opcodes = getattr(cls_method, "_opcodes")
opcodes = cls_method._opcodes
except AttributeError:
continue

Expand Down
3 changes: 2 additions & 1 deletion MC6809/components/mc6809_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__set_attr_dict()
warnings.warn(
"CPU TypeAssert used! (Should be only activated for debugging!)"
"CPU TypeAssert used! (Should be only activated for debugging!)",
stacklevel=2,
)

def __set_attr_dict(self):
Expand Down
7 changes: 7 additions & 0 deletions MC6809/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
from pathlib import Path

import MC6809


CLI_EPILOG = 'Project Homepage: https://github.com/6809/MC6809'

BASE_PATH = Path(MC6809.__file__).parent
Loading

0 comments on commit 6e6a786

Please sign in to comment.