Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 52 additions & 29 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This file is centrally managed as a template file in https://github.com/canonical/solutions-engineering-automation
# To update the file:
# - Edit it in the canonical/solutions-engineering-automation repository.
# - Open a PR with the changes.
# - When the PR merges, the soleng-terraform bot will open a PR to the target repositories with the changes.
name: Tests

on:
Expand Down Expand Up @@ -27,13 +32,17 @@ jobs:
with:
submodules: true

- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install tox
run: uv tool install tox --with tox-uv
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# pin tox to the current major version to avoid
# workflows breaking all at once when a new major version is released.
python -m pip install 'tox<5'

- name: Run linters
run: tox -e lint
Expand All @@ -50,13 +59,15 @@ jobs:
with:
submodules: true

- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install tox
run: uv tool install tox --with tox-uv
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install 'tox<5'

- name: Run unit tests
run: tox -e unit
Expand Down Expand Up @@ -104,7 +115,7 @@ jobs:

- uses: canonical/craft-actions/charmcraft/setup@main
with:
channel: "latest/stable"
channel: "3.x/stable"

- name: Pack the charms
id: build
Expand Down Expand Up @@ -133,12 +144,9 @@ jobs:
strategy:
fail-fast: false
matrix:
runs-on: [[ubuntu-24.04], [ubuntu-24.04-arm]]
runs-on: [[ubuntu-24.04], [ubuntu-22.04-arm]]
test-command: ['tox -e func -- -v --base ubuntu@20.04 --keep-models', 'tox -e func -- -v --base ubuntu@22.04 --keep-models', 'tox -e func -- -v --base ubuntu@24.04 --keep-models' ]
juju-channel: ["3.6/stable"]
test-command:
- "tox -e func -- -v --base ubuntu@20.04 --keep-models"
- "tox -e func -- -v --base ubuntu@22.04 --keep-models"
- "tox -e func -- -v --base ubuntu@24.04 --keep-models"
steps:
- uses: actions/checkout@v6
with:
Expand All @@ -150,20 +158,17 @@ jobs:
sudo apt update
sudo apt install -y gcc

- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- name: Install tox
run: uv tool install tox --with tox-uv

- name: Setup Juju environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: "lxd"
juju-channel: ${{ matrix.juju-channel }}
charmcraft-channel: "latest/stable"
charmcraft-channel: "3.x/stable"

- name: Determine system architecture
run: echo "SYSTEM_ARCH=$(uname -m)" >> $GITHUB_ENV
Expand Down Expand Up @@ -273,12 +278,30 @@ jobs:
with:
fetch-depth: 0

# Install dependencies for TICS analysis (coverage + pylint)
- name: Set up uv
uses: astral-sh/setup-uv@v7
# Install everything from all requirements.txt files otherwise TICS errors.
- name: Install all charm dependencies
run: |
# run in a virtualenv to ensure dependencies will not conflict with the system python packages
sudo apt update
sudo apt install python3-venv -y
python3 -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install coverage[toml] pylint flake8

for f in $(find -name '*requirements.txt'); do
echo "${f}"
.venv/bin/python -m pip install --requirement "${f}"
done

# For reactive charms
for f in $(find -name 'wheelhouse.txt'); do
echo "${f}"
.venv/bin/python -m pip install --requirement "${f}"
done

- name: Install charm dependencies
run: uv sync --group tics
# Symlink venv to a short path so TICS version string stays under 31 chars
sudo ln -s "$GITHUB_WORKSPACE/.venv" /opt/venv
echo "/opt/venv/bin" >> $GITHUB_PATH

- name: Determine system architecture
run: echo "SYSTEM_ARCH=$(uname -m)" >> $GITHUB_ENV
Expand All @@ -300,12 +323,12 @@ jobs:

if [ -e "${coverage_files[0]}" ]; then
echo "Merging coverage files: ${coverage_files[*]}"
uv run coverage combine "${coverage_files[@]}"
coverage combine "${coverage_files[@]}"

# Check if there is actual data to report before generating XML with merged reports
if uv run coverage report > /dev/null 2>&1; then
uv run coverage report --show-missing
uv run coverage xml -o tests/report/coverage.xml
if coverage report > /dev/null 2>&1; then
coverage report --show-missing
coverage xml -o tests/report/coverage.xml
fi

fi
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches: [ main ]
release:
types: [ published ]
workflow_dispatch:

jobs:
check:
Expand All @@ -20,6 +19,8 @@ jobs:
release:
needs: check
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down
136 changes: 54 additions & 82 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
[project]
name = "hardware-observer-operator"
version = "0.0.0"
requires-python = ">=3.8"
dependencies = [
"cosl",
"distro",
"ops>=2.2.0",
"jinja2",
"redfish",
"pydantic<2",
"prometheus-hardware-exporter",
]

