From 2cc2f4f8487f807e7bc87d4c8f96e0e056109dfc Mon Sep 17 00:00:00 2001 From: argrento Date: Thu, 8 Jun 2023 14:15:26 +0200 Subject: [PATCH] main: add wheel build * rearrange folder structure * ci tests for wheel and module call --- .gitignore | 3 +- .woodpecker.yml | 49 ++++++++++++++++++-- README.md | 5 +- huami_token/__init__.py | 17 +++++++ huami_token/__main__.py | 8 ++++ errors.py => huami_token/errors.py | 0 huami_token.py => huami_token/huami_token.py | 15 ++++-- urls.py => huami_token/urls.py | 0 pyproject.toml | 33 +++++++++++++ 9 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 huami_token/__init__.py create mode 100644 huami_token/__main__.py rename errors.py => huami_token/errors.py (100%) rename huami_token.py => huami_token/huami_token.py (98%) rename urls.py => huami_token/urls.py (100%) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index e9b78c9..555c55f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ __pycache__ *.fw *.bin venv -.mypy_cache \ No newline at end of file +.mypy_cache +dist \ No newline at end of file diff --git a/.woodpecker.yml b/.woodpecker.yml index bcdea79..6e77512 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -9,7 +9,7 @@ pipeline: - python -m pip install pylint flake8 mypy>=0.971 - python -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - mypy --strict ./ - - python -m pylint -f parseable ./*.py + - python -m pylint -f parseable huami_token/*.py unit_tests: image: python:${TAG}-buster @@ -24,9 +24,50 @@ pipeline: - pytest tests/ secrets: [ amazfit_email, amazfit_password ] + wheel_build: + image: python:${TAG}-buster + commands: + - python -m pip install --upgrade pip build wheel + - python -m pip install -r requirements.txt + - python -m build + + wheel_test: + image: python:${TAG}-buster + commands: + - python -m pip install --upgrade pip + - python -m pip install dist/*.whl + - python -m pip install pytest + - pytest tests/test_amazfit.py + - python -m huami_token -m amazfit -e $AMAZFIT_EMAIL -p $AMAZFIT_PASSWORD -b >/dev/null 2>&1 + secrets: [ amazfit_email, amazfit_password ] + + publish_release: + image: woodpeckerci/plugin-gitea-release + settings: + api_key: + from_secret: api_token + base_url: https://codeberg.org + files: + - "dist/*" + target: master + checksum: md5 + when: + event: tag + secrets: [ api_token ] + + upload_to_index: + image: python:3.8-buster + commands: + - python -m pip install twine + - python -m twine check dist/* + - python -m twine upload dist/* + when: + event: tag + secrets: [ twine_username, twine_password ] + matrix: TAG: - 3.8 - - 3.9 - - 3.10 - - 3.11 + # - 3.9 + # - 3.10 + # - 3.11 diff --git a/README.md b/README.md index 06b4036..f3e27a9 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,8 @@ because only this login methods are supported. If not, create new Amazfit accoun with e-mail and password. 2. Pair, sync and update your watch with Amazfit App. Your pairing key will be stored on Huami servers. -3. Clone this repo: -```git clone https://codeberg.org/argrento/huami-token.git``` -4. Install requirements: `pip3 install -r requirements.txt` +3. `pip3 install huami_token` +4. Use like this: `python3 -m huami_token ...` ## Usage ``` diff --git a/huami_token/__init__.py b/huami_token/__init__.py new file mode 100644 index 0000000..0375218 --- /dev/null +++ b/huami_token/__init__.py @@ -0,0 +1,17 @@ +""" +The huami_token module provides functionalities to retrieve the Bluetooth +access token for the watch or band from Huami servers and also to download the +AGPS data packs, cep_alm_pak.zip and cep_7days.zip. + +This module consists of the following main components: +- HuamiAmazfit: A class that encapsulates all the operations related to + token retrieval and AGPS data downloading. +- ERRORS: A dictionary mapping error codes to their descriptions. +- URLS, PAYLOADS: Constants used for making requests to Huami servers. +""" + +from .huami_token import HuamiAmazfit +from .errors import ERRORS +from .urls import URLS, PAYLOADS + +__all__ = ["HuamiAmazfit", "ERRORS", "URLS", "PAYLOADS"] diff --git a/huami_token/__main__.py b/huami_token/__main__.py new file mode 100644 index 0000000..007b039 --- /dev/null +++ b/huami_token/__main__.py @@ -0,0 +1,8 @@ +""" +Entry point when using huami_token as a module +""" + +from .huami_token import main + +if __name__ == "__main__": + main() diff --git a/errors.py b/huami_token/errors.py similarity index 100% rename from errors.py rename to huami_token/errors.py diff --git a/huami_token.py b/huami_token/huami_token.py similarity index 98% rename from huami_token.py rename to huami_token/huami_token.py index 7999d59..60d90f9 100644 --- a/huami_token.py +++ b/huami_token/huami_token.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -# pylint: disable=too-many-instance-attributes -# pylint: disable=invalid-name +# pylint: disable=too-many-instance-attributes, too-many-branches +# pylint: disable=invalid-name, too-many-statements, too-many-locals +# pylint: disable=too-many-nested-blocks # Copyright (c) 2020 Kirill Snezhko # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -31,8 +32,7 @@ import zlib import requests -import errors -import urls +from . import errors, urls def encode_uint32(value: int) -> bytes: """Convert 4-bytes value into a list with 4 bytes""" @@ -295,7 +295,8 @@ class HuamiAmazfit: return result -if __name__ == "__main__": +def main() -> None: + """ Main Entry Point """ parser = argparse.ArgumentParser(description="Obtain Bluetooth Auth key from Amazfit " "servers and download AGPS data.") parser.add_argument("-m", @@ -417,3 +418,7 @@ if __name__ == "__main__": print("\nLogged out.") else: print("\nError logging out.") + + +if __name__ == "__main__": + main() diff --git a/urls.py b/huami_token/urls.py similarity index 100% rename from urls.py rename to huami_token/urls.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..707cd03 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +requires = ["flit_core>=3.4"] +build-backend = "flit_core.buildapi" + +[project] +name = "huami_token" +version = "0.7" +authors = [ + { name="Kirill Snezhko", email="kirill.snezhko@pm.me" }, +] +description = "This script retrieves the Bluetooth access token for the watch or band from Huami servers. Additionally, it downloads the AGPS data packs, cep_alm_pak.zip and cep_7days.zip." +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +dependencies = [ + "requests == 2.25.1", + "types-requests == 2.25.1" +] + +[project.urls] +"Homepage" = "https://codeberg.org/argrento/huami-token" +"Bug Tracker" = "https://codeberg.org/argrento/huami-token/issues" + +[project.scripts] +huami_token = "huami_token:main" + + +[project.optional-dependencies] +test = ["pytest-pylint==0.18.0", "pytest-flake8==1.0.6"]