From 3918862047e8d921ecb1a513f7d4afeb6c7b0c28 Mon Sep 17 00:00:00 2001 From: "salt-extensions-renovatebot[bot]" <182623858+salt-extensions-renovatebot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 04:40:02 +0000 Subject: [PATCH] Update dependency https://github.com/lkubb/salt-extension-copier to v0.4.2 --- .copier-answers.yml | 9 +- .github/workflows/pr.yml | 12 ++ .github/workflows/tag.yml | 16 ++ .gitignore | 1 + .pre-commit-config.yaml | 72 +++++---- .pre-commit-hooks/make-autodocs.py | 8 +- .pylintrc | 142 ++++++++---------- CODE-OF-CONDUCT.md | 12 ++ CONTRIBUTING.md | 5 + README.md | 99 +++++++++--- docs/conf.py | 11 +- docs/topics/installation.md | 8 - noxfile.py | 130 ++++++---------- pyproject.toml | 95 ++++++------ .../prometheus/engines/prometheus_mod.py | 1 + src/saltext/prometheus/loader.py | 1 + .../returners/prometheus_textfile.py | 1 + tests/conftest.py | 26 +++- tests/support/mock.py | 7 +- tests/unit/conftest.py | 5 + .../test_prometheus_textfile_return.py | 2 +- 21 files changed, 379 insertions(+), 284 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 3938c69..329f116 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,10 +1,14 @@ # Autogenerated. Do not edit this by hand, use `copier update`. --- -_commit: 0.2.6 +_commit: 0.4.2 _src_path: https://github.com/lkubb/salt-extension-copier author: EITR Technologies, LLC author_email: devops@eitr.tech +coc_contact: '' +copyright_begin: 2024 +deploy_docs: rolling docs_url: '' +integration_name: Prometheus license: apache loaders: - engine @@ -14,9 +18,12 @@ no_saltext_namespace: false package_name: prometheus project_name: prometheus python_requires: '3.8' +relax_pylint: false salt_version: '3005' source_url: https://github.com/salt-extensions/saltext-prometheus ssh_fixtures: false summary: Salt Extension for interacting with Prometheus +test_containers: false tracker_url: https://github.com/salt-extensions/saltext-prometheus/issues url: https://github.com/salt-extensions/saltext-prometheus +workflows: org diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3a04455..5356b9d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,3 +1,7 @@ +<<<<<<< before updating +======= +--- +>>>>>>> after updating name: Pull Request or Push on: @@ -13,7 +17,15 @@ jobs: name: CI uses: salt-extensions/central-artifacts/.github/workflows/ci.yml@main with: +<<<<<<< before updating setup-vault: true permissions: contents: write +======= + deploy-docs: true + permissions: + contents: write + id-token: write + pages: write +>>>>>>> after updating pull-requests: read diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index abdd5e7..caeab4d 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -1,3 +1,7 @@ +<<<<<<< before updating +======= +--- +>>>>>>> after updating name: Tagged Releases on: @@ -16,17 +20,29 @@ jobs: - name: Extract tag name id: get_version +<<<<<<< before updating run: echo "::set-output name=version::$(echo ${GITHUB_REF#refs/tags/v})" +======= + run: echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" +>>>>>>> after updating call_central_workflow: needs: get_tag_version uses: salt-extensions/central-artifacts/.github/workflows/ci.yml@main with: +<<<<<<< before updating setup-vault: true +======= + deploy-docs: true +>>>>>>> after updating release: true version: ${{ needs.get_tag_version.outputs.version }} permissions: contents: write id-token: write +<<<<<<< before updating +======= + pages: write +>>>>>>> after updating pull-requests: read secrets: inherit diff --git a/.gitignore b/.gitignore index e9a082d..ee310d2 100644 --- a/.gitignore +++ b/.gitignore @@ -102,6 +102,7 @@ celerybeat.pid *.sage.py # Environments +!.envrc .env .venv env/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52af702..eeffecf 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,16 +2,16 @@ minimum_pre_commit_version: 2.4.0 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - - id: check-merge-conflict # Check for files that contain merge conflict strings. - - id: trailing-whitespace # Trims trailing whitespace. + - id: check-merge-conflict # Check for files that contain merge conflict strings. + args: [--assume-in-merge] + - id: trailing-whitespace # Trim trailing whitespace. args: [--markdown-linebreak-ext=md] - - id: mixed-line-ending # Replaces or checks mixed line ending. + - id: mixed-line-ending # Ensure files use UNIX-style newlines only. args: [--fix=lf] - - id: end-of-file-fixer # Makes sure files end in a newline and only a newline. - - id: check-merge-conflict # Check for files that contain merge conflict strings. - - id: check-ast # Simply check whether files parse as valid python. + - id: end-of-file-fixer # Ensure files end with a newline. + - id: check-ast # Check whether files parse as valid Python. # ----- Formatting ----------------------------------------------------------------------------> - repo: https://github.com/saltstack/pre-commit-remove-import-headers @@ -24,7 +24,7 @@ repos: - id: check-cli-examples name: Check CLI examples on execution modules entry: python .pre-commit-hooks/check-cli-examples.py - language: system + language: python files: ^src/saltext/prometheus/modules/.*\.py$ - repo: local @@ -32,7 +32,7 @@ repos: - id: check-docs name: Check rST doc files exist for modules/states entry: python .pre-commit-hooks/make-autodocs.py - language: system + language: python pass_filenames: false - repo: https://github.com/s0undt3ch/salt-rewrite @@ -56,7 +56,7 @@ repos: args: [--silent, -E, fix_docstrings] - repo: https://github.com/asottile/pyupgrade - rev: v2.37.2 + rev: v3.16.0 hooks: - id: pyupgrade name: Rewrite Code to be Py3.8+ @@ -65,35 +65,35 @@ repos: ] exclude: src/saltext/prometheus/version.py - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.10.0 + - repo: https://github.com/PyCQA/isort + rev: 5.13.2 hooks: - - id: reorder-python-imports + - id: isort args: [ - --py38-plus, + --py 38, ] - exclude: src/saltext/prometheus/version.py + exclude: src/saltext/prometheus/(__init__|version).py - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 24.8.0 hooks: - id: black args: [-l 100] exclude: src/saltext/prometheus/version.py - repo: https://github.com/adamchainz/blacken-docs - rev: v1.12.1 + rev: 1.18.0 hooks: - id: blacken-docs args: [--skip-errors] files: ^(docs/.*\.rst|src/saltext/prometheus/.*\.py)$ additional_dependencies: - - black==22.6.0 + - black==24.2.0 # <---- Formatting ----------------------------------------------------------------------------- # ----- Security ------------------------------------------------------------------------------> - repo: https://github.com/PyCQA/bandit - rev: "1.7.4" + rev: 1.7.9 hooks: - id: bandit alias: bandit-salt @@ -101,7 +101,7 @@ repos: args: [--silent, -lll, --skip, B701] exclude: src/saltext/prometheus/version.py - repo: https://github.com/PyCQA/bandit - rev: "1.7.4" + rev: 1.7.9 hooks: - id: bandit alias: bandit-tests @@ -111,29 +111,35 @@ repos: # <---- Security ------------------------------------------------------------------------------- # ----- Code Analysis -------------------------------------------------------------------------> - - repo: https://github.com/saltstack/mirrors-nox - rev: v2021.6.12 + + - repo: local hooks: - id: nox alias: lint-src name: Lint Source Code + language: python + entry: nox -e lint-code-pre-commit -- files: ^((setup|noxfile)|src/.*)\.py$ require_serial: true - args: - - -e - - lint-code-pre-commit - - -- + additional_dependencies: + - nox==2024.4.15 + - uv==0.4.0 # Makes this hook much faster - - repo: https://github.com/saltstack/mirrors-nox - rev: v2021.6.12 - hooks: - id: nox alias: lint-tests name: Lint Tests + language: python + entry: nox -e lint-tests-pre-commit -- files: ^tests/.*\.py$ require_serial: true - args: - - -e - - lint-tests-pre-commit - - -- + additional_dependencies: + - nox==2024.4.15 + - uv==0.4.0 # Makes this hook much faster + + - repo: https://github.com/Mateusz-Grzelinski/actionlint-py + rev: 1ca29a1b5d949b3586800190ad6cc98317cb43b8 # v1.7.1.15 + hooks: + - id: actionlint + additional_dependencies: + - shellcheck-py>=0.9.0.5 # <---- Code Analysis -------------------------------------------------------------------------- diff --git a/.pre-commit-hooks/make-autodocs.py b/.pre-commit-hooks/make-autodocs.py index 88e9088..2fdce95 100644 --- a/.pre-commit-hooks/make-autodocs.py +++ b/.pre-commit-hooks/make-autodocs.py @@ -3,7 +3,6 @@ import subprocess from pathlib import Path - repo_path = Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode().strip()) src_dir = repo_path / "src" / "saltext" / "prometheus" doc_dir = repo_path / "docs" @@ -34,9 +33,14 @@ def write_module(rst_path, path, use_virtualname=True): virtualname = "``" + _find_virtualname(path) + "``" else: virtualname = make_import_path(path) + header_len = len(virtualname) + # The check-merge-conflict pre-commit hook chokes here: + # https://github.com/pre-commit/pre-commit-hooks/issues/100 + if header_len == 7: + header_len += 1 module_contents = f"""\ {virtualname} -{'='*len(virtualname)} +{'='*header_len} .. automodule:: {make_import_path(path)} :members: diff --git a/.pylintrc b/.pylintrc index 5692f3b..b304cb9 100755 --- a/.pylintrc +++ b/.pylintrc @@ -39,7 +39,7 @@ extension-pkg-whitelist= fail-on= # Specify a score threshold under which the program will exit with error. -fail-under=10 +fail-under=10.0 # Interpret the stdin as a python script, whose filename needs to be passed as # the module_or_package argument. @@ -59,10 +59,11 @@ ignore-paths= # Emacs file locks ignore-patterns=^\.# -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis). It -# supports qualified module names, as well as Unix pattern matching. +# List of module names for which member attributes should not be checked and +# will not be imported (useful for modules/projects where namespaces are +# manipulated during runtime and thus existing member attributes cannot be +# deduced by static analysis). It supports qualified module names, as well as +# Unix pattern matching. ignored-modules= # Python code to execute, usually for sys.path manipulation such as @@ -86,9 +87,13 @@ load-plugins= # Pickle collected data for later comparisons. persistent=yes +# Resolve imports to .pyi stubs if available. May reduce no-member messages and +# increase not-an-iterable messages. +prefer-stubs=no + # Minimum Python version to use for version dependent checks. Will default to # the version used to run pylint. -py-version=3.10 +py-version=3.8 # Discover python modules and packages in the file system subtree. recursive=no @@ -285,19 +290,19 @@ exclude-too-few-public-methods= ignored-parents= # Maximum number of arguments for function / method. -max-args=15 +max-args=35 # Maximum number of attributes for a class (see R0902). -max-attributes=7 +max-attributes=15 # Maximum number of boolean expressions in an if statement (see R0916). -max-bool-expr=5 +max-bool-expr=8 # Maximum number of branch for function / method body. -max-branches=12 +max-branches=48 # Maximum number of locals for function / method body. -max-locals=15 +max-locals=40 # Maximum number of parents for a class (see R0901). max-parents=7 @@ -306,10 +311,10 @@ max-parents=7 max-public-methods=25 # Maximum number of return / yield for function / method body. -max-returns=6 +max-returns=10 # Maximum number of statements in function / method body. -max-statements=50 +max-statements=100 # Minimum number of public methods for a class (see R0903). min-public-methods=2 @@ -324,7 +329,7 @@ overgeneral-exceptions=builtins.BaseException,builtins.Exception [FORMAT] # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= +expected-line-ending-format=LF # Regexp for a line that is allowed to be longer than the limit. ignore-long-lines=^\s*(# )??$ @@ -337,10 +342,10 @@ indent-after-paren=4 indent-string=' ' # Maximum number of characters on a single line. -max-line-length=100 +max-line-length=120 # Maximum number of lines in a module. -max-module-lines=2000 +max-module-lines=3000 # Allow the body of a class to be on the same line as the declaration if body # contains single statement. @@ -421,43 +426,18 @@ confidence=HIGH, # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use "--disable=all --enable=classes # --disable=W". -disable=R, - locally-disabled, - file-ignored, - unexpected-special-method-signature, - import-error, - no-member, - unsubscriptable-object, - blacklisted-name, - invalid-name, - missing-docstring, - empty-docstring, - unidiomatic-typecheck, - wrong-import-order, - ungrouped-imports, - wrong-import-position, - bad-mcs-method-argument, - bad-mcs-classmethod-argument, - line-too-long, - too-many-lines, - bad-continuation, - exec-used, - attribute-defined-outside-init, - protected-access, - reimported, - fixme, - global-statement, - unused-variable, - unused-argument, - redefined-outer-name, - redefined-builtin, - undefined-loop-variable, - logging-format-interpolation, - invalid-format-index, - line-too-long, - import-outside-toplevel, - deprecated-method, - keyword-arg-before-vararg, +disable=duplicate-code, + fixme, + keyword-arg-before-vararg, + line-too-long, + logging-fstring-interpolation, + missing-class-docstring, + missing-function-docstring, + missing-module-docstring, + protected-access, + too-few-public-methods, + ungrouped-imports, + wrong-import-position # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -495,6 +475,11 @@ max-nested-blocks=5 # printed. never-returning-functions=sys.exit,argparse.parse_error +# Let 'consider-using-join' be raised when the separator to join on would be +# non-empty (resulting in expected fixes of the type: ``"- " + " - +# ".join(items)``) +suggest-join-with-non-empty-separator=yes + [REPORTS] @@ -509,8 +494,9 @@ evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor # used to format the message information. See doc for all details. msg-template= -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio). You can also give a reporter class, e.g. +# Set the output format. Available formats are: text, parseable, colorized, +# json2 (improved json format), json (old json format) and msvs (visual +# studio). You can also give a reporter class, e.g. # mypackage.mymodule.MyReporterClass. #output-format= @@ -544,8 +530,8 @@ min-similarity-lines=4 # Limits count of emitted suggestions for spelling mistakes. max-spelling-suggestions=4 -# Spelling dictionary name. No available dictionaries : You need to install the -# system dependency for enchant to work.. +# Spelling dictionary name. No available dictionaries : You need to install +# both the python package and the system dependency for enchant to work. spelling-dict= # List of comma separated words that should be considered directives if they @@ -633,27 +619,27 @@ signature-mutators= # List of additional names supposed to be defined in builtins. Remember that # you should avoid defining new builtins when possible. additional-builtins=__opts__, - __salt__, - __pillar__, - __grains__, - __context__, - __runner__, - __ret__, - __env__, - __low__, - __states__, - __lowstate__, - __running__, - __active_provider_name__, - __master_opts__, - __jid_event__, - __instance_id__, - __salt_system_encoding__, - __proxy__, - __serializers__, - __reg__, - __executors__, - __events__ + __salt__, + __pillar__, + __grains__, + __context__, + __runner__, + __ret__, + __env__, + __low__, + __states__, + __lowstate__, + __running__, + __active_provider_name__, + __master_opts__, + __jid_event__, + __instance_id__, + __salt_system_encoding__, + __proxy__, + __serializers__, + __reg__, + __executors__, + __events__ # Tells whether unused global variables should be treated as a violation. allow-global-unused-variables=yes diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md index 412404b..819fec7 100644 --- a/CODE-OF-CONDUCT.md +++ b/CODE-OF-CONDUCT.md @@ -3,11 +3,19 @@ ## Our Pledge We as members, contributors, and leaders pledge to make participation in Salt +<<<<<<< before updating Extension Modules for Prometheus project and our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. +======= +Extension Modules for Prometheus project and our community a +harassment-free experience for everyone, regardless of age, body size, visible +or invisible disability, ethnicity, sex characteristics, gender identity and +expression, level of experience, education, socio-economic status, nationality, +personal appearance, race, religion, or sexual identity and orientation. +>>>>>>> after updating We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. @@ -59,7 +67,11 @@ representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be +<<<<<<< before updating reported to the community leaders responsible for enforcement at devops@eitr.tech. +======= +reported to the community leaders responsible for enforcement. +>>>>>>> after updating All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4b00ec..de47577 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,11 @@ Thanks for your interest in contributing to the Salt Extension Modules for +<<<<<<< before updating Prometheus! We welcome any contribution, large or small - from adding a new feature to fixing a single letter typo. +======= +Prometheus! We welcome any contribution, large or small - from +adding a new feature to fixing a single letter typo. +>>>>>>> after updating This is a companion to the Salt Project and the [Salt Contributing Guide][salt-contributing] should be considered the default for this project. diff --git a/README.md b/README.md index b13494f..87397e1 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,32 @@ This is a collection of Salt extension modules for use with Prometheus. ## Security -If you think you've found a security vulnerability, see -[Salt's security guide][security]. +If you discover a security vulnerability, please refer +to [Salt's security guide][security]. ## User Documentation +<<<<<<< before updating This README is more for contributing to the project. If you just want to get started, check out the [User Documentation][docs]. +======= +For setup and usage instructions, please refer to the +module docstrings (for now, documentation is coming!). +>>>>>>> after updating ## Contributing -The saltext-prometheus project team welcomes contributions from the community. +The saltext-prometheus project welcomes contributions from anyone! -The [Salt Contributing guide][salt-contributing] has a lot of relevant -information, but if you'd like to jump right in here's how to get started: +The [Salt Extensions guide][salt-extensions-guide] provides comprehensive instructions on all aspects +of Salt extension development, including [writing tests][writing-tests], [running tests][running-tests], +[writing documentation][writing-docs] and [rendering the docs][rendering-docs]. +### Quickstart +To get started contributing, first clone this repository (or your fork): + +<<<<<<< before updating # Clone the repo git clone --origin salt git@github.com:salt-extensions/saltext-prometheus.git @@ -51,35 +61,80 @@ information, but if you'd like to jump right in here's how to get started: # Build the docs, serve, and view in your web browser: python -m nox -e docs && (cd docs/_build/html; python -m webbrowser localhost:8000; python -m http.server; cd -) +======= +```bash +# Clone the repo +git clone --origin upstream git@github.com:salt-extensions/saltext-prometheus.git + +# Change to the repo dir +cd saltext-prometheus +``` + +#### Automatic +If you have installed [direnv][direnv], allowing the project's `.envrc` ensures +a proper development environment is present and the virtual environment is active. + +Without `direnv`, you can still run the automation explicitly: + +```bash +python3 tools/initialize.py +source .venv/bin/activate +``` + +#### Manual +Please follow the [first steps][first-steps], skipping the repository initialization and first commit. + +### Pull request + +Always make changes in a feature branch: -Writing code isn't the only way to contribute! We value contributions in any of -these areas: +```bash +git switch -c my-feature-branch +``` -* Documentation - especially examples of how to use this module to solve - specific problems. -* Triaging [issues][issues] and participating in [discussions][discussions] -* Reviewing [Pull Requests][PRs] (we really like - [Conventional Comments][comments]!) +To [submit a Pull Request][submitting-pr], you'll need a fork of this repository in +your own GitHub account. If you followed the instructions above, +set your fork as the `origin` remote now: -You could also contribute in other ways: +```bash +git remote add origin git@github.com:.git +``` +>>>>>>> after updating + +Ensure you followed the [first steps][first-steps] and commit your changes, fixing any +failing `pre-commit` hooks. Then push the feature branch to your fork and submit a PR. + +### Ways to contribute + +Contributions come in many forms, and they’re all valuable! Here are some ways you can help +without writing code: + +* **Documentation**: Especially examples showing how to use this project + to solve specific problems. +* **Triaging issues**: Help manage [issues][issues] and participate in [discussions][discussions]. +* **Reviewing [Pull Requests][PRs]**: We especially appreciate reviews using [Conventional Comments][comments]. + +You can also contribute by: * Writing blog posts -* Posting on social media about how you used Salt+Prometheus to solve your - problems, including videos +* Sharing your experiences using Salt + Prometheus + on social media * Giving talks at conferences * Publishing videos -* Asking/answering questions in IRC, Slack, or email groups +* Engaging in IRC, Discord or email groups Any of these things are super valuable to our community, and we sincerely appreciate every contribution! - -For more information, build the docs and head over to http://localhost:8000/ — -that's where you'll find the rest of the documentation. - - [security]: https://github.com/saltstack/salt/blob/master/SECURITY.md -[salt-contributing]: https://docs.saltproject.io/en/master/topics/development/contributing.html +[salt-extensions-guide]: https://salt-extensions.github.io/salt-extension-copier/ +[writing-tests]: https://salt-extensions.github.io/salt-extension-copier/topics/testing/writing.html +[running-tests]: https://salt-extensions.github.io/salt-extension-copier/topics/testing/running.html +[writing-docs]: https://salt-extensions.github.io/salt-extension-copier/topics/documenting/writing.html +[rendering-docs]: https://salt-extensions.github.io/salt-extension-copier/topics/documenting/building.html +[first-steps]: https://salt-extensions.github.io/salt-extension-copier/topics/creation.html#initialize-the-python-virtual-environment +[submitting-pr]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork +[direnv]: https://direnv.net [issues]: https://github.com/salt-extensions/saltext-prometheus/issues [PRs]: https://github.com/salt-extensions/saltext-prometheus/pulls [discussions]: https://github.com/salt-extensions/saltext-prometheus/discussions diff --git a/docs/conf.py b/docs/conf.py index 48fc30d..5da3ba0 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -42,12 +42,12 @@ # -- Project information ----------------------------------------------------- this_year = datetime.datetime.today().year -if this_year == 2021: - copyright_year = 2021 +if this_year == 2024: + copyright_year = "2024" else: - copyright_year = f"2021 - {this_year}" + copyright_year = f"2024 - {this_year}" project = dist.metadata["Summary"] -author = dist.metadata["Author"] +author = dist.metadata.get("Author") if author is None: # Core metadata is serialized differently with pyproject.toml: @@ -79,6 +79,8 @@ # -- General configuration --------------------------------------------------- +linkcheck_ignore = [r"http://localhost:\d+"] + # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. @@ -92,6 +94,7 @@ "sphinx.ext.coverage", "sphinx_copybutton", "sphinxcontrib.spelling", + "saltdomain", "sphinxcontrib.towncrier.ext", "myst_parser", "sphinx_inline_tabs", diff --git a/docs/topics/installation.md b/docs/topics/installation.md index 79cec87..b4ef336 100644 --- a/docs/topics/installation.md +++ b/docs/topics/installation.md @@ -22,15 +22,7 @@ pip install saltext-prometheus ``` ::: -:::{important} -Currently, there is [an issue][issue-second-saltext] where the installation of a Saltext fails silently -if the environment already has another one installed. You can workaround this by -removing all Saltexts and reinstalling them in one transaction. -::: - :::{hint} Saltexts are not distributed automatically via the fileserver like custom modules, they need to be installed on each node you want them to be available on. ::: - -[issue-second-saltext]: https://github.com/saltstack/salt/issues/65433 diff --git a/noxfile.py b/noxfile.py index f31cee7..6e2c516 100755 --- a/noxfile.py +++ b/noxfile.py @@ -1,11 +1,10 @@ -# pylint: disable=missing-module-docstring,import-error,protected-access,missing-function-docstring import datetime import json import os -import pathlib import shutil import sys import tempfile +from importlib import metadata from pathlib import Path import nox @@ -17,6 +16,9 @@ nox.options.reuse_existing_virtualenvs = True # Don't fail on missing interpreters nox.options.error_on_missing_interpreters = False +# Speed up all sessions by using uv if possible +if tuple(map(int, metadata.version("nox").split("."))) >= (2024, 3): + nox.options.default_venv_backend = "uv|virtualenv" # Python versions to test against PYTHON_VERSIONS = ("3", "3.8", "3.9", "3.10") @@ -25,10 +27,10 @@ os.environ.get("JENKINS_URL") or os.environ.get("CI") or os.environ.get("DRONE") is not None ) PIP_INSTALL_SILENT = CI_RUN is False -SKIP_REQUIREMENTS_INSTALL = "SKIP_REQUIREMENTS_INSTALL" in os.environ +SKIP_REQUIREMENTS_INSTALL = os.environ.get("SKIP_REQUIREMENTS_INSTALL", "0") == "1" EXTRA_REQUIREMENTS_INSTALL = os.environ.get("EXTRA_REQUIREMENTS_INSTALL") -COVERAGE_VERSION_REQUIREMENT = "coverage==5.2" +COVERAGE_REQUIREMENT = os.environ.get("COVERAGE_REQUIREMENT") or "coverage==7.5.1" SALT_REQUIREMENT = os.environ.get("SALT_REQUIREMENT") or "salt>=3005" if SALT_REQUIREMENT == "salt==master": SALT_REQUIREMENT = "git+https://github.com/saltstack/salt.git@master" @@ -37,7 +39,7 @@ os.environ["PYTHONDONTWRITEBYTECODE"] = "1" # Global Path Definitions -REPO_ROOT = pathlib.Path(__file__).resolve().parent +REPO_ROOT = Path(__file__).resolve().parent # Change current directory to REPO_ROOT os.chdir(str(REPO_ROOT)) @@ -85,16 +87,17 @@ def _install_requirements( install_extras=None, ): install_extras = install_extras or [] + no_progress = "--progress-bar=off" + if isinstance(session._runner.venv, VirtualEnv) and session._runner.venv.venv_backend == "uv": + no_progress = "--no-progress" if SKIP_REQUIREMENTS_INSTALL is False: # Always have the wheel package installed - session.install("--progress-bar=off", "wheel", silent=PIP_INSTALL_SILENT) + session.install(no_progress, "wheel", silent=PIP_INSTALL_SILENT) if install_coverage_requirements: - session.install( - "--progress-bar=off", COVERAGE_VERSION_REQUIREMENT, silent=PIP_INSTALL_SILENT - ) + session.install(no_progress, COVERAGE_REQUIREMENT, silent=PIP_INSTALL_SILENT) if install_salt: - session.install("--progress-bar=off", SALT_REQUIREMENT, silent=PIP_INSTALL_SILENT) + session.install(no_progress, SALT_REQUIREMENT, silent=PIP_INSTALL_SILENT) if install_test_requirements: install_extras.append("tests") @@ -106,7 +109,7 @@ def _install_requirements( "EXTRA_REQUIREMENTS_INSTALL='%s'", EXTRA_REQUIREMENTS_INSTALL, ) - install_command = ["--progress-bar=off"] + install_command = [no_progress] install_command += [req.strip() for req in EXTRA_REQUIREMENTS_INSTALL.split()] session.install(*install_command, silent=PIP_INSTALL_SILENT) @@ -172,7 +175,7 @@ def tests(session): if arg.startswith(f"tests{os.sep}"): break try: - pathlib.Path(arg).resolve().relative_to(REPO_ROOT / "tests") + Path(arg).resolve().relative_to(REPO_ROOT / "tests") break except ValueError: continue @@ -248,7 +251,7 @@ def _lint(session, rcfile, flags, paths, tee_output=True): install_salt=False, install_coverage_requirements=False, install_test_requirements=False, - install_extras=["dev", "tests"], + install_extras=["lint", "tests"], ) if tee_output: @@ -311,12 +314,25 @@ def _lint_pre_commit(session, rcfile, flags, paths): ) # Let's patch nox to make it run inside the pre-commit virtualenv - session._runner.venv = VirtualEnv( - os.environ["VIRTUAL_ENV"], - interpreter=session._runner.func.python, - reuse_existing=True, - venv=True, - ) + try: + # nox >= 2024.03.02 + # pylint: disable=unexpected-keyword-arg + venv = VirtualEnv( + os.environ["VIRTUAL_ENV"], + interpreter=session._runner.func.python, + reuse_existing=True, + venv_backend="venv", + ) + except TypeError: + # nox < 2024.03.02 + # pylint: disable=unexpected-keyword-arg + venv = VirtualEnv( + os.environ["VIRTUAL_ENV"], + interpreter=session._runner.func.python, + reuse_existing=True, + venv=True, + ) + session._runner.venv = venv _lint(session, rcfile, flags, paths, tee_output=False) @@ -348,7 +364,7 @@ def lint_tests(session): Run PyLint against the test suite. Set PYLINT_REPORT to a path to capture output. """ flags = [ - "--disable=I,redefined-outer-name,missing-function-docstring,no-member,missing-module-docstring" + "--disable=I,redefined-outer-name,no-member,missing-module-docstring,missing-function-docstring,missing-class-docstring,attribute-defined-outside-init,inconsistent-return-statements,too-few-public-methods,too-many-public-methods", ] if session.posargs: paths = session.posargs @@ -376,7 +392,7 @@ def lint_tests_pre_commit(session): Run PyLint against the code and the test suite. Set PYLINT_REPORT to a path to capture output. """ flags = [ - "--disable=I,redefined-outer-name,missing-function-docstring,no-member,missing-module-docstring", + "--disable=I,redefined-outer-name,no-member,missing-module-docstring,missing-function-docstring,missing-class-docstring,attribute-defined-outside-init,inconsistent-return-statements,too-few-public-methods,too-many-public-methods", ] if session.posargs: paths = session.posargs @@ -411,37 +427,8 @@ def docs(session): os.chdir(str(REPO_ROOT)) -@nox.session(name="docs-html", python="3") -@nox.parametrize("clean", [False, True]) -@nox.parametrize("include_api_docs", [False, True]) -def docs_html(session, clean, include_api_docs): - """ - Build Sphinx HTML Documentation - - TODO: Add option for `make linkcheck` and `make coverage` - calls via Sphinx. Ran into problems with two when - using Furo theme and latest Sphinx. - """ - _install_requirements( - session, - install_coverage_requirements=False, - install_test_requirements=False, - install_source=True, - install_extras=["docs"], - ) - if include_api_docs: - gen_api_docs(session) - build_dir = Path("docs", "_build", "html") - sphinxopts = "-Wn" - if clean: - sphinxopts += "E" - args = [sphinxopts, "--keep-going", "docs", str(build_dir)] - session.run("sphinx-build", *args, external=True) - - @nox.session(name="docs-dev", python="3") -@nox.parametrize("clean", [False, True]) -def docs_dev(session, clean) -> None: +def docs_dev(session): """ Build and serve the Sphinx HTML documentation, with live reloading on file changes, via sphinx-autobuild. @@ -456,10 +443,18 @@ def docs_dev(session, clean) -> None: install_extras=["docs", "docsauto"], ) - # Launching LIVE reloading Sphinx session build_dir = Path("docs", "_build", "html") - args = ["--watch", ".", "--open-browser", "docs", str(build_dir)] - if clean and build_dir.exists(): + + # Allow specifying sphinx-autobuild options, like --host. + args = ["--watch", "."] + session.posargs + if not any(arg.startswith("--host") for arg in args): + # If the user is overriding the host to something other than localhost, + # it's likely they are rendering on a remote/headless system and don't + # want the browser to open. + args.append("--open-browser") + args += ["docs", str(build_dir)] + + if build_dir.exists(): shutil.rmtree(build_dir) session.run("sphinx-autobuild", *args) @@ -500,30 +495,3 @@ def docs_crosslink_info(session): "python", "-m", "sphinx.ext.intersphinx", mapping_entry[0].rstrip("/") + "/objects.inv" ) os.chdir(str(REPO_ROOT)) - - -@nox.session(name="gen-api-docs", python="3") -def gen_api_docs(session): - """ - Generate API Docs - """ - _install_requirements( - session, - install_coverage_requirements=False, - install_test_requirements=False, - install_source=True, - install_extras=["docs"], - ) - try: - shutil.rmtree("docs/ref") - except FileNotFoundError: - pass - session.run( - "sphinx-apidoc", - "--implicit-namespaces", - "--module-first", - "-o", - "docs/ref/", - "src/saltext", - "src/saltext/prometheus/config/schemas", - ) diff --git a/pyproject.toml b/pyproject.toml index 4447e1f..15cf7ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,10 +51,8 @@ Tracker = "https://github.com/salt-extensions/saltext-prometheus/issues" [project.optional-dependencies] changelog = ["towncrier==22.12.0"] dev = [ - "nox", - "pre-commit>=2.4.0", - "pylint", - "saltpylint", + "nox[uv]>=2024.3", + "pre-commit>=2.21.0", ] docs = [ "sphinx", @@ -69,12 +67,11 @@ docs = [ ] docsauto = ["sphinx-autobuild"] lint = [ - "pylint", - "saltpylint", + "pylint==3.2.6", ] tests = [ - "pytest>=6.1.0", - "pytest-salt-factories>=1.0.0rc19", + "pytest>=7.2.0", + "pytest-salt-factories>=1.0.0", ] [project.entry-points."salt.loader"] @@ -104,42 +101,48 @@ build_dir = "build/sphinx" [tool.black] line-length = 100 +[tool.isort] +force_single_line = true +skip = ["src/saltext/prometheus/__init__.py"] +profile = "black" +line_length = 100 + [tool.towncrier] - package = "saltext.prometheus" - filename = "CHANGELOG.md" - template = "changelog/.template.jinja" - directory = "changelog/" - start_string = "# Changelog\n" - underlines = ["", "", ""] - title_format = "## {version} ({project_date})" - issue_format = "[#{issue}](https://github.com/salt-extensions/saltext-prometheus/issues/{issue})" - - [[tool.towncrier.type]] - directory = "removed" - name = "Removed" - showcontent = true - - [[tool.towncrier.type]] - directory = "deprecated" - name = "Deprecated" - showcontent = true - - [[tool.towncrier.type]] - directory = "changed" - name = "Changed" - showcontent = true - - [[tool.towncrier.type]] - directory = "fixed" - name = "Fixed" - showcontent = true - - [[tool.towncrier.type]] - directory = "added" - name = "Added" - showcontent = true - - [[tool.towncrier.type]] - directory = "security" - name = "Security" - showcontent = true +package = "saltext.prometheus" +filename = "CHANGELOG.md" +template = "changelog/.template.jinja" +directory = "changelog/" +start_string = "# Changelog\n" +underlines = ["", "", ""] +title_format = "## {version} ({project_date})" +issue_format = "[#{issue}](https://github.com/salt-extensions/saltext-prometheus/issues/{issue})" + +[[tool.towncrier.type]] +directory = "removed" +name = "Removed" +showcontent = true + +[[tool.towncrier.type]] +directory = "deprecated" +name = "Deprecated" +showcontent = true + +[[tool.towncrier.type]] +directory = "changed" +name = "Changed" +showcontent = true + +[[tool.towncrier.type]] +directory = "fixed" +name = "Fixed" +showcontent = true + +[[tool.towncrier.type]] +directory = "added" +name = "Added" +showcontent = true + +[[tool.towncrier.type]] +directory = "security" +name = "Security" +showcontent = true diff --git a/src/saltext/prometheus/engines/prometheus_mod.py b/src/saltext/prometheus/engines/prometheus_mod.py index 28f5829..3a7afc6 100644 --- a/src/saltext/prometheus/engines/prometheus_mod.py +++ b/src/saltext/prometheus/engines/prometheus_mod.py @@ -1,6 +1,7 @@ """ Salt engine module """ + import logging log = logging.getLogger(__name__) diff --git a/src/saltext/prometheus/loader.py b/src/saltext/prometheus/loader.py index 634ce85..3a57c91 100644 --- a/src/saltext/prometheus/loader.py +++ b/src/saltext/prometheus/loader.py @@ -2,6 +2,7 @@ Define the required entry-points functions in order for Salt to know what and from where it should load this extension's loaders """ + from . import PACKAGE_ROOT # pylint: disable=unused-import diff --git a/src/saltext/prometheus/returners/prometheus_textfile.py b/src/saltext/prometheus/returners/prometheus_textfile.py index 90edf6e..4d8fc92 100644 --- a/src/saltext/prometheus/returners/prometheus_textfile.py +++ b/src/saltext/prometheus/returners/prometheus_textfile.py @@ -123,6 +123,7 @@ prometheus_textfile.raw_version: true """ + import logging import os import time diff --git a/tests/conftest.py b/tests/conftest.py index d73622a..0d75e98 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ import os import pytest -from saltext.prometheus import PACKAGE_ROOT from saltfactories.utils import random_string +from saltext.prometheus import PACKAGE_ROOT # Reset the root logger to its default level(because salt changed it) logging.root.setLevel(logging.WARNING) @@ -30,10 +30,26 @@ def salt_factories_config(): @pytest.fixture(scope="package") -def master(salt_factories): - return salt_factories.salt_master_daemon(random_string("master-")) +def master_config(): + """ + Salt master configuration overrides for integration tests. + """ + return {} + + +@pytest.fixture(scope="package") +def master(salt_factories, master_config): + return salt_factories.salt_master_daemon(random_string("master-"), overrides=master_config) + + +@pytest.fixture(scope="package") +def minion_config(): + """ + Salt minion configuration overrides for integration tests. + """ + return {} @pytest.fixture(scope="package") -def minion(master): - return master.salt_minion_daemon(random_string("minion-")) +def minion(master, minion_config): + return master.salt_minion_daemon(random_string("minion-"), overrides=minion_config) diff --git a/tests/support/mock.py b/tests/support/mock.py index 6e167e0..38be87e 100644 --- a/tests/support/mock.py +++ b/tests/support/mock.py @@ -11,6 +11,7 @@ Note: mock >= 2.0.0 required since unittest.mock does not have MagicMock.assert_called in Python < 3.6. """ + # pylint: disable=unused-import,function-redefined import copy import errno @@ -18,16 +19,16 @@ import sys from unittest import mock from unittest.mock import ANY -from unittest.mock import call -from unittest.mock import create_autospec from unittest.mock import DEFAULT from unittest.mock import FILTER_DIR from unittest.mock import MagicMock from unittest.mock import Mock from unittest.mock import NonCallableMagicMock from unittest.mock import NonCallableMock -from unittest.mock import patch from unittest.mock import PropertyMock +from unittest.mock import call +from unittest.mock import create_autospec +from unittest.mock import patch from unittest.mock import sentinel import salt.utils.stringutils diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 3e3fa4a..b3b6ced 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,3 +1,5 @@ +import os + import pytest import salt.config @@ -17,6 +19,7 @@ def minion_opts(tmp_path): dirpath.mkdir(parents=True) opts[name] = str(dirpath) opts["log_file"] = "logs/minion.log" + opts["conf_file"] = os.path.join(opts["conf_dir"], "minion") return opts @@ -35,6 +38,7 @@ def master_opts(tmp_path): dirpath.mkdir(parents=True) opts[name] = str(dirpath) opts["log_file"] = "logs/master.log" + opts["conf_file"] = os.path.join(opts["conf_dir"], "master") return opts @@ -54,4 +58,5 @@ def syndic_opts(tmp_path): dirpath.mkdir(parents=True) opts[name] = str(dirpath) opts["log_file"] = "logs/syndic.log" + opts["conf_file"] = os.path.join(opts["conf_dir"], "syndic") return opts diff --git a/tests/unit/returners/test_prometheus_textfile_return.py b/tests/unit/returners/test_prometheus_textfile_return.py index 522807c..23b8d66 100644 --- a/tests/unit/returners/test_prometheus_textfile_return.py +++ b/tests/unit/returners/test_prometheus_textfile_return.py @@ -6,8 +6,8 @@ import pytest import salt.utils.files import salt.version -import saltext.prometheus.returners.prometheus_textfile as prometheus_textfile +import saltext.prometheus.returners.prometheus_textfile as prometheus_textfile from tests.support.mock import MagicMock from tests.support.mock import patch