Compare commits
23
Commits
cb036da997
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef5fe0f790 | ||
|
|
832e4d572f | ||
|
|
2efdebff58 | ||
|
|
c8891f2571 | ||
|
|
2ea75f23ee | ||
|
|
7458b0c4f4 | ||
|
|
3ba464b8fc | ||
|
|
ec0aca846a | ||
|
|
608b2d6b10 | ||
|
|
02b156996d | ||
|
|
08a5ad8afa | ||
|
|
c0ce37f43c | ||
|
|
7d88b54d53 | ||
|
|
a777751a5a | ||
|
|
db01c63b89 | ||
|
|
ff18f4c6d7 | ||
|
|
32dfa10613 | ||
|
|
95b95fd84b | ||
|
|
e725dce168 | ||
|
|
4ed4ab665b | ||
|
|
10fc399746 | ||
|
|
97f48122cc | ||
|
|
5e610dd469 |
@@ -7,26 +7,38 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup-python-uv-dependencies:
|
|
||||||
name: Setup Python and UV dependencies
|
|
||||||
uses: ./.gitea/workflows/setup-python-uv-dependencies.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
code-quality:
|
code-quality:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
run: pip install uv
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
env:
|
||||||
|
UV_LINK_MODE: copy
|
||||||
|
run: uv sync
|
||||||
|
|
||||||
|
- name: Type check with mypy
|
||||||
|
run: uv run mypy .
|
||||||
|
|
||||||
- name: Ruff lint
|
- name: Ruff lint
|
||||||
run: ruff check .
|
run: uv run ruff check .
|
||||||
|
|
||||||
- name: Ruff format
|
- name: Ruff format
|
||||||
run: ruff format --check .
|
run: uv run ruff format --check .
|
||||||
|
|
||||||
- name: Pyupgrade check
|
- name: Pyupgrade check
|
||||||
run: pyupgrade --py313-plus $(git ls-files '*.py') && git diff --exit-code
|
run: uv run pyupgrade --py313-plus $(git ls-files '*.py') && git diff --exit-code
|
||||||
|
|
||||||
- name: Install prettier
|
|
||||||
run: npm install --save-dev --save-exact prettier
|
|
||||||
|
|
||||||
- name: Prettier format
|
- name: Prettier format
|
||||||
run: npx prettier --check .
|
run: |
|
||||||
|
npm install --save-dev --save-exact prettier
|
||||||
|
npx prettier --check .
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup-python:
|
update-check:
|
||||||
name: Setup Python
|
|
||||||
uses: ./.gitea/workflows/setup-python.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
renovate-like:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
- name: Install uv and pip-review
|
- name: Install uv and pip-review
|
||||||
run: |
|
run: |
|
||||||
pip install uv pip-review
|
pip install uv pip-review
|
||||||
|
|||||||
@@ -8,19 +8,16 @@ on:
|
|||||||
- "v*.*.*"
|
- "v*.*.*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup-python:
|
|
||||||
name: Setup Python
|
|
||||||
uses: ./.gitea/workflows/setup-python.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
build-and-publish:
|
build-and-publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Checkout code
|
||||||
uses: ./.gitea/workflows/setup-python.yml
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
- name: Install uv
|
- name: Install uv
|
||||||
run: pip install uv
|
run: pip install uv
|
||||||
@@ -34,14 +31,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Build package
|
- name: Build package
|
||||||
run: |
|
run: |
|
||||||
uv pip install build --system
|
uv sync --no-dev
|
||||||
uv build
|
uv build
|
||||||
|
|
||||||
- name: Publish to Gitea Package Registry
|
- name: Publish to Gitea Package Registry
|
||||||
env:
|
env:
|
||||||
TWINE_USERNAME: __token__
|
UV_PUBLISH_TOKEN: ${{ secrets.CI_RUNNER_TOKEN }}
|
||||||
TWINE_PASSWORD: ${{ secrets.CI_RUNNER_TOKEN }}
|
UV_PUBLISH_URL: ${{ vars.REPOSITORY_URL }}
|
||||||
TWINE_REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
|
|
||||||
run: |
|
run: |
|
||||||
uv pip install twine --system
|
uv publish
|
||||||
twine upload dist/*
|
|
||||||
|
|||||||
@@ -6,14 +6,24 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup-python-uv-dependencies:
|
|
||||||
name: Setup Python and UV dependencies
|
|
||||||
uses: ./.gitea/workflows/setup-python-uv-dependencies.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
safety:
|
safety:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
run: pip install uv
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
env:
|
||||||
|
UV_LINK_MODE: copy
|
||||||
|
run: uv sync
|
||||||
|
|
||||||
- name: Run safety check
|
- name: Run safety check
|
||||||
run: safety check
|
run: uv run safety check
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
name: Setup Python Pipeline
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
python-version:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
setup-python-uv-dependencies:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: ${{ inputs.python-version }}
|
|
||||||
|
|
||||||
- name: Install uv
|
|
||||||
run: pip install uv
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
env:
|
|
||||||
UV_LINK_MODE: copy
|
|
||||||
run: uv sync
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
name: Setup Python Pipeline
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
python-version:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
setup-python:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: ${{ inputs.python-version }}
|
|
||||||
@@ -11,10 +11,13 @@ jobs:
|
|||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Python
|
- name: Checkout code
|
||||||
uses: ./.gitea/workflows/setup-python.yml
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
- name: Configure git
|
- name: Configure git
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -7,16 +7,41 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup-python-uv-dependencies:
|
|
||||||
name: Setup Python and UV dependencies
|
|
||||||
uses: ./.gitea/workflows/setup-python-uv-dependencies.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Run pytest
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
run: pip install uv
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
env:
|
||||||
|
UV_LINK_MODE: copy
|
||||||
|
run: uv sync
|
||||||
|
|
||||||
|
- name: Run pytest with coverage report
|
||||||
env:
|
env:
|
||||||
PYTHONPATH: .
|
PYTHONPATH: .
|
||||||
run: pytest
|
run: uv run pytest --cov=python_utils --cov-report=term-missing > coverage.txt
|
||||||
|
|
||||||
|
- name: Post coverage summary to PR
|
||||||
|
env:
|
||||||
|
API_URL: ${{ vars.API_URL }}
|
||||||
|
REPO_OWNER: ${{ github.repository_owner }}
|
||||||
|
REPO_NAME: ${{ github.event.repository.name }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
CI_RUNNER_TOKEN: ${{ secrets.CI_RUNNER_TOKEN }}
|
||||||
|
run: |
|
||||||
|
COVERAGE=$(cat coverage.txt)
|
||||||
|
COMMENT_BODY="**Test Coverage Report:**\n\`\`\`\n$COVERAGE\n\`\`\`"
|
||||||
|
curl -s -X POST "$API_URL/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments" \
|
||||||
|
-H "Authorization: token $CI_RUNNER_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"body\": \"$COMMENT_BODY\"}"
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
name: Type Check
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
setup-python-uv-dependencies:
|
|
||||||
name: Setup Python and UV dependencies
|
|
||||||
uses: ./.gitea/workflows/setup-python-uv-dependencies.yml
|
|
||||||
with:
|
|
||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
type-check:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Run mypy
|
|
||||||
run: mypy monitor_utils
|
|
||||||
@@ -7,6 +7,15 @@ __pycache__/
|
|||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
||||||
|
# Node.js/npm
|
||||||
|
node_modules/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.npm
|
||||||
|
.yarn-integrity
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
build/
|
build/
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
def main():
|
|
||||||
print("Hello from python-utils!")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -20,7 +20,34 @@ dev = [
|
|||||||
"mypy>=1.17.1",
|
"mypy>=1.17.1",
|
||||||
"pre-commit>=4.3.0",
|
"pre-commit>=4.3.0",
|
||||||
"pytest>=8.4.1",
|
"pytest>=8.4.1",
|
||||||
|
"pytest-cov>=7.0.0",
|
||||||
"pyupgrade>=3.20.0",
|
"pyupgrade>=3.20.0",
|
||||||
"ruff>=0.12.10",
|
"ruff>=0.12.10",
|
||||||
"safety>=3.6.0",
|
"safety>=3.6.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "private-cache"
|
||||||
|
url = "http://10.0.0.2:5001/index/"
|
||||||
|
default = true
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
python_version = "3.10"
|
||||||
|
warn_return_any = true # nudge to use stricter types
|
||||||
|
warn_unused_configs = true # nudge to remove unused configs
|
||||||
|
disallow_untyped_defs = true # disallow untyped function definitions
|
||||||
|
disallow_incomplete_defs = true # ensure all parts of a function has type annotation
|
||||||
|
check_untyped_defs = true # dont skip untyped functions
|
||||||
|
disallow_untyped_decorators = false # allow untyped decorators to keep code more readable
|
||||||
|
no_implicit_optional = true # disallow implicit optional types leading to None-mess
|
||||||
|
warn_redundant_casts = true # nudge to use explicit type casts
|
||||||
|
warn_unused_ignores = true # nudge to remove unused ignores
|
||||||
|
warn_no_return = true # catch missing return statements
|
||||||
|
warn_unreachable = true # catch unreachable code
|
||||||
|
show_error_codes = true # show error codes in output
|
||||||
|
explicit_package_bases = true # reduce risk of import confusion
|
||||||
|
namespace_packages = true # enable namespace packages
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
addopts = "--cov=python_utils --cov-report=term-missing"
|
||||||
|
testpaths = ["tests"]
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from .check_env import check_env as check_env
|
||||||
|
from .readable_unit import readable_unit as readable_unit
|
||||||
|
|
||||||
|
__all__ = ["check_env", "readable_unit"]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
def check_env(
|
def check_env(
|
||||||
var_list: str | list[str],
|
var_list: str | set[str] | list[str] | tuple[str, ...],
|
||||||
missing_ok: bool = False,
|
missing_ok: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check if environment variables are set.
|
"""Check if environment variables are set.
|
||||||
|
|||||||
@@ -3,12 +3,15 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pytohn_utils import check_env
|
from python_utils import check_env
|
||||||
|
|
||||||
|
|
||||||
class TestCheckEnv(unittest.TestCase):
|
class TestCheckEnv(unittest.TestCase):
|
||||||
|
set_vars: list[str]
|
||||||
|
unset_var: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls) -> None:
|
||||||
"""Set up test environment variables."""
|
"""Set up test environment variables."""
|
||||||
cls.set_vars = ["A", "B", "C"]
|
cls.set_vars = ["A", "B", "C"]
|
||||||
for var in cls.set_vars:
|
for var in cls.set_vars:
|
||||||
@@ -20,41 +23,41 @@ class TestCheckEnv(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls) -> None:
|
||||||
for var in cls.set_vars:
|
for var in cls.set_vars:
|
||||||
if var in os.environ:
|
if var in os.environ:
|
||||||
del os.environ[var]
|
del os.environ[var]
|
||||||
os.environ.pop(var, None)
|
os.environ.pop(var, None)
|
||||||
|
|
||||||
def test_check_env_accepts_single_string(self):
|
def test_check_env_accepts_single_string(self) -> None:
|
||||||
"""Test check_env function with a valid single string."""
|
"""Test check_env function with a valid single string."""
|
||||||
self.assertIsNone(check_env(self.set_vars[0]))
|
check_env(self.set_vars[0])
|
||||||
|
|
||||||
def test_check_env_accepts_list_of_strings(self):
|
def test_check_env_accepts_list_of_strings(self) -> None:
|
||||||
"""Test check_env function with a valid list of strings."""
|
"""Test check_env function with a valid list of strings."""
|
||||||
self.assertIsNone(check_env(self.set_vars))
|
check_env(self.set_vars)
|
||||||
|
|
||||||
def test_check_env_accepts_set_of_strings(self):
|
def test_check_env_accepts_set_of_strings(self) -> None:
|
||||||
"""Test check_env function with a valid set of strings."""
|
"""Test check_env function with a valid set of strings."""
|
||||||
self.assertIsNone(check_env(set(self.set_vars)))
|
check_env(set(self.set_vars))
|
||||||
|
|
||||||
def test_check_env_accepts_tuple_of_strings(self):
|
def test_check_env_accepts_tuple_of_strings(self) -> None:
|
||||||
"""Test check_env function with a valid tuple of strings."""
|
"""Test check_env function with a valid tuple of strings."""
|
||||||
self.assertIsNone(check_env(tuple(self.set_vars)))
|
check_env(tuple(self.set_vars))
|
||||||
|
|
||||||
def test_check_env_rejects_empty_list(self):
|
def test_check_env_rejects_empty_list(self) -> None:
|
||||||
"""Test check_env function with an empty list."""
|
"""Test check_env function with an empty list."""
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
check_env([])
|
check_env([])
|
||||||
|
|
||||||
def test_check_env_raises_error_on_missing_vars(self):
|
def test_check_env_raises_error_on_missing_vars(self) -> None:
|
||||||
"""Test check_env function with missing environment variables."""
|
"""Test check_env function with missing environment variables."""
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
check_env(self.unset_var)
|
check_env(self.unset_var)
|
||||||
|
|
||||||
def test_check_env_does_not_raise_error_when_missing_ok_flag_set(self):
|
def test_check_env_does_not_raise_error_when_missing_ok_flag_set(self) -> None:
|
||||||
"""Test that check_env does not raise an error when the environment variable is missing and missing_ok=True.
|
"""Test that check_env does not raise an error when the environment variable is missing and missing_ok=True.
|
||||||
|
|
||||||
The 'missing_ok' flag allows the function to skip raising an error if the specified environment variable(s) are not set.
|
The 'missing_ok' flag allows the function to skip raising an error if the specified environment variable(s) are not set.
|
||||||
"""
|
"""
|
||||||
self.assertIsNone(check_env(self.unset_var, missing_ok=True))
|
check_env(self.unset_var, missing_ok=True)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Unittests for the readable function."""
|
"""Unittests for the readable function."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from python_utils import readable_unit
|
from python_utils import readable_unit
|
||||||
|
|
||||||
@@ -31,7 +32,11 @@ TEST_CASES = [
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("value, unit, expected", TEST_CASES)
|
@pytest.mark.parametrize("value, unit, expected", TEST_CASES)
|
||||||
def test_readable_unit(value, unit, expected):
|
def test_readable_unit(
|
||||||
|
value: Any, # Allow invalid types for testing
|
||||||
|
unit: Any, # Allow invalid types for testing
|
||||||
|
expected: Any, # Allow invalid types for testing
|
||||||
|
) -> None:
|
||||||
"""Test readable_unit function with valid inputs."""
|
"""Test readable_unit function with valid inputs."""
|
||||||
if isinstance(expected, type) and issubclass(expected, Exception):
|
if isinstance(expected, type) and issubclass(expected, Exception):
|
||||||
with pytest.raises(expected):
|
with pytest.raises(expected):
|
||||||
|
|||||||
Reference in New Issue
Block a user