diff --git a/.github/workflows/generate-monorepo-manager.yml b/.github/workflows/generate-monorepo-manager.yml index c680e4c2..ca6d9e3f 100644 --- a/.github/workflows/generate-monorepo-manager.yml +++ b/.github/workflows/generate-monorepo-manager.yml @@ -47,84 +47,83 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - - - uses: actions/checkout@v4 - name: Set up - Checkout lib/py_monorepo_manager - with: - ref: ${{ github.head_ref }} - token: ${{ secrets.WORKFLOW_TOKEN }} - - # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow - # from installing Poetry every time, which can be slow. Note the use of the Poetry version - # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache - # manually if/when you want to upgrade Poetry, or if something goes wrong. This could be - # mildly cleaner by using an environment variable, but I don't really care. - - name: Set up - Cache Poetry 1.7.1 - uses: actions/cache@v4 - with: - path: ~/.local - key: python-3.11-poetry-1.7.1 - - # If you wanted to use multiple Python versions, you'd have specify a matrix in the job and - # reference the matrix python version here. - - uses: actions/setup-python@v5 - name: Set up - Install Python 3.11 - with: - python-version: 3.11 - - # Install Poetry. You could do this manually, or there are several actions that do this. - # `snok/install-poetry` seems to be minimal yet complete, and really just calls out to - # Poetry's default install script, which feels correct. I pin the Poetry version here - # because Poetry does occasionally change APIs between versions and I don't want my - # actions to break if it does. - # - # The key configuration value here is `virtualenvs-in-project: true`: this creates the - # venv as a `.venv` in your testing directory, which allows the next step to easily - # cache it. - - name: Set up - Install Poetry 1.7.1 - uses: snok/install-poetry@v1 - with: - version: 1.7.1 - virtualenvs-create: true - virtualenvs-in-project: true - - # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache - # key: if you're using multiple Python versions, or multiple OSes, you'd need to include - # them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock. - - name: Set up - Cache lib/py_monorepo_manager dependencies - id: cache-deps - uses: actions/cache@v4 - with: - path: ./lib/py_monorepo_manager/.venv - key: py_monorepo_manager-${{ hashFiles('./lib/py_monorepo_manager/poetry.lock', './lib/py_dev_dependencies/**/*.py', './lib/py_dev_dependencies/**/*.sql', './lib/py_dev_dependencies/poetry.lock')}}-3.11-1.7.1 - - # Install dependencies. `--no-root` means "install all dependencies but not the project - # itself", which is what you want to avoid caching _your_ code. The `if` statement - # ensures this only runs on a cache miss. - - name: Set up - Install lib/py_monorepo_manager dependencies - run: poetry install --no-interaction --no-root --all-extras - working-directory: ./lib/py_monorepo_manager - - - name: generate files - # always run poetry install to ensure the entrypoint is up to date - run: poetry install && poetry run monorepo_manager all - working-directory: ./lib/py_monorepo_manager - - - name: Add add new workflow files - run: git add ./.github/workflows/* - - - name: Add add new library files - run: git add ./lib/* - - - name: Add add new service files - run: git add ./services/* - - - name: Add add new script files - run: git add ./scripts/* - - - uses: actions-js/push@master - name: Push changes - with: - github_token: ${{ secrets.WORKFLOW_TOKEN }} - branch: ${{ github.head_ref }} - message: "Update monorepo boilerplate" + - uses: actions/checkout@v4 + name: Set up - Checkout lib/py_monorepo_manager + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.WORKFLOW_TOKEN }} + + # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow + # from installing Poetry every time, which can be slow. Note the use of the Poetry version + # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache + # manually if/when you want to upgrade Poetry, or if something goes wrong. This could be + # mildly cleaner by using an environment variable, but I don't really care. + - name: Set up - Cache Poetry 1.7.1 + uses: actions/cache@v4 + with: + path: ~/.local + key: python-3.11-poetry-1.7.1 + + # If you wanted to use multiple Python versions, you'd have specify a matrix in the job and + # reference the matrix python version here. + - uses: actions/setup-python@v5 + name: Set up - Install Python 3.11 + with: + python-version: 3.11 + + # Install Poetry. You could do this manually, or there are several actions that do this. + # `snok/install-poetry` seems to be minimal yet complete, and really just calls out to + # Poetry's default install script, which feels correct. I pin the Poetry version here + # because Poetry does occasionally change APIs between versions and I don't want my + # actions to break if it does. + # + # The key configuration value here is `virtualenvs-in-project: true`: this creates the + # venv as a `.venv` in your testing directory, which allows the next step to easily + # cache it. + - name: Set up - Install Poetry 1.7.1 + uses: snok/install-poetry@v1 + with: + version: 1.7.1 + virtualenvs-create: true + virtualenvs-in-project: true + + # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache + # key: if you're using multiple Python versions, or multiple OSes, you'd need to include + # them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock. + - name: Set up - Cache lib/py_monorepo_manager dependencies + id: cache-deps + uses: actions/cache@v4 + with: + path: ./lib/py_monorepo_manager/.venv + key: py_monorepo_manager-${{ hashFiles('./lib/py_monorepo_manager/poetry.lock', './lib/py_dev_dependencies/**/*.py', './lib/py_dev_dependencies/**/*.sql', './lib/py_dev_dependencies/poetry.lock')}}-3.11-1.7.1 + + # Install dependencies. `--no-root` means "install all dependencies but not the project + # itself", which is what you want to avoid caching _your_ code. The `if` statement + # ensures this only runs on a cache miss. + - name: Set up - Install lib/py_monorepo_manager dependencies + run: poetry install --no-interaction --no-root --all-extras + working-directory: ./lib/py_monorepo_manager + + - name: generate files + # always run poetry install to ensure the entrypoint is up to date + run: poetry install && poetry run monorepo_manager all + working-directory: ./lib/py_monorepo_manager + + - name: Add add new workflow files + run: git add ./.github/workflows/* + + - name: Add add new library files + run: git add ./lib/* + + - name: Add add new service files + run: git add ./services/* + + - name: Add add new script files + run: git add ./scripts/* + + - uses: actions-js/push@master + name: Push changes + with: + github_token: ${{ secrets.WORKFLOW_TOKEN }} + branch: ${{ github.head_ref }} + message: "Update monorepo boilerplate" diff --git a/.github/workflows/test-lib-py_carlos_database.yml b/.github/workflows/test-lib-py_carlos_database.yml index 99f0cd1c..a4215b4d 100644 --- a/.github/workflows/test-lib-py_carlos_database.yml +++ b/.github/workflows/test-lib-py_carlos_database.yml @@ -18,6 +18,7 @@ on: - .github/workflows/test-lib-py_carlos_database.yml - lib/py_carlos_database/** - lib/py_dev_dependencies/** + - lib/py_edge_interface/** workflow_dispatch: @@ -94,7 +95,7 @@ jobs: uses: actions/cache@v4 with: path: ./lib/py_carlos_database/.venv - key: py_carlos_database-${{ hashFiles('./lib/py_carlos_database/poetry.lock', './lib/py_dev_dependencies/**/*.py', './lib/py_dev_dependencies/**/*.sql', './lib/py_dev_dependencies/poetry.lock')}}-3.11-1.7.1 + key: py_carlos_database-${{ hashFiles('./lib/py_carlos_database/poetry.lock', './lib/py_dev_dependencies/**/*.py', './lib/py_edge_interface/**/*.py', './lib/py_dev_dependencies/**/*.sql', './lib/py_edge_interface/**/*.sql', './lib/py_dev_dependencies/poetry.lock', './lib/py_edge_interface/poetry.lock')}}-3.11-1.7.1 # Install dependencies. `--no-root` means "install all dependencies but not the project # itself", which is what you want to avoid caching _your_ code. The `if` statement @@ -147,3 +148,20 @@ jobs: message: "update lib/py_carlos_database" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_carlos_database/pyproject.toml + python_files: + - lib/py_carlos_database/carlos/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-lib-py_dev_dependencies.yml b/.github/workflows/test-lib-py_dev_dependencies.yml index 2ad52970..e283d802 100644 --- a/.github/workflows/test-lib-py_dev_dependencies.yml +++ b/.github/workflows/test-lib-py_dev_dependencies.yml @@ -146,3 +146,20 @@ jobs: message: "update lib/py_dev_dependencies" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_dev_dependencies/pyproject.toml + python_files: + - lib/py_dev_dependencies/devtools/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-lib-py_edge_device.yml b/.github/workflows/test-lib-py_edge_device.yml index f879aa0d..3c5a09a0 100644 --- a/.github/workflows/test-lib-py_edge_device.yml +++ b/.github/workflows/test-lib-py_edge_device.yml @@ -148,3 +148,20 @@ jobs: message: "update lib/py_edge_device" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_edge_device/pyproject.toml + python_files: + - lib/py_edge_device/carlos/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-lib-py_edge_interface.yml b/.github/workflows/test-lib-py_edge_interface.yml index 13138159..08d9c603 100644 --- a/.github/workflows/test-lib-py_edge_interface.yml +++ b/.github/workflows/test-lib-py_edge_interface.yml @@ -147,3 +147,20 @@ jobs: message: "update lib/py_edge_interface" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_edge_interface/pyproject.toml + python_files: + - lib/py_edge_interface/carlos/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-lib-py_edge_server.yml b/.github/workflows/test-lib-py_edge_server.yml index 40f0aa05..7ecc2543 100644 --- a/.github/workflows/test-lib-py_edge_server.yml +++ b/.github/workflows/test-lib-py_edge_server.yml @@ -18,6 +18,7 @@ on: - .github/workflows/test-lib-py_edge_server.yml - lib/py_edge_server/** - lib/py_edge_interface/** + - lib/py_carlos_database/** - lib/py_dev_dependencies/** - lib/py_edge_device/** @@ -96,7 +97,7 @@ jobs: uses: actions/cache@v4 with: path: ./lib/py_edge_server/.venv - key: py_edge_server-${{ hashFiles('./lib/py_edge_server/poetry.lock', './lib/py_edge_interface/**/*.py', './lib/py_dev_dependencies/**/*.py', './lib/py_edge_device/**/*.py', './lib/py_edge_interface/**/*.sql', './lib/py_dev_dependencies/**/*.sql', './lib/py_edge_device/**/*.sql', './lib/py_edge_interface/poetry.lock', './lib/py_dev_dependencies/poetry.lock', './lib/py_edge_device/poetry.lock')}}-3.11-1.7.1 + key: py_edge_server-${{ hashFiles('./lib/py_edge_server/poetry.lock', './lib/py_edge_interface/**/*.py', './lib/py_carlos_database/**/*.py', './lib/py_dev_dependencies/**/*.py', './lib/py_edge_device/**/*.py', './lib/py_edge_interface/**/*.sql', './lib/py_carlos_database/**/*.sql', './lib/py_dev_dependencies/**/*.sql', './lib/py_edge_device/**/*.sql', './lib/py_edge_interface/poetry.lock', './lib/py_carlos_database/poetry.lock', './lib/py_dev_dependencies/poetry.lock', './lib/py_edge_device/poetry.lock')}}-3.11-1.7.1 # Install dependencies. `--no-root` means "install all dependencies but not the project # itself", which is what you want to avoid caching _your_ code. The `if` statement @@ -149,3 +150,20 @@ jobs: message: "update lib/py_edge_server" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_edge_server/pyproject.toml + python_files: + - lib/py_edge_server/carlos/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-lib-py_monorepo_manager.yml b/.github/workflows/test-lib-py_monorepo_manager.yml index 02b20e1f..188ae66d 100644 --- a/.github/workflows/test-lib-py_monorepo_manager.yml +++ b/.github/workflows/test-lib-py_monorepo_manager.yml @@ -147,3 +147,20 @@ jobs: message: "update lib/py_monorepo_manager" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - lib/py_monorepo_manager/pyproject.toml + python_files: + - lib/py_monorepo_manager/monorepo_manager/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-services-api.yml b/.github/workflows/test-services-api.yml index 86c37d8b..5fd9ab1f 100644 --- a/.github/workflows/test-services-api.yml +++ b/.github/workflows/test-services-api.yml @@ -172,3 +172,20 @@ jobs: message: "update services/api" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - services/api/pyproject.toml + python_files: + - services/api/carlos/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.github/workflows/test-services-device.yml b/.github/workflows/test-services-device.yml index 339c296b..23e170d9 100644 --- a/.github/workflows/test-services-device.yml +++ b/.github/workflows/test-services-device.yml @@ -148,3 +148,20 @@ jobs: message: "update services/device" coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} + + - name: Set up - Get changed files for CHANGELOG.md + if: ${{ !cancelled() }} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - services/device/pyproject.toml + python_files: + - services/device/device/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 diff --git a/.monorepo_manager.yaml b/.monorepo_manager.yaml index 25e3500d..499f1f5a 100644 --- a/.monorepo_manager.yaml +++ b/.monorepo_manager.yaml @@ -40,6 +40,13 @@ services/api: language: python services/device: language: python + makefile: + config: + - poetry run python -m device.cli config create + config-show: + - poetry run python -m device.cli config show + run: + - poetry run python -m device.cli run services/frontend: language: javascript services/nginx: diff --git a/lib/py_edge_device/carlos/edge/device/retry.py b/lib/py_edge_device/carlos/edge/device/retry.py index b4a9c1c2..a932c40a 100644 --- a/lib/py_edge_device/carlos/edge/device/retry.py +++ b/lib/py_edge_device/carlos/edge/device/retry.py @@ -91,12 +91,11 @@ async def execute( while True: try: return await func() - except expected_exceptions as ex: + except expected_exceptions: logger.info( - f"Failed to run function: {func}.\n\n" - f"Exception: {''.join(traceback.format_exception(ex))}\n\n" - f"Retrying in {backoff_time}." + f"Failed to run function: {func}. Retrying in {backoff_time}." ) + logger.debug(traceback.format_exc()) await sleep(backoff_time.total_seconds()) diff --git a/lib/py_edge_device/carlos/edge/device/runtime.py b/lib/py_edge_device/carlos/edge/device/runtime.py index d8207c2b..14949287 100644 --- a/lib/py_edge_device/carlos/edge/device/runtime.py +++ b/lib/py_edge_device/carlos/edge/device/runtime.py @@ -1,10 +1,14 @@ """The runtime module contains the device runtime that is used as the main entry point of the application.""" +from datetime import timedelta +from pathlib import Path + from apscheduler import AsyncScheduler from apscheduler.triggers.interval import IntervalTrigger from carlos.edge.interface import EdgeConnectionDisconnected, EdgeProtocol from carlos.edge.interface.protocol import PING +from loguru import logger from .communication import DeviceCommunicationHandler from .config import DeviceConfig @@ -25,6 +29,13 @@ def __init__(self, config: DeviceConfig, protocol: EdgeProtocol): async def run(self): """Runs the device runtime.""" + logger.add( + sink=Path.cwd() / ".carlos_data" / "device" / "device_log_{time}.log", + level="INFO", + rotation="50 MB", + retention=timedelta(days=60), + ) + communication_handler = DeviceCommunicationHandler( protocol=self.protocol, device_id=self.config.device_id ) diff --git a/lib/py_edge_device/carlos/edge/device/update.py b/lib/py_edge_device/carlos/edge/device/update.py index 09928623..9dcf387b 100644 --- a/lib/py_edge_device/carlos/edge/device/update.py +++ b/lib/py_edge_device/carlos/edge/device/update.py @@ -40,7 +40,7 @@ def update_device(): # pragma: no cover logger.debug(process.stdout.decode("utf-8").strip()) # Restart the running process - logger.debug("Restarting the running process...") + logger.info("Restarting the running process...") os.execv(sys.executable, [sys.executable] + sys.argv) diff --git a/lib/py_edge_device/poetry.lock b/lib/py_edge_device/poetry.lock index 98e374dd..96ec1d33 100644 --- a/lib/py_edge_device/poetry.lock +++ b/lib/py_edge_device/poetry.lock @@ -79,33 +79,33 @@ tests-no-zope = ["attrs[tests-mypy]", "cloudpickle", "hypothesis", "pympler", "p [[package]] name = "black" -version = "24.3.0" +version = "24.4.0" description = "The uncompromising code formatter." optional = false python-versions = ">=3.8" files = [ - {file = "black-24.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395"}, - {file = "black-24.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995"}, - {file = "black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7"}, - {file = "black-24.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0"}, - {file = "black-24.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9"}, - {file = "black-24.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597"}, - {file = "black-24.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d"}, - {file = "black-24.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5"}, - {file = "black-24.3.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f"}, - {file = "black-24.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11"}, - {file = "black-24.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4"}, - {file = "black-24.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5"}, - {file = "black-24.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837"}, - {file = "black-24.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd"}, - {file = "black-24.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213"}, - {file = "black-24.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959"}, - {file = "black-24.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb"}, - {file = "black-24.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7"}, - {file = "black-24.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7"}, - {file = "black-24.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f"}, - {file = "black-24.3.0-py3-none-any.whl", hash = "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93"}, - {file = "black-24.3.0.tar.gz", hash = "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f"}, + {file = "black-24.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6ad001a9ddd9b8dfd1b434d566be39b1cd502802c8d38bbb1ba612afda2ef436"}, + {file = "black-24.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e3a3a092b8b756c643fe45f4624dbd5a389f770a4ac294cf4d0fce6af86addaf"}, + {file = "black-24.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dae79397f367ac8d7adb6c779813328f6d690943f64b32983e896bcccd18cbad"}, + {file = "black-24.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:71d998b73c957444fb7c52096c3843875f4b6b47a54972598741fe9a7f737fcb"}, + {file = "black-24.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:8e5537f456a22cf5cfcb2707803431d2feeb82ab3748ade280d6ccd0b40ed2e8"}, + {file = "black-24.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:64e60a7edd71fd542a10a9643bf369bfd2644de95ec71e86790b063aa02ff745"}, + {file = "black-24.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cd5b4f76056cecce3e69b0d4c228326d2595f506797f40b9233424e2524c070"}, + {file = "black-24.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:64578cf99b6b46a6301bc28bdb89f9d6f9b592b1c5837818a177c98525dbe397"}, + {file = "black-24.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f95cece33329dc4aa3b0e1a771c41075812e46cf3d6e3f1dfe3d91ff09826ed2"}, + {file = "black-24.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4396ca365a4310beef84d446ca5016f671b10f07abdba3e4e4304218d2c71d33"}, + {file = "black-24.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:44d99dfdf37a2a00a6f7a8dcbd19edf361d056ee51093b2445de7ca09adac965"}, + {file = "black-24.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:21f9407063ec71c5580b8ad975653c66508d6a9f57bd008bb8691d273705adcd"}, + {file = "black-24.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:652e55bb722ca026299eb74e53880ee2315b181dfdd44dca98e43448620ddec1"}, + {file = "black-24.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7f2966b9b2b3b7104fca9d75b2ee856fe3fdd7ed9e47c753a4bb1a675f2caab8"}, + {file = "black-24.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1bb9ca06e556a09f7f7177bc7cb604e5ed2d2df1e9119e4f7d2f1f7071c32e5d"}, + {file = "black-24.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:d4e71cdebdc8efeb6deaf5f2deb28325f8614d48426bed118ecc2dcaefb9ebf3"}, + {file = "black-24.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6644f97a7ef6f401a150cca551a1ff97e03c25d8519ee0bbc9b0058772882665"}, + {file = "black-24.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:75a2d0b4f5eb81f7eebc31f788f9830a6ce10a68c91fbe0fade34fff7a2836e6"}, + {file = "black-24.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb949f56a63c5e134dfdca12091e98ffb5fd446293ebae123d10fc1abad00b9e"}, + {file = "black-24.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:7852b05d02b5b9a8c893ab95863ef8986e4dda29af80bbbda94d7aee1abf8702"}, + {file = "black-24.4.0-py3-none-any.whl", hash = "sha256:74eb9b5420e26b42c00a3ff470dc0cd144b80a766128b1771d07643165e08d0e"}, + {file = "black-24.4.0.tar.gz", hash = "sha256:f07b69fda20578367eaebbd670ff8fc653ab181e1ff95d84497f9fa20e7d0641"}, ] [package.dependencies] diff --git a/lib/py_edge_device/pyproject.toml b/lib/py_edge_device/pyproject.toml index fc71ba4b..de3e1ec8 100644 --- a/lib/py_edge_device/pyproject.toml +++ b/lib/py_edge_device/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "carlos.edge.device" -version = "0.1.0" +version = "0.1.1" description = "The library for the edge device of the carlos project." authors = ["Felix Fanghanel"] license = "MIT" diff --git a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/ci.install_workflow.yml.jinja2 b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/ci.install_workflow.yml.jinja2 index 903a0592..a3de55c2 100644 --- a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/ci.install_workflow.yml.jinja2 +++ b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/ci.install_workflow.yml.jinja2 @@ -1,4 +1,4 @@ {% extends "ci.install.yml.jinja2" %} {%- block checkout_with %} -token: {% raw %}${{ secrets.WORKFLOW_TOKEN }}{% endraw %} + token: {% raw %}${{ secrets.WORKFLOW_TOKEN }}{% endraw %} {%- endblock %} diff --git a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/generate-monorepo-manager.yml.jinja2 b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/generate-monorepo-manager.yml.jinja2 index cdc0856e..8b1e6707 100644 --- a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/generate-monorepo-manager.yml.jinja2 +++ b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/generate-monorepo-manager.yml.jinja2 @@ -47,32 +47,31 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - {% macro include_runtime_install() %}{% include "ci.install_workflow.yml.jinja2" %}{% endmacro %} - {{ include_runtime_install()|indent(6) }} + {% include "ci.install_workflow.yml.jinja2" %} - - name: generate files - # always run poetry install to ensure the entrypoint is up to date - run: poetry install && poetry run monorepo_manager all - working-directory: ./{{ project.path_from_root }} + - name: generate files + # always run poetry install to ensure the entrypoint is up to date + run: poetry install && poetry run monorepo_manager all + working-directory: ./{{ project.path_from_root }} - - name: Add add new workflow files - run: git add ./.github/workflows/* + - name: Add add new workflow files + run: git add ./.github/workflows/* - - name: Add add new library files - run: git add ./lib/* + - name: Add add new library files + run: git add ./lib/* - - name: Add add new service files - run: git add ./services/* + - name: Add add new service files + run: git add ./services/* - - name: Add add new script files - run: git add ./scripts/* + - name: Add add new script files + run: git add ./scripts/* {%- raw %} - - uses: actions-js/push@master - name: Push changes - with: - github_token: ${{ secrets.WORKFLOW_TOKEN }} - branch: ${{ github.head_ref }} - message: "Update monorepo boilerplate" + - uses: actions-js/push@master + name: Push changes + with: + github_token: ${{ secrets.WORKFLOW_TOKEN }} + branch: ${{ github.head_ref }} + message: "Update monorepo boilerplate" {%- endraw %} diff --git a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/github-action-python.yml.jinja2 b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/github-action-python.yml.jinja2 index 88db34cd..b4de160f 100644 --- a/lib/py_monorepo_manager/monorepo_manager/language/python/templates/github-action-python.yml.jinja2 +++ b/lib/py_monorepo_manager/monorepo_manager/language/python/templates/github-action-python.yml.jinja2 @@ -123,4 +123,21 @@ jobs: coauthor_email: ${{ github.event.pull_request.user.login }}@users.noreply.github.com coauthor_name: ${{ github.event.pull_request.user.login }} {%- endraw %} + + - name: Set up - Get changed files for CHANGELOG.md + if: {% raw %}${{ !cancelled() }}{% endraw %} + id: detect-changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + pyproject_toml: + - {{ project.path_from_root }}/pyproject.toml + python_files: + - {{ project.path_from_root }}/{{ project.root_package_name }}/**/*.py + - name: Test - Version bump + # This step will fail if there are python files changed but the version in pyproject.toml is not updated + if: (steps.detect-changed-files.outputs.python_files_any_changed == 'true') && (steps.detect-changed-files.outputs.pyproject_toml_any_changed == 'false') && !cancelled() + run: | + echo "No changes in pyproject.toml but there are changes in python files. Please update the version in pyproject.toml if the code changes. Otherwise the automatic update of the carlos device may fail." + exit 1 {% endif %} \ No newline at end of file diff --git a/scripts/update_all_python_venvs.sh b/scripts/update_all_python_venvs.sh index 34e9dced..77f2627e 100644 --- a/scripts/update_all_python_venvs.sh +++ b/scripts/update_all_python_venvs.sh @@ -11,8 +11,8 @@ update_venv(){ # the order is important update_venv lib/py_dev_dependencies -update_venv lib/py_carlos_database update_venv lib/py_edge_interface +update_venv lib/py_carlos_database update_venv lib/py_edge_device update_venv lib/py_edge_server update_venv lib/py_monorepo_manager diff --git a/services/device/Makefile b/services/device/Makefile index 44f8a217..61c547ad 100644 --- a/services/device/Makefile +++ b/services/device/Makefile @@ -50,3 +50,11 @@ ci-check: make mypy make pytest make coverage + + +config: + poetry run python -m device.cli config create +config-show: + poetry run python -m device.cli config show +run: + poetry run python -m device.cli run diff --git a/services/device/carlos_device.service b/services/device/carlos_device.service new file mode 100644 index 00000000..3c1ffac0 --- /dev/null +++ b/services/device/carlos_device.service @@ -0,0 +1,13 @@ +[Unit] +Description=Carlos Device +After=network.target + +[Service] +Type=simple +User=carlos +WorkingDirectory=~/carlos/services/device +ExecStart=~/carlos/services/device/.venv/bin/python -m device.cli run +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/services/device/device/run.py b/services/device/device/run.py index 2a977751..55800539 100644 --- a/services/device/device/run.py +++ b/services/device/device/run.py @@ -1,4 +1,6 @@ from carlos.edge.device import DeviceRuntime, read_config +from carlos.edge.device.constants import VERSION +from loguru import logger from device.connection import read_connection_settings from device.websocket import DeviceWebsocketClient @@ -8,6 +10,20 @@ async def main(): # pragma: no cover """The main entry point of the application.""" + logger.info( + r""" + + ______ __ ____ _ + / ____/____ _ _____ / /____ _____ / __ \ ___ _ __ (_)_____ ___ + / / / __ `// ___// // __ \ / ___// / / // _ \| | / // // ___// _ \ + / /___ / /_/ // / / // /_/ /(__ )/ /_/ // __/| |/ // // /__ / __/ + \____/ \__,_//_/ /_/ \____//____//_____/ \___/ |___//_/ \___/ \___/ + + """ + ) + + logger.info(f"Starting Carlos device (v{VERSION})...") + device_config = read_config() device_connection = read_connection_settings() protocol = DeviceWebsocketClient( diff --git a/services/device/install-service.sh b/services/device/install-service.sh new file mode 100644 index 00000000..1347bcdf --- /dev/null +++ b/services/device/install-service.sh @@ -0,0 +1,3 @@ +sudo cp carlos_device.service /etc/systemd/system/ +sudo systemctl enable carlos_device.service +sudo systemctl start carlos_device.service \ No newline at end of file diff --git a/services/device/poetry.lock b/services/device/poetry.lock index 67896057..b76f5872 100644 --- a/services/device/poetry.lock +++ b/services/device/poetry.lock @@ -123,7 +123,7 @@ uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "carlos-edge-device" -version = "0.1.0" +version = "0.1.1" description = "The library for the edge device of the carlos project." optional = false python-versions = ">=3.11,<3.12" diff --git a/services/device/pyproject.toml b/services/device/pyproject.toml index 9ca6e5e8..32eec1ee 100644 --- a/services/device/pyproject.toml +++ b/services/device/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "device" -version = "0.1.0" +version = "0.1.1" description = "The device runtime for the Carlos Edge Computing Platform" authors = ["Felix Fanghänel"] readme = "README.md"