Skip to content

Commit

Permalink
Update requirements adn split CLI code
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Jul 12, 2024
1 parent 0d67333 commit d5f7f11
Show file tree
Hide file tree
Showing 29 changed files with 1,193 additions and 1,121 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ max_line_length = 119
indent_style = tab
insert_final_newline = false

[*.yml]
indent_size = 2

[*.yaml]
[{*.yaml,*.yml}]
indent_size = 2
27 changes: 17 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.10", "3.9"]
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
python-version: ["3.12", "3.11", "3.10", "3.9"]
steps:
- name: Checkout
run: |
echo $GITHUB_REF $GITHUB_SHA
git clone --depth 1 https://github.com/$GITHUB_REPOSITORY.git .
git clone https://github.com/$GITHUB_REPOSITORY.git .
git fetch origin $GITHUB_SHA:temporary-ci-branch
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
Expand All @@ -34,25 +31,35 @@ 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'
- name: 'Bootstrap app venv'
# The first CLI call will create the .venv
run: |
./cli.py version
- name: 'app CLI help'
run: |
./cli.py --help
- name: 'Bootstrap dev venv'
# The first CLI call will create the .venv
run: |
./dev-cli.py version
./dev-cli.py create-default-settings
./cli.py version
- name: 'CLI help'
- name: 'dev CLI help'
run: |
./dev-cli.py --help
./cli.py --help
- name: 'Safety'
run: |
./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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
*.egg-info
__pycache__
/dist/
/coverage.json
/coverage.xml
/build/
/coverage.*
*.orig

!.github
!.editorconfig
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style Check code style by calling darker + flake8 │
│ coverage Run and show coverage.
│ coverage Run tests and show coverage report.
│ create-default-settings Create a default user settings file. (Used by CI pipeline ;) │
│ fix-code-style Fix code style of all inverter source code files via darker │
│ install Run pip-sync and install 'inverter' via pip as editable. │
│ 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) │
│ publish Build and upload this project to PyPi │
│ safety Run safety check against current requirements files │
Expand Down
9 changes: 5 additions & 4 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import hashlib
import shlex
import subprocess
import sys
import venv
Expand All @@ -32,7 +33,7 @@ def print_no_pip_error():
sys.exit(-1)


assert sys.version_info >= (3, 9), 'Python version is too old!'
assert sys.version_info >= (3, 9), f'Python version {sys.version_info} is too old!'


if sys.platform == 'win32': # wtf
Expand Down Expand Up @@ -60,7 +61,7 @@ def print_no_pip_error():


def get_dep_hash():
"""Get SHA512 hash from poetry.lock content."""
"""Get SHA512 hash from lock file content."""
return hashlib.sha512(DEP_LOCK_PATH.read_bytes()).hexdigest()


Expand All @@ -77,7 +78,7 @@ def venv_up2date():


def verbose_check_call(*popen_args):
print(f'\n+ {" ".join(str(arg) for arg in popen_args)}\n')
print(f'\n+ {shlex.join(str(arg) for arg in popen_args)}\n')
return subprocess.check_call(popen_args)


Expand Down Expand Up @@ -106,7 +107,7 @@ def main(argv):

# Call our entry point CLI:
try:
verbose_check_call(PROJECT_SHELL_SCRIPT, *sys.argv[1:])
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:])
except subprocess.CalledProcessError as err:
sys.exit(err.returncode)

Expand Down
9 changes: 5 additions & 4 deletions dev-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import hashlib
import shlex
import subprocess
import sys
import venv
Expand All @@ -32,7 +33,7 @@ def print_no_pip_error():
sys.exit(-1)


assert sys.version_info >= (3, 9), 'Python version is too old!'
assert sys.version_info >= (3, 9), f'Python version {sys.version_info} is too old!'


if sys.platform == 'win32': # wtf
Expand Down Expand Up @@ -60,7 +61,7 @@ def print_no_pip_error():


def get_dep_hash():
"""Get SHA512 hash from poetry.lock content."""
"""Get SHA512 hash from lock file content."""
return hashlib.sha512(DEP_LOCK_PATH.read_bytes()).hexdigest()


Expand All @@ -77,7 +78,7 @@ def venv_up2date():


def verbose_check_call(*popen_args):
print(f'\n+ {" ".join(str(arg) for arg in popen_args)}\n')
print(f'\n+ {shlex.join(str(arg) for arg in popen_args)}\n')
return subprocess.check_call(popen_args)


Expand Down Expand Up @@ -106,7 +107,7 @@ def main(argv):

# Call our entry point CLI:
try:
verbose_check_call(PROJECT_SHELL_SCRIPT, *sys.argv[1:])
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:])
except subprocess.CalledProcessError as err:
sys.exit(err.returncode)

Expand Down
2 changes: 1 addition & 1 deletion energymeter2mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Get values from modbus energy meter to MQTT / HomeAssistant
"""

__version__ = '0.2.0'
__version__ = '0.3.0'
__author__ = 'Jens Diemer <git@jensdiemer.de>'
6 changes: 1 addition & 5 deletions energymeter2mqtt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"""


from energymeter2mqtt.cli import cli_app


def main():
cli_app.main()
from energymeter2mqtt.cli_app import main


if __name__ == '__main__':
Expand Down
Empty file removed energymeter2mqtt/cli/__init__.py
Empty file.
Loading

0 comments on commit d5f7f11

Please sign in to comment.