From 072e98495442d509d1642b65a21846badf4ad9a9 Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Fri, 28 Feb 2025 23:09:51 -0500 Subject: [PATCH 1/2] ci setup --- .github/workflows/ci.yml | 149 +++++++++++++++++++++++++++++++++++++++ codecov.yml | 44 ++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 codecov.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d75c570 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,149 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Run tests with coverage + run: | + pdm run pytest --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + fail_ci_if_error: true + + format: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Check Black formatting + run: | + pdm run black --check . + + - name: Check isort + run: | + pdm run isort --check . + + - name: Check unused imports with autoflake + run: | + pdm run autoflake . -r --remove-unused-variables --remove-all-unused-imports --ignore-pass-after-docstring --exclude ./.venv/*,./_scripts/* --check + + type-check: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Run mypy + run: | + pdm run mypy + + docs: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Check markdown formatting + run: | + pdm run mdformat --check . + + build: + runs-on: ubuntu-latest + needs: [test, format, type-check, docs] + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Build package + run: | + pdm build \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..c1ca2f7 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,44 @@ +codecov: + require_ci_to_pass: yes + strict_yaml_branch: main + +coverage: + precision: 2 + round: down + range: "95...100" + status: + project: + default: + target: 100% + threshold: 0% + base: auto + branches: + - main + if_not_found: failure + if_ci_failed: error + informational: false + only_pulls: false + patch: + default: + target: 100% + threshold: 0% + base: auto + branches: + - main + if_not_found: failure + if_ci_failed: error + informational: false + only_pulls: false + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "reach,diff,flags,files,footer" + behavior: default + require_changes: no \ No newline at end of file From b5b3837d6f27db855f8a65e682b9d740ba52951d Mon Sep 17 00:00:00 2001 From: Jon Stroop Date: Sat, 1 Mar 2025 10:47:45 -0500 Subject: [PATCH 2/2] trying new codecov config --- .github/workflows/ci.yml | 171 +++++---------------------- README.md | 2 +- TODO.md | 13 ++ codecov.yml | 44 ++----- fitbit_client/resources/nutrition.py | 6 +- 5 files changed, 60 insertions(+), 176 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84bac6c..78aa91e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,146 +8,37 @@ on: jobs: test: + name: test runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v3 - - - name: Set up Python 3.13 - uses: actions/setup-python@v4 - with: - python-version: "3.13" - - - name: Install PDM - run: | - python -m pip install --upgrade pip - pip install pdm - - - name: Install dependencies - run: | - pdm install -G:all - - - name: Run tests with coverage - run: | - pdm run pytest --cov-report=xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.xml - fail_ci_if_error: true - verbose: true - - format: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v3 - - - name: Set up Python 3.13 - uses: actions/setup-python@v4 - with: - python-version: "3.13" - - - name: Install PDM - run: | - python -m pip install --upgrade pip - pip install pdm - - - name: Install dependencies - run: | - pdm install -G:all - - - name: Check Black formatting - run: | - pdm run black --check - - - name: Check isort - run: | - pdm run isort --check - - - name: Check unused imports with autoflake - run: | - pdm run autoflake - - type-check: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v3 - - - name: Set up Python 3.13 - uses: actions/setup-python@v4 - with: - python-version: "3.13" - - - name: Install PDM - run: | - python -m pip install --upgrade pip - pip install pdm - - - name: Install dependencies - run: | - pdm install -G:all - - - name: Run mypy - run: | - pdm run mypy - - docs: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v3 - - - name: Set up Python 3.13 - uses: actions/setup-python@v4 - with: - python-version: "3.13" - - - name: Install PDM - run: | - python -m pip install --upgrade pip - pip install pdm - - - name: Install dependencies - run: | - pdm install -G:all - - - name: Check markdown formatting - run: | - echo "Markdown format checking temporarily disabled" - exit 0 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: "3.13" + + - name: Install PDM + run: | + python -m pip install --upgrade pip + pip install pdm + + - name: Install dependencies + run: | + pdm install -G:all + + - name: Run tests with coverage + run: | + pdm run pytest --cov=fitbit_client --cov-report=xml:coverage.xml - # todo: https://github.com/ydah/mdformat-action - - # build: - # runs-on: ubuntu-latest - # needs: [test, format, type-check, docs] - - # steps: - # - name: Check out repository - # uses: actions/checkout@v3 - - # - name: Set up Python 3.13 - # uses: actions/setup-python@v4 - # with: - # python-version: "3.13" - - # - name: Install PDM - # run: | - # python -m pip install --upgrade pip - # pip install pdm - - # - name: Install dependencies - # run: | - # pdm install -G:all - - # - name: Build package - # run: | - # pdm build + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + # fail_ci_if_error: false + name: codecov-umbrella + verbose: true \ No newline at end of file diff --git a/README.md b/README.md index ae7c895..7aab7d4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Fitbit Client [![CI](https://github.com/jpstroop/fitbit-client/actions/workflows/ci.yml/badge.svg)](https://github.com/jpstroop/fitbit-client/actions/workflows/ci.yml) -[![codecov](https://codecov.io/gh/jpstroop/fitbit-client/branch/main/graph/badge.svg)](https://codecov.io/gh/jpstroop/fitbit-client) +[![codecov](https://codecov.io/gh/jpstroop/fitbit-client-python/graph/badge.svg?token=DM0JD8VKZ4)](https://codecov.io/gh/jpstroop/fitbit-client-python) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/release/python-3130/) [![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0) diff --git a/TODO.md b/TODO.md index df86bf9..ec98ffa 100644 --- a/TODO.md +++ b/TODO.md @@ -45,6 +45,19 @@ if not food_id and not (food_name and calories): params[str(key)] = float(value) ``` +It needs to change to: + +```python + for key, value in nutritional_values.items(): + if isinstance(key, NutritionalValue): + if key == NutritionalValue.CALORIES_FROM_FAT: + params[key.value] = int(value) + else: + params[key.value] = float(value) + else: + params[str(key)] = float(value) +``` + see: test_create_food_calories_from_fat_must_be_integer(nutrition_resource) - exceptions.py diff --git a/codecov.yml b/codecov.yml index c1ca2f7..65cc730 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,44 +1,22 @@ codecov: require_ci_to_pass: yes strict_yaml_branch: main + notify: + wait_for_ci: false + after_n_builds: 1 coverage: - precision: 2 - round: down - range: "95...100" status: - project: + project: #add everything under here, more options at https://docs.codecov.com/docs/commit-status default: target: 100% threshold: 0% - base: auto - branches: - - main - if_not_found: failure - if_ci_failed: error - informational: false - only_pulls: false - patch: - default: - target: 100% - threshold: 0% - base: auto - branches: - - main - if_not_found: failure - if_ci_failed: error - informational: false - only_pulls: false - -parsers: - gcov: - branch_detection: - conditional: yes - loop: yes - method: no - macro: no + base: auto -comment: - layout: "reach,diff,flags,files,footer" +comment: #this is a top-level key + layout: " diff, flags, files" behavior: default - require_changes: no \ No newline at end of file + require_changes: false # if true: only post the comment if coverage changes + require_base: false # [true :: must have a base report to post] + require_head: true # [true :: must have a head report to post] + hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage] diff --git a/fitbit_client/resources/nutrition.py b/fitbit_client/resources/nutrition.py index 3999d28..7a2cc14 100644 --- a/fitbit_client/resources/nutrition.py +++ b/fitbit_client/resources/nutrition.py @@ -103,10 +103,12 @@ def create_food( error_type="client_validation", field_name="CALORIES_FROM_FAT", ) - # Handle both enum and string nutritional values for key, value in nutritional_values.items(): if isinstance(key, NutritionalValue): - params[key.value] = float(value) + if key == NutritionalValue.CALORIES_FROM_FAT: + params[key.value] = int(value) + else: + params[key.value] = float(value) else: params[str(key)] = float(value)