[tool.uv]
package = false

[tool.uv.sources]
prometheus-hardware-exporter = {git = "https://github.com/canonical/prometheus-hardware-exporter.git", tag = "v1.2.1"}
# This file is centrally managed as a template file in https://github.com/canonical/solutions-engineering-automation
# To update the file:
# - Edit it in the canonical/solutions-engineering-automation repository.
# - Open a PR with the changes.
# - When the PR merges, the soleng-terraform bot will open a PR to the target repositories with the changes.

[dependency-groups]
reformat = [
"ruff",
]
lint = [
"mypy",
"ruff",
"codespell",
"types-requests>=2.32.0.20241016",
]
unit = [
"coverage",
"parameterized",
"pytest",
"pytest-cov",
]
func = [
"pytest",
"pytest-cov",
"pytest-operator",
"async-lru",
"protobuf",
"tenacity",
]
integration = [
"juju~=3.5.0",
"pytest",
"pytest-operator",
"prometheus-client",
"pyinstaller",
"tenacity",
]
tics = [
"coverage[toml]",
]
[tool.setuptools_scm]

[tool.ruff]
line-length = 99
[tool.flake8]
max-line-length = 99
max-doc-length = 99
max-complexity = 10
exclude = [
".git",
"__pycache__",
Expand All @@ -74,34 +28,47 @@ exclude = [
"hooks/charmhelpers",
"tests/charmhelpers",
]
select = ["E", "W", "F", "C", "N", "R", "D", "H"]
# Ignore W503, E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__
# Ignore D415 Docstring first line punctuation (doesn't make sense for properties)
# Ignore N818 Exceptions end with "Error" (not all exceptions are errors)
# D100, D101, D102, D103: Ignore missing docstrings in tests
ignore = ["C901", "W503", "E501", "D107", "D415", "N818", "D100", "D101", "D102", "D103", "W504"]
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104"]
# Check for properly formatted copyright header in each file
copyright-check = "True"
copyright-author = "Canonical Ltd."
copyright-regexp = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+%(author)s"

[tool.ruff.lint]
select = ["E", "W", "F", "C90", "N", "D", "I", "CPY"]
ignore = [
"E501", # line too long (handled by formatter)
"D107", # missing docstring in __init__
"D203", # one-blank-line-before-class (incompatible with D211)
"D213", # multi-line-summary-second-line (incompatible with D212)
"D415", # first line should end with punctuation
"D100", # missing docstring in public module
"D101", # missing docstring in public class
"D102", # missing docstring in public method
"D103", # missing docstring in public function
"N818", # exception name should end with Error
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D100", "D101", "D102", "D103", "D104"]

[tool.ruff.lint.mccabe]
max-complexity = 10
[tool.black]
line-length = 99
exclude = '''
/(
| .eggs
| .git
| .tox
| .venv
| .build
| build
| lib
| report
| docs
| mod
| hooks/charmhelpers
| tests/charmhelpers
)/
'''

[tool.ruff.lint.pycodestyle]
max-doc-length = 99
[tool.isort]
profile = "black"
line_length = 99
skip_glob = [".eggs", ".git", ".tox", ".venv", ".build", "build", "lib", "report", "mod/*", "hooks/charmhelpers", "tests/charmhelpers"]

[tool.ruff.lint.flake8-copyright]
notice-rgx = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+Canonical Ltd\\."
min-file-size = 1
[tool.pylint]
max-line-length = 99
disable = ["E1102"]
ignore = ['.eggs', '.git', '.tox', '.venv', '.build', 'lib', 'report', 'tests', 'docs', "mod", "hooks/charmhelpers", "tests/charmhelpers"]

[tool.mypy]
warn_unused_ignores = true
Expand All @@ -113,11 +80,16 @@ no_namespace_packages = true
exclude = ['.eggs', '.git', '.tox', '.venv', '.build', 'lib', 'report', 'tests', 'docs', "mod", "hooks/charmhelpers", "tests/charmhelpers"]

[tool.codespell]
skip = ".eggs,.tox,.git,.venv,venv,build,.build,lib,report,docs,htmlcov,mod,hooks/charmhelpers,tests/charmhelpers,uv.lock"
skip = ".eggs,.tox,.git,.venv,venv,build,.build,lib,report,docs,poetry.lock,htmlcov,mod,hooks/charmhelpers,tests/charmhelpers"
quiet-level = 3
check-filenames = true
ignore-words-list = "assertIn"

## Ignore unsupported imports
[[tool.mypy.overrides]]
module = ["charmhelpers.*", "setuptools"]
ignore_missing_imports = true

[tool.coverage.run]
relative_files = true
source = ["."]
Expand Down
Loading
Loading