Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tox.ini and pyproject.toml, and apply new formatting rules #26

Merged
merged 6 commits into from
Feb 12, 2025
Merged
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
91 changes: 91 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[tool.flake8]
line-length = 99
max-line-length = 99
max-doc-length = 99
max-complexity = 10
exclude = [
".git",
"__pycache__",
".tox",
".build",
"build",
"dist",
".eggs",
"*.egg_info",
"venv",
".venv",
"report",
]
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.black]
line-length = 99
exclude = '''
/(
| .eggs
| .git
| .tox
| .venv
| .build
| build
| lib
| report
| docs
)/
'''

[tool.isort]
profile = "black"
line_length = 99
skip_glob = [".eggs", ".git", ".tox", ".venv", ".build", "build", "lib", "report"]

[tool.pylint]
max-line-length = 99
disable = ["E1102"]
ignore = ['.eggs', '.git', '.tox', '.venv', '.build', 'lib', 'report', 'tests', 'docs']

[tool.mypy]
warn_unused_ignores = true
warn_unused_configs = true
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']

[tool.codespell]
skip = ".eggs,.tox,.git,.venv,venv,build,.build,lib,report,docs,poetry.lock,htmlcov"
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 = ["."]
omit = ["tests/**", "docs/**", "lib/**", "snap/**", "build/**", "setup.py"]

[tool.coverage.report]
fail_under = 100
show_missing = true

[tool.coverage.html]
directory = "tests/report/html"

[tool.coverage.xml]
output = "tests/report/coverage.xml"
4 changes: 1 addition & 3 deletions reactive/prometheus_blackbox_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def update_dashboards_from_resource():
hookenv.log("BadZipFile: {}".format(error), hookenv.ERROR)
return
except PermissionError as error:
hookenv.log(
"Unable to unzip the provided resource: {}".format(error), hookenv.ERROR
)
hookenv.log("Unable to unzip the provided resource: {}".format(error), hookenv.ERROR)
return

register_grafana_dashboards()
15 changes: 4 additions & 11 deletions tests/functional/tests/test_prometheus_blackbox_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def test_01_api_ready(self):
response = model.run_on_unit(self.lead_unit_name, curl_command)
if response["Code"] == "0":
return
logging.warning(
"Unexpected curl response: {}. Retrying in 30s.".format(response)
)
logging.warning("Unexpected curl response: {}. Retrying in 30s.".format(response))
time.sleep(30)

# we didn't get rc=0 in the allowed time, fail the test
Expand All @@ -59,14 +57,9 @@ def test_01_api_ready(self):
def test_02_nrpe_http_check(self):
"""Verify nrpe check exists."""
expected_nrpe_check = (
"command[check_prometheus_blackbox_exporter_http]={} -I 127.0.0.1 "
"-p {} -u {}"
).format(
"/usr/lib/nagios/plugins/check_http", DEFAULT_API_PORT, DEFAULT_API_URL
)
logging.debug(
"Verify the nrpe check is created and has the required content..."
)
"command[check_prometheus_blackbox_exporter_http]={} -I 127.0.0.1 -p {} -u {}"
).format("/usr/lib/nagios/plugins/check_http", DEFAULT_API_PORT, DEFAULT_API_URL)
logging.debug("Verify the nrpe check is created and has the required content...")
cmd = "cat /etc/nagios/nrpe.d/check_prometheus_blackbox_exporter_http.cfg"
result = model.run_on_unit(self.lead_unit_name, cmd)
code = result.get("Code")
Expand Down
19 changes: 4 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,20 @@ allowlist_externals =

[testenv:lint]
commands =
flake8
black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
pflake8
black --check .
deps =
black
flake8
flake8-docstrings
flake8-import-order
pep8-naming
flake8-colors

[flake8]
exclude =
.git,
__pycache__,
.tox,
charmhelpers,
mod,
.build

max-line-length = 88
max-complexity = 10
pyproject-flake8

[testenv:black]
commands =
black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
black .
deps =
black

Expand Down