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
82 changes: 55 additions & 27 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,14 +32,20 @@ jobs:
with:
submodules: true

- name: Install 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 just
uses: extractions/setup-just@v3
- 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: just lint
run: tox -e lint

unit:
name: Unit
Expand All @@ -48,14 +59,18 @@ jobs:
with:
submodules: true

- name: Install 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 just
uses: extractions/setup-just@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install 'tox<5'

- name: Run unit tests
run: just unit
run: tox -e unit

- name: Determine system architecture
run: echo "SYSTEM_ARCH=$(uname -m)" >> $GITHUB_ENV
Expand Down Expand Up @@ -100,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 @@ -130,7 +145,7 @@ jobs:
fail-fast: false
matrix:
runs-on: [['self-hosted', 'jammy', 'amd64', 'two-xlarge']]
test-command: ['TEST_MODEL_SETTINGS="update-status-hook-interval=30s" just func']
test-command: ['TEST_MODEL_SETTINGS="update-status-hook-interval=30s" tox -e func']
juju-channel: ['3.6/stable']
steps:
- uses: actions/checkout@v6
Expand All @@ -143,18 +158,17 @@ jobs:
sudo apt update
sudo apt install -y gcc

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install just
uses: extractions/setup-just@v3
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- 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 @@ -265,12 +279,26 @@ jobs:
fetch-depth: 0

# Install everything from all requirements.txt files otherwise TICS errors.
- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install TICS dependencies
- name: Install all charm dependencies
run: |
uv sync --group tics
# 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

# 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
Expand All @@ -295,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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 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.

# Python Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
128 changes: 62 additions & 66 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,83 +1,74 @@
[project]
name = "openstack-exporter-operator"
version = "0.0.0"
requires-python = ">=3.10"
dependencies = [
"charmlibs-snap~=1.0.1",
"cosl",
"ops ~= 2.5",
"pydantic < 2",
"pyyaml ~= 6.0",
]
# 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.

[tool.uv]
package = false
override-dependencies = [
"setuptools<82", # setuptools v82.0.0 officially removed the pkg_resources module which python-keystoneclient 3.21.0 depends on
"prettytable>0.7.2" # prettytable v0.7.2 uses .tar.bz2 format for source distribution which is not supported by newer version of uv
]
[tool.setuptools_scm]

[dependency-groups]
unit = [
"pytest",
"pytest-cov",
"pytest-mock",
]
func = [
"python-openstackclient",
"pytest",
"pytest-cov",
"pytest-operator",
"zaza @ git+https://github.com/openstack-charmers/zaza.git@master",
"zaza-openstack @ git+https://github.com/openstack-charmers/zaza-openstack-tests.git",
]
lint = [
"ruff",
"mypy",
"codespell",
]
reformat = ["ruff"]
tics = [
"coverage[toml]",
"pylint>=4.0.7",
]

[tool.ruff]
line-length = 99
preview = true
[tool.flake8]
max-line-length = 99
max-doc-length = 99
max-complexity = 10
exclude = [
".eggs",
".git",
"__pycache__",
".tox",
".venv",
".build",
"build",
"lib",
"dist",
".eggs",
"*.egg_info",
"venv",
".venv",
"report",
"docs",
"lib",
"mod",
"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 (conflicts with D211)
"D213", # multi-line-summary-second-line (conflicts with D212)
"D415", # first line punctuation
"N818", # exception name without 'Error'
"D100", "D101", "D102", "D103",
]
[tool.black]
line-length = 99
exclude = '''
/(
| .eggs
| .git
| .tox
| .venv
| .build
| build
| lib
| report
| docs
| mod
| hooks/charmhelpers
| tests/charmhelpers
)/
'''

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D100", "D101", "D102", "D103", "D104"]
[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 @@ -86,14 +77,19 @@ warn_unreachable = true
disallow_untyped_defs = true
ignore_missing_imports = true
no_namespace_packages = true
exclude = [".eggs", ".git", ".tox", ".venv", ".build", "lib", "report", "tests", "docs", "mod", "hooks/charmhelpers", "tests/charmhelpers"]
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