diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 22e9f730..15eefc4e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -9,45 +9,33 @@ on: # NOLINT jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/statick + permissions: + id-token: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up Python 3.11 - uses: actions/setup-python@v1 + - name: Set up Python + uses: actions/setup-python@v5 with: python-version: '3.11' - - - uses: actions/cache@v3 - if: startsWith(runner.os, 'Linux') - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- + cache: 'pip' - name: Install tools run: | - python -m pip install --upgrade setuptools - python -m pip install --upgrade wheel - python -m pip install -r requirements-docs.txt - python -m pip install -r requirements.txt + pip install .[docs] - name: Build a binary wheel and a source tarball run: | - python setup.py sdist bdist_wheel - - - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{ secrets.PYPI_TEST_TOKEN }} - repository_url: https://test.pypi.org/legacy/ + pip install -q build + python -m build - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{ secrets.PYPI_TOKEN }} + uses: pypa/gh-action-pypi-publish@release/v1 - name: Sphinx lint uses: ammaraskar/sphinx-action@master @@ -55,7 +43,7 @@ jobs: docs-folder: 'docs/' - name: Publish documentation - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/build/html diff --git a/.github/workflows/publish_docker_image.yaml b/.github/workflows/publish_docker_image.yaml index 571ea943..17a91c1b 100644 --- a/.github/workflows/publish_docker_image.yaml +++ b/.github/workflows/publish_docker_image.yaml @@ -11,17 +11,17 @@ env: jobs: build-and-push-image: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Log in to the Container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -29,14 +29,14 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}} - name: Build and push Docker image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: docker push: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4db4860a..d977bf08 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,69 +14,36 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-latest, ubuntu-20.04, ubuntu-22.04, windows-latest] - python-version: ['3.9', '3.10', '3.11'] + os: [macos-latest, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: '16' - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - - uses: actions/cache@v3 - if: startsWith(runner.os, 'Linux') - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - uses: actions/cache@v3 - if: startsWith(runner.os, 'macOS') - with: - path: ~/Library/Caches/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - uses: actions/cache@v3 - if: startsWith(runner.os, 'Windows') - with: - path: ~\AppData\Local\pip\Cache - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- + cache: 'pip' - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install --upgrade -r requirements.txt - python -m pip install --upgrade mypy - python -m pip install --upgrade setuptools - python -m pip install --upgrade tox - python -m pip install --upgrade tox-gh-actions - python -m pip install --upgrade types-deprecated - python -m pip install --upgrade types-PyYAML - python -m pip install --upgrade types-tabulate - python -m pip install --upgrade wheel + pip install --upgrade pip + pip install .[docs,test] # Remove apt repos that are known to break from time to time. # See https://github.com/actions/virtual-environments/issues/323 - name: Remove broken apt repos [Ubuntu] - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' + if: runner.os == 'Linux' run: | for apt_file in `grep -lr microsoft /etc/apt/sources.list.d/`; do sudo rm $apt_file; done - # Use apt-get instead of apt as apt does not have a stable CLI interface. The apt tool prints out - # "WARNING: apt does not have a stable CLI interface. Use with caution in scripts." - name: Install tools (Linux) - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' + if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install cccc @@ -98,24 +65,25 @@ jobs: sudo apt-get install clang-format-14 sudo apt-get install clang-tidy-14 - # Have to install newer version from non-apt source due to SSL library compatibility issues. - - name: Install node - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' + - name: Install node tools + if: runner.os == 'Linux' run: | npm install -g markdownlint-cli@0.21.0 npm install -g npm-groovy-lint - name: Test with mypy run: | - mypy --ignore-missing-imports --strict statick statick_tool/ + mypy --ignore-missing-imports --strict src/statick_tool/ - - name: Statick markdown - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' - run: | - statick . --check --profile documentation.yaml + # Re-enable this step when statick-md switches from yapsy to entry points plugin approach. + # - name: Statick markdown + # if: runner.os == 'Linux' + # run: | + # pip install statick-md + # statick . --check --profile documentation.yaml - name: Sphinx lint - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu.22.04' + if: runner.os == 'Linux' uses: ammaraskar/sphinx-action@master with: docs-folder: 'docs/' @@ -125,12 +93,13 @@ jobs: python -m tox - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} - name: Self check - if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' + if: runner.os == 'Linux' run: | mkdir statick-output - ./statick . --output-directory statick-output --check --profile self_check.yaml --log INFO + statick . --output-directory statick-output --check --profile self_check.yaml --log INFO diff --git a/.gitignore b/.gitignore index a456aca3..3c66f5ac 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ build/ dist/ *.egg-info/ MANIFEST +requirements.txt docs/_build diff --git a/CHANGELOG.md b/CHANGELOG.md index 727d5875..3ad1ba98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Unreleased + +### Added + +- Use of `pyproject.toml` instead of `setup.py` and `requirements.txt`. +- Added support for Python 3.12 and 3.13. +- Switched from yapsy to setuptools for plugin mechanism. (#508) + +### Fixed + +- Run `isort` on unit test files. +- Handle updated warning type from `cppcheck` introduced in version 2.8. + ## v0.10.0 - 2025-01-03 ### Added diff --git a/README.md b/README.md index 5c4f5e5b..a78a7472 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,6 @@ Each _tool_ plugin provides the types of files it can analyze, then the output o determine the specific files that should be analyzed by each tool. The _tool_ plugin can also specify any other tools that are required to run before the current tool can act. -For example, `cppcheck` depends on the output of the `make` tool. The _tool_ plugin then scans each package by invoking the binary associated with the tool. The output of the scan is parsed to generate the list of issues discovered by Statick. @@ -418,10 +417,14 @@ $ statick . --output-directory /tmp/x --timings ## Advanced Installation -To install Statick from source on your system and make it part of your `$PATH`: +To install from source best practices is to use a virtual environment. +These instructions are for Linux, activating a virtual environment on Mac/Windows is similar. +To install Statick from source on your system: ```shell -sudo python3 setup.py install +python3 -m venv venv +. venv/bin/activate +pip install . ``` ## Existing Plugins @@ -648,34 +651,43 @@ The resource file (in your _user path_) must be named `_clang-format`. If you have the need to support any type of _discovery_, _tool_, or _reporting_ plugin that does not come built-in with Statick then you can write a custom plugin. +Declare the plugin module as a [module entry point] in `pyproject.toml` and provide the path according to plugin type +(_discovery_, _tool_, _reporting_). -Plugins consist of both a Python file and a `yapsy` file. -For a description of how yapsy works, check out the [yapsy documentation](http://yapsy.sourceforge.net/). - -A _user path_ with some custom plugins may look like +A _user path_ with custom plugins and configuration files may look like ```shell -my_custom_config - setup.py - |- plugins - |- my_discovery_plugin - |- my_discovery_plugin.py - |- my_discovery_plugin.yapsy - |- my_tool_plugins - |- my_tool_plugin.py - |- my_tool_plugin.yapsy - |- my_other_tool_plugin.py - |- my_other_tool_plugin.yapsy - |- rsc - |- config.yaml - |- exceptions.yaml +my-custom-project + pyproject.toml + |- src + |- statick_tool + |- plugins + |- discovery + |- my_discovery_plugin.py + |- tool + |- my_tool_plugin.py + |- my_other_tool_plugin.py + |- rsc + |- config.yaml + |- exceptions.yaml +``` + +In `pyproject.toml` declare the plugins as entry points. + +```toml +[project.entry-points."statick_tool.plugins.discovery"] +my_discovery_name = "statick_tool.plugins.discovery.my_discovery_plugin:MyDiscoveryPlugin" + +[project.entry-points."statick_tool.plugins.tool"] +my_tool_name = "statick_tool.plugins.tool.my_tool_plugin:MyToolPlugin" +my_other_tool_name = "statick_tool.plugins.tool.my_other_tool_plugin:MyOtherToolPlugin" ``` For the actual implementation of a plugin, it is recommended to copy a suitable default plugin provided by Statick and modify as needed. -For the contents of `setup.py`, it is recommended to copy a working external plugin. -Some examples are [statick-fortify](https://github.com/soartech/statick-fortify) and [statick-tex](https://github.com/tdenewiler/statick-tex). +For the contents of `pyproject.toml`, it is recommended to copy a working external plugin. +Some examples are [statick-md] and [statick-tex]. Those plugins are set up in such a way that they work with Statick when released on PyPI. ## Examples @@ -834,14 +846,14 @@ If you have a unit test file at `tests/my_module/test_my_module.py` you can easi and save yourself a lot of time during development. ```shell -python3 -m pytest --cov=statick_tool/ tests/my_module/test_my_module.py +python3 -m pytest --cov=src/statick_tool/ tests/my_module/test_my_module.py ``` To run all the tests and get a report with branch coverage specify the `tests` directory. Any subdirectory will run all the tests in that subdirectory. ```shell -python3 -m pytest --cov=statick_tool/ --cov-report term-missing --cov-report html --cov-branch tests/ +python3 -m pytest --cov=src/statick_tool/ --cov-report term-missing --cov-report html --cov-branch tests/ ``` ### Mypy @@ -893,6 +905,7 @@ His commits were scrubbed from git history upon the initial public release. [lizard]: https://github.com/terryyin/lizard [logging]: https://docs.python.org/3/howto/logging.html [make]: https://gcc.gnu.org/onlinedocs/libstdc++/index.html +[module entry point]: https://setuptools.pypa.io/en/latest/userguide/entry_point.html#entry-points-syntax [mypy]: https://github.com/python/mypy [npm-groovy-lint]: https://nvuillam.github.io/npm-groovy-lint/ [perlcritic]: http://perlcritic.com/ @@ -902,10 +915,12 @@ His commits were scrubbed from git history upon the initial public release. [pydocstyle]: http://www.pydocstyle.org/en/stable/ [pyflakes]: https://github.com/PyCQA/pyflakes [pylint]: https://pylint.org/ -[ruff]: https://github.com/charliermarsh/ruff [ros]: https://www.ros.org/ +[ruff]: https://github.com/charliermarsh/ruff [shellcheck]: https://github.com/koalaman/shellcheck [spotbugs]: https://github.com/spotbugs/spotbugs +[statick-md]: https://github.com/sscpac/statick-md +[statick-tex]: https://github.com/tdenewiler/statick-tex [uncrustify]: https://github.com/uncrustify/uncrustify [xmllint]: http://xmlsoft.org/ [yamllint]: https://yamllint.readthedocs.io/en/stable/ diff --git a/docker/requirements.txt b/docker/requirements.txt index 42fb4413..a7a5acdb 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -26,4 +26,3 @@ statick-web tabulate xmltodict yamllint -yapsy diff --git a/docs/source/conf.py b/docs/source/conf.py index d17ae023..98ef4e1a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -65,7 +65,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/docs/source/statick_tool.plugins.discovery.rst b/docs/source/statick_tool.plugins.discovery.rst index 5e5e6eb6..7971c47e 100644 --- a/docs/source/statick_tool.plugins.discovery.rst +++ b/docs/source/statick_tool.plugins.discovery.rst @@ -12,99 +12,99 @@ Module contents Submodules ---------- -statick_tool.plugins.discovery.c_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.c module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.c_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.c :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.cmake_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.cmake module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.cmake_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.cmake :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.groovy_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.groovy module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.groovy_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.groovy :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.java_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.java module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.java_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.java :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.maven_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.maven module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.maven_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.maven :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.perl_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.perl module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.perl_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.perl :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.python_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.python module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.python_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.python :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.ros_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.ros module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.ros_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.ros :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.shell_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.shell module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.shell_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.shell :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.xml_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.xml module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.xml_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.xml :members: :undoc-members: :show-inheritance: -statick_tool.plugins.discovery.yaml_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.discovery.yaml module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.discovery.yaml_discovery_plugin +.. automodule:: statick_tool.plugins.discovery.yaml :members: :undoc-members: :show-inheritance: diff --git a/docs/source/statick_tool.plugins.reporting.rst b/docs/source/statick_tool.plugins.reporting.rst index 545658ad..7dc6891a 100644 --- a/docs/source/statick_tool.plugins.reporting.rst +++ b/docs/source/statick_tool.plugins.reporting.rst @@ -12,42 +12,42 @@ Module contents Submodules ---------- -statick_tool.plugins.reporting.code_climate_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.reporting.code_climate module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.reporting.code_climate_reporting_plugin +.. automodule:: statick_tool.plugins.reporting.code_climate :members: :undoc-members: :show-inheritance: -statick_tool.plugins.reporting.do_nothing_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.reporting.do_nothing module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.reporting.do_nothing_reporting_plugin +.. automodule:: statick_tool.plugins.reporting.do_nothing :members: :undoc-members: :show-inheritance: -statick_tool.plugins.reporting.json_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.reporting.json module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.reporting.json_reporting_plugin +.. automodule:: statick_tool.plugins.reporting.json :members: :undoc-members: :show-inheritance: -statick_tool.plugins.reporting.print_to_console_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.reporting.print_to_console module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.reporting.print_to_console_reporting_plugin +.. automodule:: statick_tool.plugins.reporting.print_to_console :members: :undoc-members: :show-inheritance: -statick_tool.plugins.reporting.write_jenkins_warnings_ng_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.reporting.write_jenkins_warnings_ng module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.reporting.write_jenkins_warnings_ng_reporting_plugin +.. automodule:: statick_tool.plugins.reporting.write_jenkins_warnings_ng :members: :undoc-members: :show-inheritance: diff --git a/docs/source/statick_tool.plugins.tool.rst b/docs/source/statick_tool.plugins.tool.rst index 64e3842b..10fa7cfb 100644 --- a/docs/source/statick_tool.plugins.tool.rst +++ b/docs/source/statick_tool.plugins.tool.rst @@ -12,234 +12,234 @@ Module contents Submodules ---------- -statick_tool.plugins.tool.bandit_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.bandit module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.bandit_tool_plugin +.. automodule:: statick_tool.plugins.tool.bandit :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.black_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.black module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.black_tool_plugin +.. automodule:: statick_tool.plugins.tool.black :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.catkin_lint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.catkin_lint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.catkin_lint_tool_plugin +.. automodule:: statick_tool.plugins.tool.catkin_lint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.cccc_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.cccc module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.cccc_tool_plugin +.. automodule:: statick_tool.plugins.tool.cccc :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.clang_format_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.clang_format module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.clang_format_tool_plugin +.. automodule:: statick_tool.plugins.tool.clang_format :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.clang_tidy_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.clang_tidy module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.clang_tidy_tool_plugin +.. automodule:: statick_tool.plugins.tool.clang_tidy :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.cmakelint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.cmakelint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.cmakelint_tool_plugin +.. automodule:: statick_tool.plugins.tool.cmakelint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.cppcheck_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.cppcheck module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.cppcheck_tool_plugin +.. automodule:: statick_tool.plugins.tool.cppcheck :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.cpplint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.cpplint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.cpplint_tool_plugin +.. automodule:: statick_tool.plugins.tool.cpplint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.docformatter_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.docformatter module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.docformatter_tool_plugin +.. automodule:: statick_tool.plugins.tool.docformatter :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.do_nothing_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.do_nothing module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.do_nothing_tool_plugin +.. automodule:: statick_tool.plugins.tool.do_nothing :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.flawfinder_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.flawfinder module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.flawfinder_tool_plugin +.. automodule:: statick_tool.plugins.tool.flawfinder :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.groovylint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.groovylint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.groovylint_tool_plugin +.. automodule:: statick_tool.plugins.tool.groovylint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.isort_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.isort module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.isort_tool_plugin +.. automodule:: statick_tool.plugins.tool.isort :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.lizard_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.lizard module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.lizard_tool_plugin +.. automodule:: statick_tool.plugins.tool.lizard :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.make_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.make module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.make_tool_plugin +.. automodule:: statick_tool.plugins.tool.make :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.mypy_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.mypy module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.mypy_tool_plugin +.. automodule:: statick_tool.plugins.tool.mypy :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.perlcritic_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.perlcritic module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.perlcritic_tool_plugin +.. automodule:: statick_tool.plugins.tool.perlcritic :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.pycodestyle_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.pycodestyle module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.pycodestyle_tool_plugin +.. automodule:: statick_tool.plugins.tool.pycodestyle :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.pydocstyle_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.pydocstyle module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.pydocstyle_tool_plugin +.. automodule:: statick_tool.plugins.tool.pydocstyle :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.pyflakes_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.pyflakes module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.pyflakes_tool_plugin +.. automodule:: statick_tool.plugins.tool.pyflakes :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.pylint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.pylint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.pylint_tool_plugin +.. automodule:: statick_tool.plugins.tool.pylint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.ruff_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.ruff module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.ruff_tool_plugin +.. automodule:: statick_tool.plugins.tool.ruff :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.shellcheck_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.shellcheck module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.shellcheck_tool_plugin +.. automodule:: statick_tool.plugins.tool.shellcheck :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.shellcheck_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.shellcheck module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.shellcheck_tool_plugin +.. automodule:: statick_tool.plugins.tool.shellcheck :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.spotbugs_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.spotbugs module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.spotbugs_tool_plugin +.. automodule:: statick_tool.plugins.tool.spotbugs :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.uncrustify_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.uncrustify module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.uncrustify_tool_plugin +.. automodule:: statick_tool.plugins.tool.uncrustify :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.xmllint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.xmllint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.xmllint_tool_plugin +.. automodule:: statick_tool.plugins.tool.xmllint :members: :undoc-members: :show-inheritance: -statick_tool.plugins.tool.yamllint_tool_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +statick_tool.plugins.tool.yamllint module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: statick_tool.plugins.tool.yamllint_tool_plugin +.. automodule:: statick_tool.plugins.tool.yamllint :members: :undoc-members: :show-inheritance: diff --git a/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.py b/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.py index 6b044480..dd55e366 100644 --- a/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.py +++ b/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.py @@ -6,8 +6,8 @@ import subprocess from statick_tool.issue import Issue # pylint: disable=import-error -from statick_tool.tool_plugin import ( - ToolPlugin, # pylint: disable=import-error,no-name-in-module,syntax-error +from statick_tool.tool_plugin import ( # pylint: disable=import-error,no-name-in-module,syntax-error + ToolPlugin, ) diff --git a/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.yapsy-plugin b/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.yapsy-plugin deleted file mode 100644 index 888099ed..00000000 --- a/examples/navigation/navigation_config/plugins/my_custom_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = My Custom Tool Plugin -Module = my_custom_tool_plugin diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1fffd69e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,135 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "statick" +authors = [{name = "NIWC Pacific"}] +description="Making code quality easier." +version = "0.10.0" +readme = "README.md" +requires-python = ">=3.9" +license = {text = "CC0-1.0"} +classifiers = [ + "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Software Development :: Testing", +] +dependencies = [ + "PyYAML", + "bandit", + "black", + "cmakelint", + "cpplint", + "docformatter", + "flawfinder", + "importlib_metadata", + "isort", + "lizard", + "mypy", + "packaging", + "pycodestyle", + "pydocstyle", + "pyflakes", + "pylint", + "ruff>=0.0.237", + "tabulate", + "types-PyYAML", + "types-setuptools", + "types-tabulate", + "xmltodict", + "yamllint", +] + +[project.scripts] +statick = "statick_tool.statick:main" + +[tool.setuptools.package-data] +statick_tool = [ + "rsc/*", + "rsc/.*", + "rsc/plugin_mapping/*", +] + +[tool.pytest.ini_options] +pythonpath = [ + "src", +] + +[project.entry-points."statick_tool.plugins.discovery"] +c = "statick_tool.plugins.discovery.c:CDiscoveryPlugin" +cmake = "statick_tool.plugins.discovery.cmake:CMakeDiscoveryPlugin" +groovy = "statick_tool.plugins.discovery.groovy:GroovyDiscoveryPlugin" +java = "statick_tool.plugins.discovery.java:JavaDiscoveryPlugin" +maven = "statick_tool.plugins.discovery.maven:MavenDiscoveryPlugin" +perl = "statick_tool.plugins.discovery.perl:PerlDiscoveryPlugin" +python = "statick_tool.plugins.discovery.python:PythonDiscoveryPlugin" +ros = "statick_tool.plugins.discovery.ros:RosDiscoveryPlugin" +shell = "statick_tool.plugins.discovery.shell:ShellDiscoveryPlugin" +xml = "statick_tool.plugins.discovery.xml:XMLDiscoveryPlugin" +yaml = "statick_tool.plugins.discovery.yaml:YAMLDiscoveryPlugin" + +[project.entry-points."statick_tool.plugins.reporting"] +code_climate = "statick_tool.plugins.reporting.code_climate:CodeClimateReportingPlugin" +do_nothing = "statick_tool.plugins.reporting.do_nothing:DoNothingReportingPlugin" +json = "statick_tool.plugins.reporting.json:JsonReportingPlugin" +print_to_console = "statick_tool.plugins.reporting.print_to_console:PrintToConsoleReportingPlugin" +write_jenkins_warnings_ng = "statick_tool.plugins.reporting.write_jenkins_warnings_ng:WriteJenkinsWarningsNGReportingPlugin" + +[project.entry-points."statick_tool.plugins.tool"] +bandit = "statick_tool.plugins.tool.bandit:BanditToolPlugin" +black = "statick_tool.plugins.tool.black:BlackToolPlugin" +catkin_lint = "statick_tool.plugins.tool.catkin_lint:CatkinLintToolPlugin" +cccc = "statick_tool.plugins.tool.cccc:CCCCToolPlugin" +clang-format = "statick_tool.plugins.tool.clang_format:ClangFormatToolPlugin" +clang-tidy = "statick_tool.plugins.tool.clang_tidy:ClangTidyToolPlugin" +cmakelint = "statick_tool.plugins.tool.cmakelint:CMakelintToolPlugin" +cppcheck = "statick_tool.plugins.tool.cppcheck:CppcheckToolPlugin" +cpplint = "statick_tool.plugins.tool.cpplint:CpplintToolPlugin" +docformatter = "statick_tool.plugins.tool.docformatter:DocformatterToolPlugin" +do_nothing = "statick_tool.plugins.tool.do_nothing:DoNothingToolPlugin" +flawfinder = "statick_tool.plugins.tool.flawfinder:FlawfinderToolPlugin" +groovylint = "statick_tool.plugins.tool.groovylint:GroovyLintToolPlugin" +isort = "statick_tool.plugins.tool.isort:IsortToolPlugin" +lizard = "statick_tool.plugins.tool.lizard:LizardToolPlugin" +make = "statick_tool.plugins.tool.make:MakeToolPlugin" +mypy = "statick_tool.plugins.tool.mypy:MypyToolPlugin" +perlcritic = "statick_tool.plugins.tool.perlcritic:PerlCriticToolPlugin" +pycodestyle = "statick_tool.plugins.tool.pycodestyle:PycodestyleToolPlugin" +pydocstyle = "statick_tool.plugins.tool.pydocstyle:PydocstyleToolPlugin" +pyflakes = "statick_tool.plugins.tool.pyflakes:PyflakesToolPlugin" +pylint = "statick_tool.plugins.tool.pylint:PylintToolPlugin" +ruff = "statick_tool.plugins.tool.ruff:RuffToolPlugin" +shellcheck = "statick_tool.plugins.tool.shellcheck:ShellcheckToolPlugin" +spotbugs = "statick_tool.plugins.tool.spotbugs:SpotbugsToolPlugin" +uncrustify = "statick_tool.plugins.tool.uncrustify:UncrustifyToolPlugin" +xmllint = "statick_tool.plugins.tool.xmllint:XmllintToolPlugin" +yamllint = "statick_tool.plugins.tool.yamllint:YamllintToolPlugin" + +[project.urls] +"Homepage" = "https://github.com/sscpac/statick" +"Bug Tracker" = "https://github.com/sscpac/statick/issues" + +[project.optional-dependencies] +test = [ + "coverage", + "lark", + "mock", + "pylint-django", + "pytest", + "pytest-cov", + "tox", + "tox-gh-actions", +] +docs = [ + "sphinx==1.7.9", + "yaml-1.3", +] + +[tool.isort] +profile = "black" diff --git a/requirements-docs.txt b/requirements-docs.txt deleted file mode 100644 index 94521be5..00000000 --- a/requirements-docs.txt +++ /dev/null @@ -1,4 +0,0 @@ -sphinx==1.7.9 -travis-sphinx==2.2.1 -yaml-1.3 -yapsy diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 27f8adaf..00000000 --- a/requirements.txt +++ /dev/null @@ -1,25 +0,0 @@ -PyYAML -bandit -black -cmakelint -cpplint -deprecated -# Pin due to formatting conflict with black. -# https://github.com/PyCQA/docformatter/issues/94 -docformatter==1.5.1 -flawfinder -isort -lizard -mypy -pycodestyle -pydocstyle -pyflakes -pylint -pylint-django<2.0 -ruff>=0.0.237 -statick -statick-md -tabulate -xmltodict -yamllint -yapsy diff --git a/setup.py b/setup.py deleted file mode 100644 index 618a4ba1..00000000 --- a/setup.py +++ /dev/null @@ -1,76 +0,0 @@ -"""Setup.""" - -from setuptools import setup # NOLINT - -import statick_tool - -with open("README.md", encoding="utf8") as f: - LONG_DESCRIPTION = f.read() - -TEST_DEPS = [ - "backports.tempfile", - "lark", - "pylint-django", - "pytest", - "mock", - "tox", -] - -EXTRAS = { - "test": TEST_DEPS, -} - -setup( - name="statick", - description="Making code quality easier.", - author="SSC Pacific", - version=statick_tool.__version__, - packages=["statick_tool"], - package_data={ - "statick_tool": [ - "rsc/.*", - "rsc/*", - "rsc/plugin_mapping/*", - "plugins/*.py", - "plugins/discovery/*", - "plugins/tool/*", - "plugins/reporting/*", - ] - }, - scripts=["statick"], - long_description=LONG_DESCRIPTION, - long_description_content_type="text/markdown", - install_requires=[ - "bandit", - "black", - "cmakelint", - "cpplint", - "deprecated", - "docformatter", - "flawfinder", - "isort", - "lizard", - "mypy", - "pycodestyle", - "pydocstyle", - "pyflakes", - "pylint", - "PyYAML", - "ruff>=0.0.237", - "tabulate", - "xmltodict", - "yamllint", - "yapsy", - ], - tests_require=TEST_DEPS, - extras_require=EXTRAS, - url="https://github.com/sscpac/statick", - classifiers=[ - "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Topic :: Software Development :: Testing", - ], -) diff --git a/statick_tool/__init__.py b/src/statick_tool/__init__.py similarity index 58% rename from statick_tool/__init__.py rename to src/statick_tool/__init__.py index d2be0fa3..c91ed51e 100644 --- a/statick_tool/__init__.py +++ b/src/statick_tool/__init__.py @@ -1,3 +1 @@ """Making code quality easier.""" - -__version__ = "0.10.0" diff --git a/statick_tool/args.py b/src/statick_tool/args.py similarity index 100% rename from statick_tool/args.py rename to src/statick_tool/args.py diff --git a/statick_tool/config.py b/src/statick_tool/config.py similarity index 100% rename from statick_tool/config.py rename to src/statick_tool/config.py diff --git a/statick_tool/discovery_plugin.py b/src/statick_tool/discovery_plugin.py similarity index 97% rename from statick_tool/discovery_plugin.py rename to src/statick_tool/discovery_plugin.py index e7c322a0..81ed4422 100644 --- a/statick_tool/discovery_plugin.py +++ b/src/statick_tool/discovery_plugin.py @@ -6,14 +6,12 @@ import sys from typing import Any, List, Optional, Union -from yapsy.IPlugin import IPlugin - from statick_tool.exceptions import Exceptions from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -class DiscoveryPlugin(IPlugin): # type: ignore +class DiscoveryPlugin: """Default implementation of discovery plugin.""" plugin_context = None diff --git a/statick_tool/exceptions.py b/src/statick_tool/exceptions.py similarity index 100% rename from statick_tool/exceptions.py rename to src/statick_tool/exceptions.py diff --git a/statick_tool/issue.py b/src/statick_tool/issue.py similarity index 100% rename from statick_tool/issue.py rename to src/statick_tool/issue.py diff --git a/statick_tool/package.py b/src/statick_tool/package.py similarity index 100% rename from statick_tool/package.py rename to src/statick_tool/package.py diff --git a/statick_tool/plugin_context.py b/src/statick_tool/plugin_context.py similarity index 100% rename from statick_tool/plugin_context.py rename to src/statick_tool/plugin_context.py diff --git a/statick_tool/plugins/__init__.py b/src/statick_tool/plugins/__init__.py similarity index 100% rename from statick_tool/plugins/__init__.py rename to src/statick_tool/plugins/__init__.py diff --git a/statick_tool/plugins/discovery/__init__.py b/src/statick_tool/plugins/discovery/__init__.py similarity index 100% rename from statick_tool/plugins/discovery/__init__.py rename to src/statick_tool/plugins/discovery/__init__.py diff --git a/statick_tool/plugins/discovery/c_discovery_plugin.py b/src/statick_tool/plugins/discovery/c.py similarity index 100% rename from statick_tool/plugins/discovery/c_discovery_plugin.py rename to src/statick_tool/plugins/discovery/c.py diff --git a/statick_tool/plugins/discovery/cmake_discovery_plugin.py b/src/statick_tool/plugins/discovery/cmake.py similarity index 100% rename from statick_tool/plugins/discovery/cmake_discovery_plugin.py rename to src/statick_tool/plugins/discovery/cmake.py diff --git a/statick_tool/plugins/discovery/groovy_discovery_plugin.py b/src/statick_tool/plugins/discovery/groovy.py similarity index 100% rename from statick_tool/plugins/discovery/groovy_discovery_plugin.py rename to src/statick_tool/plugins/discovery/groovy.py diff --git a/statick_tool/plugins/discovery/java_discovery_plugin.py b/src/statick_tool/plugins/discovery/java.py similarity index 100% rename from statick_tool/plugins/discovery/java_discovery_plugin.py rename to src/statick_tool/plugins/discovery/java.py diff --git a/statick_tool/plugins/discovery/maven_discovery_plugin.py b/src/statick_tool/plugins/discovery/maven.py similarity index 100% rename from statick_tool/plugins/discovery/maven_discovery_plugin.py rename to src/statick_tool/plugins/discovery/maven.py diff --git a/statick_tool/plugins/discovery/perl_discovery_plugin.py b/src/statick_tool/plugins/discovery/perl.py similarity index 100% rename from statick_tool/plugins/discovery/perl_discovery_plugin.py rename to src/statick_tool/plugins/discovery/perl.py diff --git a/statick_tool/plugins/discovery/python_discovery_plugin.py b/src/statick_tool/plugins/discovery/python.py similarity index 100% rename from statick_tool/plugins/discovery/python_discovery_plugin.py rename to src/statick_tool/plugins/discovery/python.py diff --git a/statick_tool/plugins/discovery/ros_discovery_plugin.py b/src/statick_tool/plugins/discovery/ros.py similarity index 100% rename from statick_tool/plugins/discovery/ros_discovery_plugin.py rename to src/statick_tool/plugins/discovery/ros.py diff --git a/statick_tool/plugins/discovery/shell_discovery_plugin.py b/src/statick_tool/plugins/discovery/shell.py similarity index 100% rename from statick_tool/plugins/discovery/shell_discovery_plugin.py rename to src/statick_tool/plugins/discovery/shell.py diff --git a/statick_tool/plugins/discovery/xml_discovery_plugin.py b/src/statick_tool/plugins/discovery/xml.py similarity index 100% rename from statick_tool/plugins/discovery/xml_discovery_plugin.py rename to src/statick_tool/plugins/discovery/xml.py diff --git a/statick_tool/plugins/discovery/yaml_discovery_plugin.py b/src/statick_tool/plugins/discovery/yaml.py similarity index 100% rename from statick_tool/plugins/discovery/yaml_discovery_plugin.py rename to src/statick_tool/plugins/discovery/yaml.py diff --git a/statick_tool/plugins/reporting/__init__.py b/src/statick_tool/plugins/reporting/__init__.py similarity index 100% rename from statick_tool/plugins/reporting/__init__.py rename to src/statick_tool/plugins/reporting/__init__.py diff --git a/statick_tool/plugins/reporting/code_climate_reporting_plugin.py b/src/statick_tool/plugins/reporting/code_climate.py similarity index 100% rename from statick_tool/plugins/reporting/code_climate_reporting_plugin.py rename to src/statick_tool/plugins/reporting/code_climate.py diff --git a/statick_tool/plugins/reporting/do_nothing_reporting_plugin.py b/src/statick_tool/plugins/reporting/do_nothing.py similarity index 100% rename from statick_tool/plugins/reporting/do_nothing_reporting_plugin.py rename to src/statick_tool/plugins/reporting/do_nothing.py diff --git a/statick_tool/plugins/reporting/json_reporting_plugin.py b/src/statick_tool/plugins/reporting/json.py similarity index 100% rename from statick_tool/plugins/reporting/json_reporting_plugin.py rename to src/statick_tool/plugins/reporting/json.py diff --git a/statick_tool/plugins/reporting/print_to_console_reporting_plugin.py b/src/statick_tool/plugins/reporting/print_to_console.py similarity index 100% rename from statick_tool/plugins/reporting/print_to_console_reporting_plugin.py rename to src/statick_tool/plugins/reporting/print_to_console.py diff --git a/statick_tool/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin.py b/src/statick_tool/plugins/reporting/write_jenkins_warnings_ng.py similarity index 100% rename from statick_tool/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin.py rename to src/statick_tool/plugins/reporting/write_jenkins_warnings_ng.py diff --git a/statick_tool/plugins/tool/__init__.py b/src/statick_tool/plugins/tool/__init__.py similarity index 100% rename from statick_tool/plugins/tool/__init__.py rename to src/statick_tool/plugins/tool/__init__.py diff --git a/statick_tool/plugins/tool/bandit_tool_plugin.py b/src/statick_tool/plugins/tool/bandit.py similarity index 100% rename from statick_tool/plugins/tool/bandit_tool_plugin.py rename to src/statick_tool/plugins/tool/bandit.py diff --git a/statick_tool/plugins/tool/black_tool_plugin.py b/src/statick_tool/plugins/tool/black.py similarity index 100% rename from statick_tool/plugins/tool/black_tool_plugin.py rename to src/statick_tool/plugins/tool/black.py diff --git a/statick_tool/plugins/tool/catkin_lint_tool_plugin.py b/src/statick_tool/plugins/tool/catkin_lint.py similarity index 100% rename from statick_tool/plugins/tool/catkin_lint_tool_plugin.py rename to src/statick_tool/plugins/tool/catkin_lint.py diff --git a/statick_tool/plugins/tool/cccc_tool_plugin.py b/src/statick_tool/plugins/tool/cccc.py similarity index 100% rename from statick_tool/plugins/tool/cccc_tool_plugin.py rename to src/statick_tool/plugins/tool/cccc.py diff --git a/statick_tool/plugins/tool/clang_format_tool_plugin.py b/src/statick_tool/plugins/tool/clang_format.py similarity index 96% rename from statick_tool/plugins/tool/clang_format_tool_plugin.py rename to src/statick_tool/plugins/tool/clang_format.py index 3717b43e..891dde87 100644 --- a/statick_tool/plugins/tool/clang_format_tool_plugin.py +++ b/src/statick_tool/plugins/tool/clang_format.py @@ -157,11 +157,14 @@ def check_configuration(self, clang_format_bin: str) -> Optional[bool]: if not os.path.isfile(os.path.expanduser("~/" + default_file_name)): default_file_name = ".clang-format" - with open( - os.path.expanduser("~/" + default_file_name), "r", encoding="utf8" - ) as home_format_file, open( - format_file_name, "r", encoding="utf8" # type: ignore - ) as format_file: + with ( + open( + os.path.expanduser("~/" + default_file_name), "r", encoding="utf8" + ) as home_format_file, + open( + format_file_name, "r", encoding="utf8" # type: ignore + ) as format_file, + ): actual_format = home_format_file.read() target_format = format_file.read() diff = difflib.context_diff( diff --git a/statick_tool/plugins/tool/clang_format_parser.py b/src/statick_tool/plugins/tool/clang_format_parser.py similarity index 100% rename from statick_tool/plugins/tool/clang_format_parser.py rename to src/statick_tool/plugins/tool/clang_format_parser.py diff --git a/statick_tool/plugins/tool/clang_tidy_tool_plugin.py b/src/statick_tool/plugins/tool/clang_tidy.py similarity index 100% rename from statick_tool/plugins/tool/clang_tidy_tool_plugin.py rename to src/statick_tool/plugins/tool/clang_tidy.py diff --git a/statick_tool/plugins/tool/cmakelint_tool_plugin.py b/src/statick_tool/plugins/tool/cmakelint.py similarity index 100% rename from statick_tool/plugins/tool/cmakelint_tool_plugin.py rename to src/statick_tool/plugins/tool/cmakelint.py diff --git a/statick_tool/plugins/tool/cppcheck_tool_plugin.py b/src/statick_tool/plugins/tool/cppcheck.py similarity index 82% rename from statick_tool/plugins/tool/cppcheck_tool_plugin.py rename to src/statick_tool/plugins/tool/cppcheck.py index ee237f5e..df4eee14 100644 --- a/statick_tool/plugins/tool/cppcheck_tool_plugin.py +++ b/src/statick_tool/plugins/tool/cppcheck.py @@ -7,6 +7,8 @@ import subprocess from typing import List, Match, Optional, Pattern +from packaging.version import Version + from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.tool_plugin import ToolPlugin @@ -32,6 +34,26 @@ def gather_args(self, args: argparse.Namespace) -> None: "--cppcheck-bin", dest="cppcheck_bin", type=str, help="cppcheck binary path" ) + @classmethod + def get_version(cls, cppcheck_bin: str) -> str: + """Get version of tool. + + If no version is found the function returns "0.0". + """ + version = "0.0" + output = subprocess.check_output( + [cppcheck_bin, "--version"], + stderr=subprocess.STDOUT, + universal_newlines=True, + ) + ver_re = r"(.+) ([0-9]*\.?[0-9]+)" + parse: Pattern[str] = re.compile(ver_re) + match: Optional[Match[str]] = parse.match(output) + if match: + version = match.group(2) + + return version + # pylint: disable=too-many-locals, too-many-branches, too-many-return-statements def scan(self, package: Package, level: str) -> Optional[List[Issue]]: """Run tool and gather output.""" @@ -57,26 +79,17 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]: cppcheck_bin = self.plugin_context.args.cppcheck_bin try: - output = subprocess.check_output( - [cppcheck_bin, "--version"], - stderr=subprocess.STDOUT, - universal_newlines=True, - ) - ver_re = r"(.+) ([0-9]*\.?[0-9]+)" - parse: Pattern[str] = re.compile(ver_re) - match: Optional[Match[str]] = parse.match(output) - if match: - ver = float(match.group(2)) - # If specific version is not specified just use the installed version. - if user_version is not None and ver != float(user_version): - logging.warning( - "You need version %s of cppcheck, but you have %s. " - "See README.md for instuctions on how to install the " - "proper version", - user_version, - match.group(2), - ) - return None + version = self.get_version(cppcheck_bin) + # If specific version is not specified just use the installed version. + if user_version is not None and Version(version) != Version(user_version): + logging.warning( + "You need version %s of cppcheck, but you have %s. " + "See README.md for instructions on how to install the " + "proper version", + user_version, + version, + ) + return None except OSError as ex: logging.warning("Cppcheck not found! (%s)", ex) diff --git a/statick_tool/plugins/tool/cpplint_tool_plugin.py b/src/statick_tool/plugins/tool/cpplint.py similarity index 100% rename from statick_tool/plugins/tool/cpplint_tool_plugin.py rename to src/statick_tool/plugins/tool/cpplint.py diff --git a/statick_tool/plugins/tool/do_nothing_tool_plugin.py b/src/statick_tool/plugins/tool/do_nothing.py similarity index 100% rename from statick_tool/plugins/tool/do_nothing_tool_plugin.py rename to src/statick_tool/plugins/tool/do_nothing.py diff --git a/statick_tool/plugins/tool/docformatter_tool_plugin.py b/src/statick_tool/plugins/tool/docformatter.py similarity index 100% rename from statick_tool/plugins/tool/docformatter_tool_plugin.py rename to src/statick_tool/plugins/tool/docformatter.py diff --git a/statick_tool/plugins/tool/flawfinder_tool_plugin.py b/src/statick_tool/plugins/tool/flawfinder.py similarity index 100% rename from statick_tool/plugins/tool/flawfinder_tool_plugin.py rename to src/statick_tool/plugins/tool/flawfinder.py diff --git a/statick_tool/plugins/tool/groovylint_tool_plugin.py b/src/statick_tool/plugins/tool/groovylint.py similarity index 100% rename from statick_tool/plugins/tool/groovylint_tool_plugin.py rename to src/statick_tool/plugins/tool/groovylint.py diff --git a/statick_tool/plugins/tool/isort_tool_plugin.py b/src/statick_tool/plugins/tool/isort.py similarity index 100% rename from statick_tool/plugins/tool/isort_tool_plugin.py rename to src/statick_tool/plugins/tool/isort.py diff --git a/statick_tool/plugins/tool/lizard_tool_plugin.py b/src/statick_tool/plugins/tool/lizard.py similarity index 100% rename from statick_tool/plugins/tool/lizard_tool_plugin.py rename to src/statick_tool/plugins/tool/lizard.py diff --git a/statick_tool/plugins/tool/make_tool_plugin.py b/src/statick_tool/plugins/tool/make.py similarity index 100% rename from statick_tool/plugins/tool/make_tool_plugin.py rename to src/statick_tool/plugins/tool/make.py diff --git a/statick_tool/plugins/tool/mypy_tool_plugin.py b/src/statick_tool/plugins/tool/mypy.py similarity index 100% rename from statick_tool/plugins/tool/mypy_tool_plugin.py rename to src/statick_tool/plugins/tool/mypy.py diff --git a/statick_tool/plugins/tool/perlcritic_tool_plugin.py b/src/statick_tool/plugins/tool/perlcritic.py similarity index 100% rename from statick_tool/plugins/tool/perlcritic_tool_plugin.py rename to src/statick_tool/plugins/tool/perlcritic.py diff --git a/statick_tool/plugins/tool/pycodestyle_tool_plugin.py b/src/statick_tool/plugins/tool/pycodestyle.py similarity index 100% rename from statick_tool/plugins/tool/pycodestyle_tool_plugin.py rename to src/statick_tool/plugins/tool/pycodestyle.py diff --git a/statick_tool/plugins/tool/pydocstyle_tool_plugin.py b/src/statick_tool/plugins/tool/pydocstyle.py similarity index 100% rename from statick_tool/plugins/tool/pydocstyle_tool_plugin.py rename to src/statick_tool/plugins/tool/pydocstyle.py diff --git a/statick_tool/plugins/tool/pyflakes_tool_plugin.py b/src/statick_tool/plugins/tool/pyflakes.py similarity index 100% rename from statick_tool/plugins/tool/pyflakes_tool_plugin.py rename to src/statick_tool/plugins/tool/pyflakes.py diff --git a/statick_tool/plugins/tool/pylint_tool_plugin.py b/src/statick_tool/plugins/tool/pylint.py similarity index 100% rename from statick_tool/plugins/tool/pylint_tool_plugin.py rename to src/statick_tool/plugins/tool/pylint.py diff --git a/statick_tool/plugins/tool/ruff_tool_plugin.py b/src/statick_tool/plugins/tool/ruff.py similarity index 99% rename from statick_tool/plugins/tool/ruff_tool_plugin.py rename to src/statick_tool/plugins/tool/ruff.py index 99c4edba..afa2d47d 100644 --- a/statick_tool/plugins/tool/ruff_tool_plugin.py +++ b/src/statick_tool/plugins/tool/ruff.py @@ -27,7 +27,6 @@ def process_files( """Run tool and gather output.""" flags: List[str] = ["check"] flags += user_flags - total_output: List[str] = [] try: diff --git a/statick_tool/plugins/tool/shellcheck_tool_plugin.py b/src/statick_tool/plugins/tool/shellcheck.py similarity index 100% rename from statick_tool/plugins/tool/shellcheck_tool_plugin.py rename to src/statick_tool/plugins/tool/shellcheck.py diff --git a/statick_tool/plugins/tool/spotbugs_tool_plugin.py b/src/statick_tool/plugins/tool/spotbugs.py similarity index 100% rename from statick_tool/plugins/tool/spotbugs_tool_plugin.py rename to src/statick_tool/plugins/tool/spotbugs.py diff --git a/statick_tool/plugins/tool/uncrustify_tool_plugin.py b/src/statick_tool/plugins/tool/uncrustify.py similarity index 100% rename from statick_tool/plugins/tool/uncrustify_tool_plugin.py rename to src/statick_tool/plugins/tool/uncrustify.py diff --git a/statick_tool/plugins/tool/xmllint_tool_plugin.py b/src/statick_tool/plugins/tool/xmllint.py similarity index 100% rename from statick_tool/plugins/tool/xmllint_tool_plugin.py rename to src/statick_tool/plugins/tool/xmllint.py diff --git a/statick_tool/plugins/tool/yamllint_tool_plugin.py b/src/statick_tool/plugins/tool/yamllint.py similarity index 100% rename from statick_tool/plugins/tool/yamllint_tool_plugin.py rename to src/statick_tool/plugins/tool/yamllint.py diff --git a/statick_tool/profile.py b/src/statick_tool/profile.py similarity index 100% rename from statick_tool/profile.py rename to src/statick_tool/profile.py diff --git a/statick_tool/reporting_plugin.py b/src/statick_tool/reporting_plugin.py similarity index 96% rename from statick_tool/reporting_plugin.py rename to src/statick_tool/reporting_plugin.py index 044721c4..7c1c7d86 100644 --- a/statick_tool/reporting_plugin.py +++ b/src/statick_tool/reporting_plugin.py @@ -4,14 +4,12 @@ import logging from typing import Any, Dict, List, Optional, Tuple, Union -from yapsy.IPlugin import IPlugin - from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -class ReportingPlugin(IPlugin): # type: ignore +class ReportingPlugin: """Default implementation of reporting plugin.""" plugin_context = None diff --git a/statick_tool/resources.py b/src/statick_tool/resources.py similarity index 100% rename from statick_tool/resources.py rename to src/statick_tool/resources.py diff --git a/statick_tool/rsc/.clang-format b/src/statick_tool/rsc/.clang-format similarity index 100% rename from statick_tool/rsc/.clang-format rename to src/statick_tool/rsc/.clang-format diff --git a/statick_tool/rsc/.groovylintrc.json b/src/statick_tool/rsc/.groovylintrc.json similarity index 100% rename from statick_tool/rsc/.groovylintrc.json rename to src/statick_tool/rsc/.groovylintrc.json diff --git a/statick_tool/rsc/CMakeLists.txt.in b/src/statick_tool/rsc/CMakeLists.txt.in similarity index 100% rename from statick_tool/rsc/CMakeLists.txt.in rename to src/statick_tool/rsc/CMakeLists.txt.in diff --git a/statick_tool/rsc/_clang-format b/src/statick_tool/rsc/_clang-format similarity index 100% rename from statick_tool/rsc/_clang-format rename to src/statick_tool/rsc/_clang-format diff --git a/statick_tool/rsc/cccc.opt b/src/statick_tool/rsc/cccc.opt similarity index 100% rename from statick_tool/rsc/cccc.opt rename to src/statick_tool/rsc/cccc.opt diff --git a/statick_tool/rsc/config.yaml b/src/statick_tool/rsc/config.yaml similarity index 100% rename from statick_tool/rsc/config.yaml rename to src/statick_tool/rsc/config.yaml diff --git a/statick_tool/rsc/discovery_only.yaml b/src/statick_tool/rsc/discovery_only.yaml similarity index 100% rename from statick_tool/rsc/discovery_only.yaml rename to src/statick_tool/rsc/discovery_only.yaml diff --git a/statick_tool/rsc/documentation.yaml b/src/statick_tool/rsc/documentation.yaml similarity index 100% rename from statick_tool/rsc/documentation.yaml rename to src/statick_tool/rsc/documentation.yaml diff --git a/statick_tool/rsc/exceptions.yaml b/src/statick_tool/rsc/exceptions.yaml similarity index 100% rename from statick_tool/rsc/exceptions.yaml rename to src/statick_tool/rsc/exceptions.yaml diff --git a/statick_tool/rsc/gauntlet_ignore.yaml b/src/statick_tool/rsc/gauntlet_ignore.yaml similarity index 100% rename from statick_tool/rsc/gauntlet_ignore.yaml rename to src/statick_tool/rsc/gauntlet_ignore.yaml diff --git a/statick_tool/rsc/plugin_mapping/clang-tidy.txt b/src/statick_tool/rsc/plugin_mapping/clang-tidy.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/clang-tidy.txt rename to src/statick_tool/rsc/plugin_mapping/clang-tidy.txt diff --git a/statick_tool/rsc/plugin_mapping/code_climate.txt b/src/statick_tool/rsc/plugin_mapping/code_climate.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/code_climate.txt rename to src/statick_tool/rsc/plugin_mapping/code_climate.txt diff --git a/statick_tool/rsc/plugin_mapping/cppcheck.txt b/src/statick_tool/rsc/plugin_mapping/cppcheck.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/cppcheck.txt rename to src/statick_tool/rsc/plugin_mapping/cppcheck.txt diff --git a/statick_tool/rsc/plugin_mapping/make.txt b/src/statick_tool/rsc/plugin_mapping/make.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/make.txt rename to src/statick_tool/rsc/plugin_mapping/make.txt diff --git a/statick_tool/rsc/plugin_mapping/perlcritic.txt b/src/statick_tool/rsc/plugin_mapping/perlcritic.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/perlcritic.txt rename to src/statick_tool/rsc/plugin_mapping/perlcritic.txt diff --git a/statick_tool/rsc/plugin_mapping/spotbugs.txt b/src/statick_tool/rsc/plugin_mapping/spotbugs.txt similarity index 100% rename from statick_tool/rsc/plugin_mapping/spotbugs.txt rename to src/statick_tool/rsc/plugin_mapping/spotbugs.txt diff --git a/statick_tool/rsc/profile.yaml b/src/statick_tool/rsc/profile.yaml similarity index 100% rename from statick_tool/rsc/profile.yaml rename to src/statick_tool/rsc/profile.yaml diff --git a/statick_tool/rsc/sei_cert.yaml b/src/statick_tool/rsc/sei_cert.yaml similarity index 100% rename from statick_tool/rsc/sei_cert.yaml rename to src/statick_tool/rsc/sei_cert.yaml diff --git a/statick_tool/rsc/self_check.yaml b/src/statick_tool/rsc/self_check.yaml similarity index 100% rename from statick_tool/rsc/self_check.yaml rename to src/statick_tool/rsc/self_check.yaml diff --git a/statick_tool/rsc/spotbugs-security.xml b/src/statick_tool/rsc/spotbugs-security.xml similarity index 100% rename from statick_tool/rsc/spotbugs-security.xml rename to src/statick_tool/rsc/spotbugs-security.xml diff --git a/statick_tool/rsc/ultimate.yaml b/src/statick_tool/rsc/ultimate.yaml similarity index 100% rename from statick_tool/rsc/ultimate.yaml rename to src/statick_tool/rsc/ultimate.yaml diff --git a/statick_tool/rsc/uncrustify.cfg b/src/statick_tool/rsc/uncrustify.cfg similarity index 100% rename from statick_tool/rsc/uncrustify.cfg rename to src/statick_tool/rsc/uncrustify.cfg diff --git a/statick b/src/statick_tool/statick.py similarity index 76% rename from statick rename to src/statick_tool/statick.py index ee1f10ca..9a2279c3 100755 --- a/statick +++ b/src/statick_tool/statick.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Executable script for running statick against a single package.""" +"""Executable script for running Statick against one or more packages.""" import argparse import sys @@ -8,11 +8,13 @@ from tabulate import tabulate from statick_tool.args import Args -from statick_tool.statick import Statick +from statick_tool.statick_tool import Statick -def run(statick: Statick, parsed_args: argparse.Namespace, start_time: float) -> bool: - """Run statick on a single package.""" +def run( + statick: Statick, parsed_args: argparse.Namespace, start_time: float +) -> bool: # pragma: no cover + """Run Statick on a single package.""" path = parsed_args.path issues, success = statick.run(path, parsed_args, start_time) if issues is None: @@ -24,8 +26,8 @@ def run(statick: Statick, parsed_args: argparse.Namespace, start_time: float) -> return success -def main() -> None: - """Run statick.""" +def main() -> None: # pragma: no cover + """Run Statick.""" start_time: float = time.time() args = Args("Statick tool") args.parser.add_argument("path", help="Path of package or workspace to scan") @@ -54,5 +56,5 @@ def main() -> None: sys.exit(0) -if __name__ == "__main__": +if __name__ == "__main__": # pragma: no cover main() diff --git a/statick_tool/statick.py b/src/statick_tool/statick_tool.py similarity index 95% rename from statick_tool/statick.py rename to src/statick_tool/statick_tool.py index f6137881..1da37e1d 100644 --- a/statick_tool/statick.py +++ b/src/statick_tool/statick_tool.py @@ -8,12 +8,10 @@ import os import sys import time +from importlib.metadata import version from logging.handlers import MemoryHandler from typing import Any, Dict, List, Optional, Tuple -from yapsy.PluginManager import PluginManager - -from statick_tool import __version__ from statick_tool.config import Config from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions @@ -21,10 +19,13 @@ from statick_tool.package import Package from statick_tool.plugin_context import PluginContext from statick_tool.profile import Profile -from statick_tool.reporting_plugin import ReportingPlugin from statick_tool.resources import Resources from statick_tool.timing import Timing -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points class Statick: # pylint: disable=too-many-instance-attributes @@ -35,34 +36,23 @@ def __init__(self, user_paths: List[str]) -> None: self.default_level = "default" self.resources = Resources(user_paths) - self.manager = PluginManager() - self.manager.setPluginPlaces(self.resources.get_plugin_paths()) - self.manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - "Tool": ToolPlugin, - "Reporting": ReportingPlugin, - } - ) - self.manager.collectPlugins() - self.discovery_plugins: Dict[str, Any] = {} - for plugin_info in self.manager.getPluginsOfCategory("Discovery"): - self.discovery_plugins[plugin_info.plugin_object.get_name()] = ( - plugin_info.plugin_object - ) - - self.tool_plugins: Dict[str, Any] = {} - for plugin_info in self.manager.getPluginsOfCategory("Tool"): - self.tool_plugins[plugin_info.plugin_object.get_name()] = ( - plugin_info.plugin_object - ) + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + self.discovery_plugins[plugin_type.name] = plugin() self.reporting_plugins: Dict[str, Any] = {} - for plugin_info in self.manager.getPluginsOfCategory("Reporting"): - self.reporting_plugins[plugin_info.plugin_object.get_name()] = ( - plugin_info.plugin_object - ) + plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in plugins: + plugin = plugin_type.load() + self.reporting_plugins[plugin_type.name] = plugin() + + self.tool_plugins: Dict[str, Any] = {} + plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in plugins: + plugin = plugin_type.load() + self.tool_plugins[plugin_type.name] = plugin() self.config: Optional[Config] = None self.exceptions: Optional[Exceptions] = None @@ -195,7 +185,7 @@ def gather_args(self, args: argparse.ArgumentParser) -> None: args.add_argument( "--version", action="version", - version=f"%(prog)s {__version__}", + version=f"%(prog)s {version('statick')}", ) args.add_argument( "--mapping-file-suffix", @@ -242,10 +232,10 @@ def gather_args(self, args: argparse.ArgumentParser) -> None: for _, plugin in list(self.discovery_plugins.items()): plugin.gather_args(args) - for _, plugin in list(self.tool_plugins.items()): + for _, plugin in list(self.reporting_plugins.items()): plugin.gather_args(args) - for _, plugin in list(self.reporting_plugins.items()): + for _, plugin in list(self.tool_plugins.items()): plugin.gather_args(args) def get_level(self, path: str, args: argparse.Namespace) -> Optional[str]: diff --git a/statick_tool/timing.py b/src/statick_tool/timing.py similarity index 100% rename from statick_tool/timing.py rename to src/statick_tool/timing.py diff --git a/statick_tool/tool_plugin.py b/src/statick_tool/tool_plugin.py similarity index 98% rename from statick_tool/tool_plugin.py rename to src/statick_tool/tool_plugin.py index 0b57cc6a..18ee3a2c 100644 --- a/statick_tool/tool_plugin.py +++ b/src/statick_tool/tool_plugin.py @@ -6,15 +6,13 @@ import shlex from typing import Any, Dict, List, Optional, Union -from yapsy.IPlugin import IPlugin - from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.plugin_context import PluginContext # No stubs available for IPlugin so ignoring type. -class ToolPlugin(IPlugin): # type: ignore +class ToolPlugin: """Default implementation of tool plugin.""" plugin_context = None diff --git a/statick_tool/plugins/discovery/c_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/c_discovery_plugin.yapsy-plugin deleted file mode 100644 index a1869c10..00000000 --- a/statick_tool/plugins/discovery/c_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = C/C++ Discovery Plugin -Module = c_discovery_plugin diff --git a/statick_tool/plugins/discovery/cmake_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/cmake_discovery_plugin.yapsy-plugin deleted file mode 100644 index 7b7f12a5..00000000 --- a/statick_tool/plugins/discovery/cmake_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = CMake Discovery Plugin -Module = cmake_discovery_plugin diff --git a/statick_tool/plugins/discovery/groovy_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/groovy_discovery_plugin.yapsy-plugin deleted file mode 100644 index 481ac040..00000000 --- a/statick_tool/plugins/discovery/groovy_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Groovy Discovery Plugin -Module = groovy_discovery_plugin diff --git a/statick_tool/plugins/discovery/java_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/java_discovery_plugin.yapsy-plugin deleted file mode 100644 index c45e9cf6..00000000 --- a/statick_tool/plugins/discovery/java_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Java Discovery Plugin -Module = java_discovery_plugin diff --git a/statick_tool/plugins/discovery/maven_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/maven_discovery_plugin.yapsy-plugin deleted file mode 100644 index 3f16d904..00000000 --- a/statick_tool/plugins/discovery/maven_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Maven Discovery Plugin -Module = maven_discovery_plugin diff --git a/statick_tool/plugins/discovery/perl_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/perl_discovery_plugin.yapsy-plugin deleted file mode 100644 index 2611bb9b..00000000 --- a/statick_tool/plugins/discovery/perl_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Perl Discovery Plugin -Module = perl_discovery_plugin diff --git a/statick_tool/plugins/discovery/python_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/python_discovery_plugin.yapsy-plugin deleted file mode 100644 index 4e46dad3..00000000 --- a/statick_tool/plugins/discovery/python_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Python Discovery Plugin -Module = python_discovery_plugin diff --git a/statick_tool/plugins/discovery/ros_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/ros_discovery_plugin.yapsy-plugin deleted file mode 100644 index 6ac392b7..00000000 --- a/statick_tool/plugins/discovery/ros_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = ROS Discovery Plugin -Module = ros_discovery_plugin diff --git a/statick_tool/plugins/discovery/shell_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/shell_discovery_plugin.yapsy-plugin deleted file mode 100644 index a5381d89..00000000 --- a/statick_tool/plugins/discovery/shell_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Shell Discovery Plugin -Module = shell_discovery_plugin diff --git a/statick_tool/plugins/discovery/xml_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/xml_discovery_plugin.yapsy-plugin deleted file mode 100644 index c8c944a4..00000000 --- a/statick_tool/plugins/discovery/xml_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = XML Discovery Plugin -Module = xml_discovery_plugin diff --git a/statick_tool/plugins/discovery/yaml_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/yaml_discovery_plugin.yapsy-plugin deleted file mode 100644 index ac3ef60d..00000000 --- a/statick_tool/plugins/discovery/yaml_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = YAML Discovery Plugin -Module = yaml_discovery_plugin diff --git a/statick_tool/plugins/reporting/code_climate_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/code_climate_reporting_plugin.yapsy-plugin deleted file mode 100644 index 914607a1..00000000 --- a/statick_tool/plugins/reporting/code_climate_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Code Climate Reporting Plugin -Module = code_climate_reporting_plugin diff --git a/statick_tool/plugins/reporting/do_nothing_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/do_nothing_reporting_plugin.yapsy-plugin deleted file mode 100644 index 3003f2dd..00000000 --- a/statick_tool/plugins/reporting/do_nothing_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Do Nothing Reporting Plugin -Module = do_nothing_reporting_plugin diff --git a/statick_tool/plugins/reporting/json_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/json_reporting_plugin.yapsy-plugin deleted file mode 100644 index c45fecc0..00000000 --- a/statick_tool/plugins/reporting/json_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = JSON Reporting Plugin -Module = json_reporting_plugin diff --git a/statick_tool/plugins/reporting/print_to_console_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/print_to_console_reporting_plugin.yapsy-plugin deleted file mode 100644 index 4d8faac8..00000000 --- a/statick_tool/plugins/reporting/print_to_console_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Print To Console Reporting Plugin -Module = print_to_console_reporting_plugin diff --git a/statick_tool/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin.yapsy-plugin deleted file mode 100644 index 9b487415..00000000 --- a/statick_tool/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Write Jenkins Warnings NG Reporting Plugin -Module = write_jenkins_warnings_ng_reporting_plugin diff --git a/statick_tool/plugins/tool/bandit_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/bandit_tool_plugin.yapsy-plugin deleted file mode 100644 index 69e4e298..00000000 --- a/statick_tool/plugins/tool/bandit_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Bandit Tool Plugin -Module = bandit_tool_plugin diff --git a/statick_tool/plugins/tool/black_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/black_tool_plugin.yapsy-plugin deleted file mode 100644 index 62dcc66d..00000000 --- a/statick_tool/plugins/tool/black_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Black Tool Plugin -Module = black_tool_plugin diff --git a/statick_tool/plugins/tool/catkin_lint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/catkin_lint_tool_plugin.yapsy-plugin deleted file mode 100644 index 5cd36a71..00000000 --- a/statick_tool/plugins/tool/catkin_lint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Catkin Lint Tool Plugin -Module = catkin_lint_tool_plugin diff --git a/statick_tool/plugins/tool/cccc_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/cccc_tool_plugin.yapsy-plugin deleted file mode 100644 index 4174ef70..00000000 --- a/statick_tool/plugins/tool/cccc_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = CCCC Tool Plugin -Module = cccc_tool_plugin diff --git a/statick_tool/plugins/tool/clang_format_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/clang_format_tool_plugin.yapsy-plugin deleted file mode 100644 index bb6a03a8..00000000 --- a/statick_tool/plugins/tool/clang_format_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = clang-format Tool Plugin -Module = clang_format_tool_plugin diff --git a/statick_tool/plugins/tool/clang_tidy_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/clang_tidy_tool_plugin.yapsy-plugin deleted file mode 100644 index c196c142..00000000 --- a/statick_tool/plugins/tool/clang_tidy_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = clang-tidy Tool Plugin -Module = clang_tidy_tool_plugin diff --git a/statick_tool/plugins/tool/cmakelint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/cmakelint_tool_plugin.yapsy-plugin deleted file mode 100644 index 3053ea9d..00000000 --- a/statick_tool/plugins/tool/cmakelint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = cmakelint Tool Plugin -Module = cmakelint_tool_plugin diff --git a/statick_tool/plugins/tool/cppcheck_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/cppcheck_tool_plugin.yapsy-plugin deleted file mode 100644 index 3a8a151e..00000000 --- a/statick_tool/plugins/tool/cppcheck_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Cppcheck Tool Plugin -Module = cppcheck_tool_plugin diff --git a/statick_tool/plugins/tool/cpplint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/cpplint_tool_plugin.yapsy-plugin deleted file mode 100644 index ff5a3cfe..00000000 --- a/statick_tool/plugins/tool/cpplint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Cpplint Tool Plugin -Module = cpplint_tool_plugin diff --git a/statick_tool/plugins/tool/do_nothing_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/do_nothing_tool_plugin.yapsy-plugin deleted file mode 100644 index fc4d4b4d..00000000 --- a/statick_tool/plugins/tool/do_nothing_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Do Nothing Tool Plugin -Module = do_nothing_tool_plugin diff --git a/statick_tool/plugins/tool/docformatter_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/docformatter_tool_plugin.yapsy-plugin deleted file mode 100644 index faf174b6..00000000 --- a/statick_tool/plugins/tool/docformatter_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Docformatter Tool Plugin -Module = docformatter_tool_plugin diff --git a/statick_tool/plugins/tool/flawfinder_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/flawfinder_tool_plugin.yapsy-plugin deleted file mode 100644 index 6a0222e9..00000000 --- a/statick_tool/plugins/tool/flawfinder_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Flawfinder Tool Plugin -Module = flawfinder_tool_plugin diff --git a/statick_tool/plugins/tool/groovylint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/groovylint_tool_plugin.yapsy-plugin deleted file mode 100644 index 016b8e5a..00000000 --- a/statick_tool/plugins/tool/groovylint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = NPM Groovy Lint Tool Plugin -Module = groovylint_tool_plugin diff --git a/statick_tool/plugins/tool/isort_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/isort_tool_plugin.yapsy-plugin deleted file mode 100644 index 1b101b83..00000000 --- a/statick_tool/plugins/tool/isort_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Isort Tool Plugin -Module = isort_tool_plugin diff --git a/statick_tool/plugins/tool/lizard_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/lizard_tool_plugin.yapsy-plugin deleted file mode 100644 index da21452c..00000000 --- a/statick_tool/plugins/tool/lizard_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Lizard Tool Plugin -Module = lizard_tool_plugin diff --git a/statick_tool/plugins/tool/make_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/make_tool_plugin.yapsy-plugin deleted file mode 100644 index 07357ff1..00000000 --- a/statick_tool/plugins/tool/make_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Make Tool Plugin -Module = make_tool_plugin diff --git a/statick_tool/plugins/tool/mypy_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/mypy_tool_plugin.yapsy-plugin deleted file mode 100644 index 68fdbfd2..00000000 --- a/statick_tool/plugins/tool/mypy_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Mypy Tool Plugin -Module = mypy_tool_plugin diff --git a/statick_tool/plugins/tool/perlcritic_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/perlcritic_tool_plugin.yapsy-plugin deleted file mode 100644 index 2da9e4da..00000000 --- a/statick_tool/plugins/tool/perlcritic_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Perl::Critic Tool Plugin -Module = perlcritic_tool_plugin diff --git a/statick_tool/plugins/tool/pycodestyle_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/pycodestyle_tool_plugin.yapsy-plugin deleted file mode 100644 index 415a0480..00000000 --- a/statick_tool/plugins/tool/pycodestyle_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Pycodestyle Tool Plugin -Module = pycodestyle_tool_plugin diff --git a/statick_tool/plugins/tool/pydocstyle_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/pydocstyle_tool_plugin.yapsy-plugin deleted file mode 100644 index 88e36e3f..00000000 --- a/statick_tool/plugins/tool/pydocstyle_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Pydocstyle Tool Plugin -Module = pydocstyle_tool_plugin diff --git a/statick_tool/plugins/tool/pyflakes_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/pyflakes_tool_plugin.yapsy-plugin deleted file mode 100644 index de888a3d..00000000 --- a/statick_tool/plugins/tool/pyflakes_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Pyflakes Tool Plugin -Module = pyflakes_tool_plugin diff --git a/statick_tool/plugins/tool/pylint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/pylint_tool_plugin.yapsy-plugin deleted file mode 100644 index ac507ca2..00000000 --- a/statick_tool/plugins/tool/pylint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Pylint Tool Plugin -Module = pylint_tool_plugin diff --git a/statick_tool/plugins/tool/ruff_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/ruff_tool_plugin.yapsy-plugin deleted file mode 100644 index adb167f6..00000000 --- a/statick_tool/plugins/tool/ruff_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Ruff Tool Plugin -Module = ruff_tool_plugin diff --git a/statick_tool/plugins/tool/shellcheck_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/shellcheck_tool_plugin.yapsy-plugin deleted file mode 100644 index ffa620be..00000000 --- a/statick_tool/plugins/tool/shellcheck_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Shellcheck Tool Plugin -Module = shellcheck_tool_plugin diff --git a/statick_tool/plugins/tool/spotbugs_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/spotbugs_tool_plugin.yapsy-plugin deleted file mode 100644 index 60b70837..00000000 --- a/statick_tool/plugins/tool/spotbugs_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Spotbugs Tool Plugin -Module = spotbugs_tool_plugin diff --git a/statick_tool/plugins/tool/uncrustify_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/uncrustify_tool_plugin.yapsy-plugin deleted file mode 100644 index 06b813b2..00000000 --- a/statick_tool/plugins/tool/uncrustify_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Uncrustify Tool Plugin -Module = uncrustify_tool_plugin diff --git a/statick_tool/plugins/tool/xmllint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/xmllint_tool_plugin.yapsy-plugin deleted file mode 100644 index 0cc0dc7c..00000000 --- a/statick_tool/plugins/tool/xmllint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = xmllint Tool Plugin -Module = xmllint_tool_plugin diff --git a/statick_tool/plugins/tool/yamllint_tool_plugin.yapsy-plugin b/statick_tool/plugins/tool/yamllint_tool_plugin.yapsy-plugin deleted file mode 100644 index ccdaec5a..00000000 --- a/statick_tool/plugins/tool/yamllint_tool_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = yamllint Tool Plugin -Module = yamllint_tool_plugin diff --git a/templates/Dockerfile b/templates/Dockerfile index 49b90bf6..461abafb 100644 --- a/templates/Dockerfile +++ b/templates/Dockerfile @@ -1,5 +1,5 @@ -FROM ubuntu:xenial -LABEL maintainer="SPAWAR" +FROM ubuntu:22.04 +LABEL maintainer="NIWC" LABEL org.label-schema.name = "Statick Runner" LABEL org.label-schema.vcs-url = "https://github.com/sscpac/statick" @@ -14,14 +14,13 @@ RUN update-locale LC_ALL=en_US.UTF-8 # Statick requirements # packages needed to checkout and run statick itself -RUN apt-get update && apt-get install -y git wget build-essential python-yapsy python-yapsy python-yaml +RUN apt-get update && apt-get install -y git wget build-essential python-yaml # external tools -RUN apt-get update && apt-get install -y flawfinder clang-tidy clang-format clang python-yapsy findbugs bandit flawfinder libomp-dev libxml2 cppcheck cmake pylint python-pylint-django +RUN apt-get update && apt-get install -y flawfinder clang-tidy clang-format clang findbugs bandit flawfinder libomp-dev libxml2 cppcheck cmake pylint python-pylint-django RUN pip install --upgrade pip -RUN pip install yamllint cmakelint lizard flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-docstrings flake8-import-order flake8-quotes +RUN pip install yamllint cmakelint lizard flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-docstrings flake8-import-order flake8-quotes - -# Jenkins user setup (keep this at the bottom) -RUN useradd -m jenkins -s /bin/bash +# Statick user setup (keep this at the bottom) +RUN useradd -m statick -s /bin/bash ENV JAVA_OPTS="-Xmx8292m" -USER jenkins +USER statick diff --git a/tests/exceptions/test_exceptions.py b/tests/exceptions/test_exceptions.py index 2f582bce..4113bee7 100644 --- a/tests/exceptions/test_exceptions.py +++ b/tests/exceptions/test_exceptions.py @@ -2,6 +2,7 @@ import os import tempfile +from tempfile import TemporaryDirectory import pytest @@ -9,13 +10,6 @@ from statick_tool.issue import Issue from statick_tool.package import Package -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) - def test_exceptions_init_valid(): """Test that the Exceptions module initializes correctly. diff --git a/tests/plugins/discovery/c_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/c/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/c/exceptions.yaml diff --git a/tests/plugins/discovery/c_discovery_plugin/invalid_package/test.cfg b/tests/plugins/discovery/c/invalid_package/test.cfg similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/invalid_package/test.cfg rename to tests/plugins/discovery/c/invalid_package/test.cfg diff --git a/tests/plugins/discovery/c_discovery_plugin/invalid_package/test.cxy b/tests/plugins/discovery/c/invalid_package/test.cxy similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/invalid_package/test.cxy rename to tests/plugins/discovery/c/invalid_package/test.cxy diff --git a/tests/plugins/discovery/c_discovery_plugin/invalid_package/test.ha b/tests/plugins/discovery/c/invalid_package/test.ha similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/invalid_package/test.ha rename to tests/plugins/discovery/c/invalid_package/test.ha diff --git a/tests/plugins/discovery/c_discovery_plugin/test_c_discovery_plugin.py b/tests/plugins/discovery/c/test_c_discovery_plugin.py similarity index 81% rename from tests/plugins/discovery/c_discovery_plugin/test_c_discovery_plugin.py rename to tests/plugins/discovery/c/test_c_discovery_plugin.py index 51662d47..fa76e544 100644 --- a/tests/plugins/discovery/c_discovery_plugin/test_c_discovery_plugin.py +++ b/tests/plugins/discovery/c/test_c_discovery_plugin.py @@ -2,14 +2,16 @@ import contextlib import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.c_discovery_plugin import CDiscoveryPlugin +from statick_tool.plugins.discovery.c import CDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points # From https://stackoverflow.com/questions/2059482/python-temporarily-modify-the-current-processs-environment @@ -44,27 +46,13 @@ def modified_environ(*remove, **update): def test_c_discovery_plugin_found(): """Test that the plugin manager finds the C discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "c" - assert any( - plugin_info.plugin_object.get_name() == "C" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named C Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "C/C++ Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "C" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/ignore_this/ignoreme.c b/tests/plugins/discovery/c/valid_package/ignore_this/ignoreme.c similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/ignore_this/ignoreme.c rename to tests/plugins/discovery/c/valid_package/ignore_this/ignoreme.c diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/oddextensionc.source b/tests/plugins/discovery/c/valid_package/oddextensionc.source similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/oddextensionc.source rename to tests/plugins/discovery/c/valid_package/oddextensionc.source diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/oddextensioncpp.source b/tests/plugins/discovery/c/valid_package/oddextensioncpp.source similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/oddextensioncpp.source rename to tests/plugins/discovery/c/valid_package/oddextensioncpp.source diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.c b/tests/plugins/discovery/c/valid_package/test.c similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.c rename to tests/plugins/discovery/c/valid_package/test.c diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.cc b/tests/plugins/discovery/c/valid_package/test.cc similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.cc rename to tests/plugins/discovery/c/valid_package/test.cc diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.cpp b/tests/plugins/discovery/c/valid_package/test.cpp similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.cpp rename to tests/plugins/discovery/c/valid_package/test.cpp diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.cxx b/tests/plugins/discovery/c/valid_package/test.cxx similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.cxx rename to tests/plugins/discovery/c/valid_package/test.cxx diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.h b/tests/plugins/discovery/c/valid_package/test.h similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.h rename to tests/plugins/discovery/c/valid_package/test.h diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.hpp b/tests/plugins/discovery/c/valid_package/test.hpp similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.hpp rename to tests/plugins/discovery/c/valid_package/test.hpp diff --git a/tests/plugins/discovery/c_discovery_plugin/valid_package/test.hxx b/tests/plugins/discovery/c/valid_package/test.hxx similarity index 100% rename from tests/plugins/discovery/c_discovery_plugin/valid_package/test.hxx rename to tests/plugins/discovery/c/valid_package/test.hxx diff --git a/tests/plugins/discovery/cmake_discovery_plugin/cmake_ext_package/CMakeModules/FindCython.cmake b/tests/plugins/discovery/cmake/cmake_ext_package/CMakeModules/FindCython.cmake similarity index 100% rename from tests/plugins/discovery/cmake_discovery_plugin/cmake_ext_package/CMakeModules/FindCython.cmake rename to tests/plugins/discovery/cmake/cmake_ext_package/CMakeModules/FindCython.cmake diff --git a/tests/plugins/discovery/cmake_discovery_plugin/test_cmake_discovery_plugin.py b/tests/plugins/discovery/cmake/test_cmake_discovery_plugin.py similarity index 87% rename from tests/plugins/discovery/cmake_discovery_plugin/test_cmake_discovery_plugin.py rename to tests/plugins/discovery/cmake/test_cmake_discovery_plugin.py index bc683ef1..41e1e01a 100644 --- a/tests/plugins/discovery/cmake_discovery_plugin/test_cmake_discovery_plugin.py +++ b/tests/plugins/discovery/cmake/test_cmake_discovery_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.discovery.cmake_discovery_plugin import CMakeDiscoveryPlugin +from statick_tool.plugins.discovery.cmake import CMakeDiscoveryPlugin from statick_tool.resources import Resources +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + def setup_cmake_discovery_plugin(add_plugin_context=True, cmake_flags=""): """Create an instance of the CMake discovery plugin.""" @@ -35,27 +39,13 @@ def setup_cmake_discovery_plugin(add_plugin_context=True, cmake_flags=""): def test_cmake_discovery_plugin_found(): """Test that the plugin manager finds the CMake discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "cmake" - assert any( - plugin_info.plugin_object.get_name() == "cmake" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named CMake Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "CMake Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "cmake" for _, plugin in list(discovery_plugins.items()) ) @@ -218,7 +208,7 @@ def test_cmake_discovery_plugin_check_output_cpplint_with_roslint_installed( @mock.patch( - "statick_tool.plugins.discovery.cmake_discovery_plugin.subprocess.check_output" + "statick_tool.plugins.discovery.cmake.subprocess.check_output" ) def test_cmake_discovery_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means CMake hit an @@ -238,7 +228,7 @@ def test_cmake_discovery_plugin_scan_calledprocesserror(mock_subprocess_check_ou @mock.patch( - "statick_tool.plugins.discovery.cmake_discovery_plugin.subprocess.check_output" + "statick_tool.plugins.discovery.cmake.subprocess.check_output" ) def test_cmake_discovery_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means CMake is not diff --git a/tests/plugins/discovery/cmake_discovery_plugin/valid_package/CMakeLists.txt b/tests/plugins/discovery/cmake/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/discovery/cmake_discovery_plugin/valid_package/CMakeLists.txt rename to tests/plugins/discovery/cmake/valid_package/CMakeLists.txt diff --git a/tests/plugins/discovery/groovy_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/groovy/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/groovy/exceptions.yaml diff --git a/tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.aux b/tests/plugins/discovery/groovy/invalid_package/test.aux similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.aux rename to tests/plugins/discovery/groovy/invalid_package/test.aux diff --git a/tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.cls b/tests/plugins/discovery/groovy/invalid_package/test.cls similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.cls rename to tests/plugins/discovery/groovy/invalid_package/test.cls diff --git a/tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.sty b/tests/plugins/discovery/groovy/invalid_package/test.sty similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/invalid_package/test.sty rename to tests/plugins/discovery/groovy/invalid_package/test.sty diff --git a/tests/plugins/discovery/groovy_discovery_plugin/test_groovy_discovery_plugin.py b/tests/plugins/discovery/groovy/test_groovy_discovery_plugin.py similarity index 68% rename from tests/plugins/discovery/groovy_discovery_plugin/test_groovy_discovery_plugin.py rename to tests/plugins/discovery/groovy/test_groovy_discovery_plugin.py index c91e0908..5b8ec4da 100644 --- a/tests/plugins/discovery/groovy_discovery_plugin/test_groovy_discovery_plugin.py +++ b/tests/plugins/discovery/groovy/test_groovy_discovery_plugin.py @@ -1,39 +1,26 @@ """Unit tests for the Groovy discovery plugin.""" - import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.groovy_discovery_plugin import GroovyDiscoveryPlugin +from statick_tool.plugins.discovery.groovy import GroovyDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_groovy_plugin_found(): """Test that the plugin manager finds the Groovy discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "Groovy" - assert any( - plugin_info.plugin_object.get_name() == "groovy" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Groovy Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Groovy Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "groovy" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/groovy_discovery_plugin/valid_package/Jenkinsfile b/tests/plugins/discovery/groovy/valid_package/Jenkinsfile similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/valid_package/Jenkinsfile rename to tests/plugins/discovery/groovy/valid_package/Jenkinsfile diff --git a/tests/plugins/discovery/groovy_discovery_plugin/valid_package/ignore_this/ignoreme.groovy b/tests/plugins/discovery/groovy/valid_package/ignore_this/ignoreme.groovy similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/valid_package/ignore_this/ignoreme.groovy rename to tests/plugins/discovery/groovy/valid_package/ignore_this/ignoreme.groovy diff --git a/tests/plugins/discovery/groovy_discovery_plugin/valid_package/test.gradle b/tests/plugins/discovery/groovy/valid_package/test.gradle similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/valid_package/test.gradle rename to tests/plugins/discovery/groovy/valid_package/test.gradle diff --git a/tests/plugins/discovery/groovy_discovery_plugin/valid_package/test.groovy b/tests/plugins/discovery/groovy/valid_package/test.groovy similarity index 100% rename from tests/plugins/discovery/groovy_discovery_plugin/valid_package/test.groovy rename to tests/plugins/discovery/groovy/valid_package/test.groovy diff --git a/tests/plugins/discovery/java_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/java/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/java/exceptions.yaml diff --git a/tests/plugins/discovery/java_discovery_plugin/invalid_package/test.javac b/tests/plugins/discovery/java/invalid_package/test.javac similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/invalid_package/test.javac rename to tests/plugins/discovery/java/invalid_package/test.javac diff --git a/tests/plugins/discovery/java_discovery_plugin/test_java_discovery_plugin.py b/tests/plugins/discovery/java/test_java_discovery_plugin.py similarity index 71% rename from tests/plugins/discovery/java_discovery_plugin/test_java_discovery_plugin.py rename to tests/plugins/discovery/java/test_java_discovery_plugin.py index e1026b9e..e784f0d7 100644 --- a/tests/plugins/discovery/java_discovery_plugin/test_java_discovery_plugin.py +++ b/tests/plugins/discovery/java/test_java_discovery_plugin.py @@ -1,39 +1,27 @@ """Unit tests for the Java discovery plugin.""" import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.java_discovery_plugin import JavaDiscoveryPlugin +from statick_tool.plugins.discovery.java import JavaDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_java_discovery_plugin_found(): """Test that the plugin manager finds the Java discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "java" - assert any( - plugin_info.plugin_object.get_name() == "java" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Java Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Java Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "java" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/java_discovery_plugin/valid_package/ignore_this/IgnoreMe.class b/tests/plugins/discovery/java/valid_package/ignore_this/IgnoreMe.class similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/valid_package/ignore_this/IgnoreMe.class rename to tests/plugins/discovery/java/valid_package/ignore_this/IgnoreMe.class diff --git a/tests/plugins/discovery/java_discovery_plugin/valid_package/ignore_this/ignoreme.java b/tests/plugins/discovery/java/valid_package/ignore_this/ignoreme.java similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/valid_package/ignore_this/ignoreme.java rename to tests/plugins/discovery/java/valid_package/ignore_this/ignoreme.java diff --git a/tests/plugins/discovery/java_discovery_plugin/valid_package/test.class b/tests/plugins/discovery/java/valid_package/test.class similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/valid_package/test.class rename to tests/plugins/discovery/java/valid_package/test.class diff --git a/tests/plugins/discovery/java_discovery_plugin/valid_package/test.java b/tests/plugins/discovery/java/valid_package/test.java similarity index 100% rename from tests/plugins/discovery/java_discovery_plugin/valid_package/test.java rename to tests/plugins/discovery/java/valid_package/test.java diff --git a/tests/plugins/discovery/maven_discovery_plugin/multi_package/a/c/pom.xml b/tests/plugins/discovery/maven/multi_package/a/c/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/multi_package/a/c/pom.xml rename to tests/plugins/discovery/maven/multi_package/a/c/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/multi_package/a/pom.xml b/tests/plugins/discovery/maven/multi_package/a/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/multi_package/a/pom.xml rename to tests/plugins/discovery/maven/multi_package/a/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/multi_package/b/pom.xml b/tests/plugins/discovery/maven/multi_package/b/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/multi_package/b/pom.xml rename to tests/plugins/discovery/maven/multi_package/b/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/single_package/pom.xml b/tests/plugins/discovery/maven/single_package/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/single_package/pom.xml rename to tests/plugins/discovery/maven/single_package/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/test_maven_discovery_plugin.py b/tests/plugins/discovery/maven/test_maven_discovery_plugin.py similarity index 74% rename from tests/plugins/discovery/maven_discovery_plugin/test_maven_discovery_plugin.py rename to tests/plugins/discovery/maven/test_maven_discovery_plugin.py index afae9ec5..ccd9657c 100644 --- a/tests/plugins/discovery/maven_discovery_plugin/test_maven_discovery_plugin.py +++ b/tests/plugins/discovery/maven/test_maven_discovery_plugin.py @@ -1,39 +1,27 @@ """Unit tests for the Maven discovery plugin.""" import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.maven_discovery_plugin import MavenDiscoveryPlugin +from statick_tool.plugins.discovery.maven import MavenDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_maven_discovery_plugin_found(): """Test that the plugin manager finds the Maven discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "java" - assert any( - plugin_info.plugin_object.get_name() == "maven" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Maven Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Maven Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "maven" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/maven_discovery_plugin/two_package/a/pom.xml b/tests/plugins/discovery/maven/two_package/a/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/two_package/a/pom.xml rename to tests/plugins/discovery/maven/two_package/a/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/two_package/b/pom.xml b/tests/plugins/discovery/maven/two_package/b/pom.xml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/two_package/b/pom.xml rename to tests/plugins/discovery/maven/two_package/b/pom.xml diff --git a/tests/plugins/discovery/maven_discovery_plugin/valid_exceptions.yaml b/tests/plugins/discovery/maven/valid_exceptions.yaml similarity index 100% rename from tests/plugins/discovery/maven_discovery_plugin/valid_exceptions.yaml rename to tests/plugins/discovery/maven/valid_exceptions.yaml diff --git a/tests/plugins/discovery/perl_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/perl/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/perl_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/perl/exceptions.yaml diff --git a/tests/plugins/discovery/perl_discovery_plugin/test_perl_discovery_plugin.py b/tests/plugins/discovery/perl/test_perl_discovery_plugin.py similarity index 79% rename from tests/plugins/discovery/perl_discovery_plugin/test_perl_discovery_plugin.py rename to tests/plugins/discovery/perl/test_perl_discovery_plugin.py index 4522952b..fdeba61c 100644 --- a/tests/plugins/discovery/perl_discovery_plugin/test_perl_discovery_plugin.py +++ b/tests/plugins/discovery/perl/test_perl_discovery_plugin.py @@ -2,15 +2,18 @@ import contextlib import os +import sys import pytest -from yapsy.PluginManager import PluginManager -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.perl_discovery_plugin import PerlDiscoveryPlugin +from statick_tool.plugins.discovery.perl import PerlDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points # From https://stackoverflow.com/questions/2059482/python-temporarily-modify-the-current-processs-environment @@ -45,27 +48,13 @@ def modified_environ(*remove, **update): def test_perl_discovery_plugin_found(): """Test that the plugin manager finds the Perl discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "perl" - assert any( - plugin_info.plugin_object.get_name() == "perl" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Perl Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Perl Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "perl" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/perl_discovery_plugin/valid_package/ignore_this/ignoreme.pl b/tests/plugins/discovery/perl/valid_package/ignore_this/ignoreme.pl similarity index 100% rename from tests/plugins/discovery/perl_discovery_plugin/valid_package/ignore_this/ignoreme.pl rename to tests/plugins/discovery/perl/valid_package/ignore_this/ignoreme.pl diff --git a/tests/plugins/discovery/perl_discovery_plugin/valid_package/oddextensionpl.source b/tests/plugins/discovery/perl/valid_package/oddextensionpl.source similarity index 100% rename from tests/plugins/discovery/perl_discovery_plugin/valid_package/oddextensionpl.source rename to tests/plugins/discovery/perl/valid_package/oddextensionpl.source diff --git a/tests/plugins/discovery/perl_discovery_plugin/valid_package/test.pl b/tests/plugins/discovery/perl/valid_package/test.pl similarity index 100% rename from tests/plugins/discovery/perl_discovery_plugin/valid_package/test.pl rename to tests/plugins/discovery/perl/valid_package/test.pl diff --git a/tests/plugins/discovery/python_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/python/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/python_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/python/exceptions.yaml diff --git a/tests/plugins/discovery/python_discovery_plugin/invalid_package/test.cfg b/tests/plugins/discovery/python/invalid_package/test.cfg similarity index 100% rename from tests/plugins/discovery/python_discovery_plugin/invalid_package/test.cfg rename to tests/plugins/discovery/python/invalid_package/test.cfg diff --git a/tests/plugins/discovery/python_discovery_plugin/test_python_discovery_plugin.py b/tests/plugins/discovery/python/test_python_discovery_plugin.py similarity index 80% rename from tests/plugins/discovery/python_discovery_plugin/test_python_discovery_plugin.py rename to tests/plugins/discovery/python/test_python_discovery_plugin.py index fd1f4653..da36d555 100644 --- a/tests/plugins/discovery/python_discovery_plugin/test_python_discovery_plugin.py +++ b/tests/plugins/discovery/python/test_python_discovery_plugin.py @@ -2,15 +2,18 @@ import contextlib import os +import sys import pytest -from yapsy.PluginManager import PluginManager -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.python_discovery_plugin import PythonDiscoveryPlugin +from statick_tool.plugins.discovery.python import PythonDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points # From https://stackoverflow.com/questions/2059482/python-temporarily-modify-the-current-processs-environment @@ -45,27 +48,13 @@ def modified_environ(*remove, **update): def test_python_discovery_plugin_found(): """Test that the plugin manager finds the Python discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "python" - assert any( - plugin_info.plugin_object.get_name() == "python" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Python Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Python Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "python" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/python_discovery_plugin/valid_package/ignore_this/ignoreme.py b/tests/plugins/discovery/python/valid_package/ignore_this/ignoreme.py similarity index 100% rename from tests/plugins/discovery/python_discovery_plugin/valid_package/ignore_this/ignoreme.py rename to tests/plugins/discovery/python/valid_package/ignore_this/ignoreme.py diff --git a/tests/plugins/discovery/python_discovery_plugin/valid_package/oddextensionpy.source b/tests/plugins/discovery/python/valid_package/oddextensionpy.source similarity index 100% rename from tests/plugins/discovery/python_discovery_plugin/valid_package/oddextensionpy.source rename to tests/plugins/discovery/python/valid_package/oddextensionpy.source diff --git a/tests/plugins/discovery/python_discovery_plugin/valid_package/test.py b/tests/plugins/discovery/python/valid_package/test.py similarity index 100% rename from tests/plugins/discovery/python_discovery_plugin/valid_package/test.py rename to tests/plugins/discovery/python/valid_package/test.py diff --git a/tests/plugins/discovery/ros_discovery_plugin/invalid_package_nocmakelists/package.xml b/tests/plugins/discovery/ros/invalid_package_nocmakelists/package.xml similarity index 100% rename from tests/plugins/discovery/ros_discovery_plugin/invalid_package_nocmakelists/package.xml rename to tests/plugins/discovery/ros/invalid_package_nocmakelists/package.xml diff --git a/tests/plugins/discovery/ros_discovery_plugin/invalid_package_nopackagexml/CMakeLists.txt b/tests/plugins/discovery/ros/invalid_package_nopackagexml/CMakeLists.txt similarity index 100% rename from tests/plugins/discovery/ros_discovery_plugin/invalid_package_nopackagexml/CMakeLists.txt rename to tests/plugins/discovery/ros/invalid_package_nopackagexml/CMakeLists.txt diff --git a/tests/plugins/discovery/ros_discovery_plugin/ros2_python_package/package.xml b/tests/plugins/discovery/ros/ros2_python_package/package.xml similarity index 100% rename from tests/plugins/discovery/ros_discovery_plugin/ros2_python_package/package.xml rename to tests/plugins/discovery/ros/ros2_python_package/package.xml diff --git a/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py b/tests/plugins/discovery/ros/test_ros_discovery_plugin.py similarity index 83% rename from tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py rename to tests/plugins/discovery/ros/test_ros_discovery_plugin.py index 19dc5535..52ac4624 100644 --- a/tests/plugins/discovery/ros_discovery_plugin/test_ros_discovery_plugin.py +++ b/tests/plugins/discovery/ros/test_ros_discovery_plugin.py @@ -2,13 +2,15 @@ import contextlib import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.package import Package -from statick_tool.plugins.discovery.ros_discovery_plugin import RosDiscoveryPlugin +from statick_tool.plugins.discovery.ros import RosDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points # From https://stackoverflow.com/questions/2059482/python-temporarily-modify-the-current-processs-environment @@ -43,27 +45,13 @@ def modified_environ(*remove, **update): def test_ros_discovery_plugin_found(): """Test that the plugin manager can find the ROS plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "ros" - assert any( - plugin_info.plugin_object.get_name() == "ros" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named ROS Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "ROS Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "ros" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/ros_discovery_plugin/valid_package/CMakeLists.txt b/tests/plugins/discovery/ros/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/discovery/ros_discovery_plugin/valid_package/CMakeLists.txt rename to tests/plugins/discovery/ros/valid_package/CMakeLists.txt diff --git a/tests/plugins/discovery/ros_discovery_plugin/valid_package/package.xml b/tests/plugins/discovery/ros/valid_package/package.xml similarity index 100% rename from tests/plugins/discovery/ros_discovery_plugin/valid_package/package.xml rename to tests/plugins/discovery/ros/valid_package/package.xml diff --git a/tests/plugins/discovery/shell_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/shell/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/shell/exceptions.yaml diff --git a/tests/plugins/discovery/shell_discovery_plugin/test_shell_discovery_plugin.py b/tests/plugins/discovery/shell/test_shell_discovery_plugin.py similarity index 82% rename from tests/plugins/discovery/shell_discovery_plugin/test_shell_discovery_plugin.py rename to tests/plugins/discovery/shell/test_shell_discovery_plugin.py index 38305986..990e966e 100644 --- a/tests/plugins/discovery/shell_discovery_plugin/test_shell_discovery_plugin.py +++ b/tests/plugins/discovery/shell/test_shell_discovery_plugin.py @@ -2,15 +2,18 @@ import contextlib import os +import sys import pytest -from yapsy.PluginManager import PluginManager -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.shell_discovery_plugin import ShellDiscoveryPlugin +from statick_tool.plugins.discovery.shell import ShellDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points # From https://stackoverflow.com/questions/2059482/shell-temporarily-modify-the-current-processs-environment @@ -45,27 +48,13 @@ def modified_environ(*remove, **update): def test_shell_discovery_plugin_found(): """Test that the plugin manager finds the Shell discovery plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "shell" - assert any( - plugin_info.plugin_object.get_name() == "shell" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Shell Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Shell Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "shell" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/ignore_this/ignoreme.bash b/tests/plugins/discovery/shell/valid_package/ignore_this/ignoreme.bash similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/ignore_this/ignoreme.bash rename to tests/plugins/discovery/shell/valid_package/ignore_this/ignoreme.bash diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionbash.source b/tests/plugins/discovery/shell/valid_package/oddextensionbash.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionbash.source rename to tests/plugins/discovery/shell/valid_package/oddextensionbash.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensioncsh.source b/tests/plugins/discovery/shell/valid_package/oddextensioncsh.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensioncsh.source rename to tests/plugins/discovery/shell/valid_package/oddextensioncsh.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensiondash.source b/tests/plugins/discovery/shell/valid_package/oddextensiondash.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensiondash.source rename to tests/plugins/discovery/shell/valid_package/oddextensiondash.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionksh.source b/tests/plugins/discovery/shell/valid_package/oddextensionksh.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionksh.source rename to tests/plugins/discovery/shell/valid_package/oddextensionksh.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionsh.source b/tests/plugins/discovery/shell/valid_package/oddextensionsh.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionsh.source rename to tests/plugins/discovery/shell/valid_package/oddextensionsh.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionzsh.source b/tests/plugins/discovery/shell/valid_package/oddextensionzsh.source similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/oddextensionzsh.source rename to tests/plugins/discovery/shell/valid_package/oddextensionzsh.source diff --git a/tests/plugins/discovery/shell_discovery_plugin/valid_package/test.sh b/tests/plugins/discovery/shell/valid_package/test.sh similarity index 100% rename from tests/plugins/discovery/shell_discovery_plugin/valid_package/test.sh rename to tests/plugins/discovery/shell/valid_package/test.sh diff --git a/tests/plugins/discovery/xml_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/xml/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/xml_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/xml/exceptions.yaml diff --git a/tests/plugins/discovery/xml_discovery_plugin/invalid_package/test.xmla b/tests/plugins/discovery/xml/invalid_package/test.xmla similarity index 100% rename from tests/plugins/discovery/xml_discovery_plugin/invalid_package/test.xmla rename to tests/plugins/discovery/xml/invalid_package/test.xmla diff --git a/tests/plugins/discovery/xml_discovery_plugin/test_xml_discovery_plugin.py b/tests/plugins/discovery/xml/test_xml_discovery_plugin.py similarity index 66% rename from tests/plugins/discovery/xml_discovery_plugin/test_xml_discovery_plugin.py rename to tests/plugins/discovery/xml/test_xml_discovery_plugin.py index c968e022..0baa8148 100644 --- a/tests/plugins/discovery/xml_discovery_plugin/test_xml_discovery_plugin.py +++ b/tests/plugins/discovery/xml/test_xml_discovery_plugin.py @@ -1,39 +1,27 @@ """Unit tests for the XML discovery plugin.""" import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.xml_discovery_plugin import XMLDiscoveryPlugin +from statick_tool.plugins.discovery.xml import XMLDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_xml_discovery_plugin_found(): """Test that the XML discovery plugin is detected by the plugin system.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "xml" - assert any( - plugin_info.plugin_object.get_name() == "xml" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named XML Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "XML Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "xml" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/xml_discovery_plugin/valid_package/ignore_this/ignoreme.xml b/tests/plugins/discovery/xml/valid_package/ignore_this/ignoreme.xml similarity index 100% rename from tests/plugins/discovery/xml_discovery_plugin/valid_package/ignore_this/ignoreme.xml rename to tests/plugins/discovery/xml/valid_package/ignore_this/ignoreme.xml diff --git a/tests/plugins/discovery/xml_discovery_plugin/valid_package/test.launch b/tests/plugins/discovery/xml/valid_package/test.launch similarity index 100% rename from tests/plugins/discovery/xml_discovery_plugin/valid_package/test.launch rename to tests/plugins/discovery/xml/valid_package/test.launch diff --git a/tests/plugins/discovery/xml_discovery_plugin/valid_package/test.xml b/tests/plugins/discovery/xml/valid_package/test.xml similarity index 100% rename from tests/plugins/discovery/xml_discovery_plugin/valid_package/test.xml rename to tests/plugins/discovery/xml/valid_package/test.xml diff --git a/tests/plugins/discovery/yaml_discovery_plugin/exceptions.yaml b/tests/plugins/discovery/yaml/exceptions.yaml similarity index 100% rename from tests/plugins/discovery/yaml_discovery_plugin/exceptions.yaml rename to tests/plugins/discovery/yaml/exceptions.yaml diff --git a/tests/plugins/discovery/yaml_discovery_plugin/invalid_package/test.yamllint b/tests/plugins/discovery/yaml/invalid_package/test.yamllint similarity index 100% rename from tests/plugins/discovery/yaml_discovery_plugin/invalid_package/test.yamllint rename to tests/plugins/discovery/yaml/invalid_package/test.yamllint diff --git a/tests/plugins/discovery/yaml_discovery_plugin/test_yaml_discovery_plugin.py b/tests/plugins/discovery/yaml/test_yaml_discovery_plugin.py similarity index 66% rename from tests/plugins/discovery/yaml_discovery_plugin/test_yaml_discovery_plugin.py rename to tests/plugins/discovery/yaml/test_yaml_discovery_plugin.py index 51f6fa27..6f332dbc 100644 --- a/tests/plugins/discovery/yaml_discovery_plugin/test_yaml_discovery_plugin.py +++ b/tests/plugins/discovery/yaml/test_yaml_discovery_plugin.py @@ -1,39 +1,27 @@ """Unit tests for the YAML discovery plugin.""" import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.exceptions import Exceptions from statick_tool.package import Package -from statick_tool.plugins.discovery.yaml_discovery_plugin import YAMLDiscoveryPlugin +from statick_tool.plugins.discovery.yaml import YAMLDiscoveryPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_yaml_discovery_plugin_found(): """Test that the YAML discovery plugin is detected by the plugin system.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "yaml" - assert any( - plugin_info.plugin_object.get_name() == "yaml" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named YAML Discovery Plugin + discovery_plugins = {} + plugins = entry_points(group="statick_tool.plugins.discovery") + for plugin_type in plugins: + plugin = plugin_type.load() + discovery_plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "YAML Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") + plugin.get_name() == "yaml" for _, plugin in list(discovery_plugins.items()) ) diff --git a/tests/plugins/discovery/yaml_discovery_plugin/valid_package/ignore_this/ignoreme.yaml b/tests/plugins/discovery/yaml/valid_package/ignore_this/ignoreme.yaml similarity index 100% rename from tests/plugins/discovery/yaml_discovery_plugin/valid_package/ignore_this/ignoreme.yaml rename to tests/plugins/discovery/yaml/valid_package/ignore_this/ignoreme.yaml diff --git a/tests/plugins/discovery/yaml_discovery_plugin/valid_package/test.yaml b/tests/plugins/discovery/yaml/valid_package/test.yaml similarity index 100% rename from tests/plugins/discovery/yaml_discovery_plugin/valid_package/test.yaml rename to tests/plugins/discovery/yaml/valid_package/test.yaml diff --git a/tests/plugins/discovery/yaml_discovery_plugin/valid_package/test.yml b/tests/plugins/discovery/yaml/valid_package/test.yml similarity index 100% rename from tests/plugins/discovery/yaml_discovery_plugin/valid_package/test.yml rename to tests/plugins/discovery/yaml/valid_package/test.yml diff --git a/tests/plugins/reporting/code_climate_reporting_plugin/config/rsc/config-gitlab.yaml b/tests/plugins/reporting/code_climate/config/rsc/config-gitlab.yaml similarity index 100% rename from tests/plugins/reporting/code_climate_reporting_plugin/config/rsc/config-gitlab.yaml rename to tests/plugins/reporting/code_climate/config/rsc/config-gitlab.yaml diff --git a/tests/plugins/reporting/code_climate_reporting_plugin/config/rsc/config.yaml b/tests/plugins/reporting/code_climate/config/rsc/config.yaml similarity index 100% rename from tests/plugins/reporting/code_climate_reporting_plugin/config/rsc/config.yaml rename to tests/plugins/reporting/code_climate/config/rsc/config.yaml diff --git a/tests/plugins/reporting/code_climate_reporting_plugin/test_code_climate_reporting_plugin.py b/tests/plugins/reporting/code_climate/test_code_climate_reporting_plugin.py similarity index 86% rename from tests/plugins/reporting/code_climate_reporting_plugin/test_code_climate_reporting_plugin.py rename to tests/plugins/reporting/code_climate/test_code_climate_reporting_plugin.py index 3d02d51e..5343cfeb 100644 --- a/tests/plugins/reporting/code_climate_reporting_plugin/test_code_climate_reporting_plugin.py +++ b/tests/plugins/reporting/code_climate/test_code_climate_reporting_plugin.py @@ -3,26 +3,21 @@ import argparse import json import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool from statick_tool.config import Config from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.reporting.code_climate_reporting_plugin import ( - CodeClimateReportingPlugin, -) -from statick_tool.reporting_plugin import ReportingPlugin +from statick_tool.plugins.reporting.code_climate import CodeClimateReportingPlugin from statick_tool.resources import Resources -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory def setup_code_climate_reporting_plugin( @@ -51,27 +46,13 @@ def setup_code_climate_reporting_plugin( def test_code_climate_reporting_plugin_found(): """Test that the plugin manager finds the plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "code_climate" - assert any( - plugin_info.plugin_object.get_name() == "code_climate" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - # While we're at it, verify that a plugin is named Code Climate Discovery Plugin + plugins = {} + reporting_plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in reporting_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Code Climate Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") + plugin.get_name() == "code_climate" for _, plugin in list(plugins.items()) ) diff --git a/tests/plugins/reporting/do_nothing/test_do_nothing_reporting_plugin.py b/tests/plugins/reporting/do_nothing/test_do_nothing_reporting_plugin.py new file mode 100644 index 00000000..2aa5b6c6 --- /dev/null +++ b/tests/plugins/reporting/do_nothing/test_do_nothing_reporting_plugin.py @@ -0,0 +1,42 @@ +"""Unit tests for the do nothing reporting plugin.""" +import os +import sys + +from statick_tool.issue import Issue +from statick_tool.package import Package +from statick_tool.plugins.reporting.do_nothing import DoNothingReportingPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + + +def test_do_nothing_reporting_plugin_found(): + """Test that the plugin manager finds the do nothing reporting plugin.""" + plugins = {} + reporting_plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in reporting_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() + assert any( + plugin.get_name() == "do_nothing" for _, plugin in list(plugins.items()) + ) + + +def test_do_nothing_reporting_plugin_report_cert(capsys): + """Test the output of the do nothing plugin.""" + dnrp = DoNothingReportingPlugin() + package = Package( + "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") + ) + issues = { + "tool_a": [ + Issue("test.txt", 1, "tool_a", "type", 1, "This is a test", "MEM50-CPP") + ] + } + + dnrp.report(package, issues, "level") + captured = capsys.readouterr() + output = captured.out.splitlines() + assert not output diff --git a/tests/plugins/reporting/do_nothing_reporting_plugin/test_do_nothing_reporting_plugin.py b/tests/plugins/reporting/do_nothing_reporting_plugin/test_do_nothing_reporting_plugin.py deleted file mode 100644 index cc487e0d..00000000 --- a/tests/plugins/reporting/do_nothing_reporting_plugin/test_do_nothing_reporting_plugin.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Unit tests for the do nothing reporting plugin.""" - -import os - -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.issue import Issue -from statick_tool.package import Package -from statick_tool.plugins.reporting.do_nothing_reporting_plugin import ( - DoNothingReportingPlugin, -) -from statick_tool.reporting_plugin import ReportingPlugin - - -def test_do_nothing_reporting_plugin_found(): - """Test that the plugin manager finds the do nothing reporting plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "c" - assert any( - plugin_info.plugin_object.get_name() == "do_nothing" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - # While we're at it, verify that a plugin is named C Discovery Plugin - assert any( - plugin_info.name == "Do Nothing Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - - -def test_do_nothing_reporting_plugin_report_cert(capsys): - """Test the output of the do nothing plugin.""" - dnrp = DoNothingReportingPlugin() - package = Package( - "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") - ) - issues = { - "tool_a": [ - Issue("test.txt", 1, "tool_a", "type", 1, "This is a test", "MEM50-CPP") - ] - } - - dnrp.report(package, issues, "level") - captured = capsys.readouterr() - output = captured.out.splitlines() - assert not output diff --git a/tests/plugins/reporting/json_reporting_plugin/config/rsc/config.yaml b/tests/plugins/reporting/json/config/rsc/config.yaml similarity index 100% rename from tests/plugins/reporting/json_reporting_plugin/config/rsc/config.yaml rename to tests/plugins/reporting/json/config/rsc/config.yaml diff --git a/tests/plugins/reporting/json_reporting_plugin/test_json_reporting_plugin.py b/tests/plugins/reporting/json/test_json_reporting_plugin.py similarity index 74% rename from tests/plugins/reporting/json_reporting_plugin/test_json_reporting_plugin.py rename to tests/plugins/reporting/json/test_json_reporting_plugin.py index ea50fd1c..e5b1b438 100644 --- a/tests/plugins/reporting/json_reporting_plugin/test_json_reporting_plugin.py +++ b/tests/plugins/reporting/json/test_json_reporting_plugin.py @@ -2,24 +2,21 @@ import argparse import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool from statick_tool.config import Config from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.reporting.json_reporting_plugin import JsonReportingPlugin -from statick_tool.reporting_plugin import ReportingPlugin +from statick_tool.plugins.reporting.json import JsonReportingPlugin from statick_tool.resources import Resources -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory def setup_json_reporting_plugin(file_path, use_plugin_context=True): @@ -40,27 +37,13 @@ def setup_json_reporting_plugin(file_path, use_plugin_context=True): def test_json_reporting_plugin_found(): """Test that the plugin manager finds the plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "c" - assert any( - plugin_info.plugin_object.get_name() == "json" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - # While we're at it, verify that a plugin is named C Discovery Plugin + plugins = {} + reporting_plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in reporting_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "JSON Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") + plugin.get_name() == "json" for _, plugin in list(plugins.items()) ) diff --git a/tests/plugins/reporting/print_to_console_reporting_plugin/test_print_to_console_reporting_plugin.py b/tests/plugins/reporting/print_to_console/test_print_to_console_reporting_plugin.py similarity index 61% rename from tests/plugins/reporting/print_to_console_reporting_plugin/test_print_to_console_reporting_plugin.py rename to tests/plugins/reporting/print_to_console/test_print_to_console_reporting_plugin.py index d24dbe9b..a476b895 100644 --- a/tests/plugins/reporting/print_to_console_reporting_plugin/test_print_to_console_reporting_plugin.py +++ b/tests/plugins/reporting/print_to_console/test_print_to_console_reporting_plugin.py @@ -1,41 +1,29 @@ """Unit tests for the console reporting plugin.""" import os +import sys -from yapsy.PluginManager import PluginManager - -import statick_tool from statick_tool.issue import Issue from statick_tool.package import Package -from statick_tool.plugins.reporting.print_to_console_reporting_plugin import ( +from statick_tool.plugins.reporting.print_to_console import ( PrintToConsoleReportingPlugin, ) -from statick_tool.reporting_plugin import ReportingPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def test_console_reporting_plugin_found(): """Test that the plugin manager finds the console reporting plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "c" - assert any( - plugin_info.plugin_object.get_name() == "print_to_console" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - # While we're at it, verify that a plugin is named C Discovery Plugin + plugins = {} + reporting_plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in reporting_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Print To Console Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") + plugin.get_name() == "print_to_console" for _, plugin in list(plugins.items()) ) diff --git a/tests/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin/test_write_jenkins_warnings_ng_reporting_plugin.py b/tests/plugins/reporting/write_jenkins_warnings_ng/test_write_jenkins_warnings_ng_reporting_plugin.py similarity index 83% rename from tests/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin/test_write_jenkins_warnings_ng_reporting_plugin.py rename to tests/plugins/reporting/write_jenkins_warnings_ng/test_write_jenkins_warnings_ng_reporting_plugin.py index 8efb4294..0aa91609 100644 --- a/tests/plugins/reporting/write_jenkins_warnings_ng_reporting_plugin/test_write_jenkins_warnings_ng_reporting_plugin.py +++ b/tests/plugins/reporting/write_jenkins_warnings_ng/test_write_jenkins_warnings_ng_reporting_plugin.py @@ -4,26 +4,24 @@ import json import os import re - -from yapsy.PluginManager import PluginManager +import sys import statick_tool from statick_tool.config import Config from statick_tool.issue import Issue from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.reporting.write_jenkins_warnings_ng_reporting_plugin import ( +from statick_tool.plugins.reporting.write_jenkins_warnings_ng import ( WriteJenkinsWarningsNGReportingPlugin, ) -from statick_tool.reporting_plugin import ReportingPlugin from statick_tool.resources import Resources -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory output_regex = r"^{\"(.*)\": \"(.*)\", \"(.*)\": \"(.*)\", \"(.*)\": (\d+), \"(.*)\": \"(.*)\", \"(.*)\": \"(.*)\", \"(.*)\": \"(.*)\"}" @@ -50,27 +48,13 @@ def setup_write_jenkins_warnings_ng_reporting_plugin( def test_write_jenkins_warnings_ng_reporting_plugin_found(): """Test that the plugin manager finds the file writing plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "c" - assert any( - plugin_info.plugin_object.get_name() == "write_jenkins_warnings_ng" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - # While we're at it, verify that a plugin is named C Discovery Plugin + plugins = {} + reporting_plugins = entry_points(group="statick_tool.plugins.reporting") + for plugin_type in reporting_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Write Jenkins Warnings NG Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") + plugin.get_name() == "write_jenkins_warnings_ng" for _, plugin in list(plugins.items()) ) diff --git a/tests/plugins/tool/bandit_tool_plugin/test_bandit_tool_plugin.py b/tests/plugins/tool/bandit/test_bandit_tool_plugin.py similarity index 83% rename from tests/plugins/tool/bandit_tool_plugin/test_bandit_tool_plugin.py rename to tests/plugins/tool/bandit/test_bandit_tool_plugin.py index a152b149..b6ae67fc 100644 --- a/tests/plugins/tool/bandit_tool_plugin/test_bandit_tool_plugin.py +++ b/tests/plugins/tool/bandit/test_bandit_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.bandit_tool_plugin import BanditToolPlugin +from statick_tool.plugins.tool.bandit import BanditToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_bandit_tool_plugin(binary=None): @@ -39,27 +43,13 @@ def setup_bandit_tool_plugin(binary=None): def test_bandit_tool_plugin_found(): """Test that the bandit tool plugin is detected by the plugin system.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "bandit" - assert any( - plugin_info.plugin_object.get_name() == "bandit" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Bandit Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Bandit Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "bandit" for _, plugin in list(plugins.items()) ) @@ -119,7 +109,7 @@ def test_bandit_tool_plugin_scan_wrong_binary(): assert issues is None -@mock.patch("statick_tool.plugins.tool.bandit_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.bandit.subprocess.check_output") def test_bandit_tool_plugin_scan_empty_oserror(mock_subprocess_check_output): """Test what happens an OSError is hit (such as if bandit doesn't exist). @@ -137,7 +127,7 @@ def test_bandit_tool_plugin_scan_empty_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.bandit_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.bandit.subprocess.check_output") def test_bandit_tool_plugin_scan_empty_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is hit (such as if bandit encounters an error). diff --git a/tests/plugins/tool/bandit_tool_plugin/valid_package/b404.py b/tests/plugins/tool/bandit/valid_package/b404.py similarity index 100% rename from tests/plugins/tool/bandit_tool_plugin/valid_package/b404.py rename to tests/plugins/tool/bandit/valid_package/b404.py diff --git a/tests/plugins/tool/black_tool_plugin/test_black_tool_plugin.py b/tests/plugins/tool/black/test_black_tool_plugin.py similarity index 81% rename from tests/plugins/tool/black_tool_plugin/test_black_tool_plugin.py rename to tests/plugins/tool/black/test_black_tool_plugin.py index a475e59c..b2cb963f 100644 --- a/tests/plugins/tool/black_tool_plugin/test_black_tool_plugin.py +++ b/tests/plugins/tool/black/test_black_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.black_tool_plugin import BlackToolPlugin +from statick_tool.plugins.tool.black import BlackToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_black_tool_plugin(): @@ -34,27 +38,13 @@ def setup_black_tool_plugin(): def test_black_tool_plugin_found(): """Test that the plugin manager can find the PyCodeStyle plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "black" - assert any( - plugin_info.plugin_object.get_name() == "black" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Pycodestyle Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Pycodestyle Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "black" for _, plugin in list(plugins.items()) ) @@ -115,7 +105,7 @@ def test_black_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.black_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.black.subprocess.check_output") def test_black_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means black doesn't exist). @@ -133,7 +123,7 @@ def test_black_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.black_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.black.subprocess.check_output") def test_black_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means black hit an error). @@ -154,7 +144,7 @@ def test_black_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output) assert issues is None -@mock.patch("statick_tool.plugins.tool.black_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.black.subprocess.check_output") def test_black_tool_plugin_scan_internal_error(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised due to an internal error. diff --git a/tests/plugins/tool/black_tool_plugin/valid_package/format_errors.py b/tests/plugins/tool/black/valid_package/format_errors.py similarity index 100% rename from tests/plugins/tool/black_tool_plugin/valid_package/format_errors.py rename to tests/plugins/tool/black/valid_package/format_errors.py diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/c0x_package/CMakeLists.txt b/tests/plugins/tool/catkin-lint/c0x_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/c0x_package/CMakeLists.txt rename to tests/plugins/tool/catkin-lint/c0x_package/CMakeLists.txt diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/c0x_package/package.xml b/tests/plugins/tool/catkin-lint/c0x_package/package.xml similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/c0x_package/package.xml rename to tests/plugins/tool/catkin-lint/c0x_package/package.xml diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/c11_package/CMakeLists.txt b/tests/plugins/tool/catkin-lint/c11_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/c11_package/CMakeLists.txt rename to tests/plugins/tool/catkin-lint/c11_package/CMakeLists.txt diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/c11_package/package.xml b/tests/plugins/tool/catkin-lint/c11_package/package.xml similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/c11_package/package.xml rename to tests/plugins/tool/catkin-lint/c11_package/package.xml diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/cmake_flags/CMakeLists.txt b/tests/plugins/tool/catkin-lint/cmake_flags/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/cmake_flags/CMakeLists.txt rename to tests/plugins/tool/catkin-lint/cmake_flags/CMakeLists.txt diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/gnu99_package/CMakeLists.txt b/tests/plugins/tool/catkin-lint/gnu99_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/gnu99_package/CMakeLists.txt rename to tests/plugins/tool/catkin-lint/gnu99_package/CMakeLists.txt diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/gnu99_package/package.xml b/tests/plugins/tool/catkin-lint/gnu99_package/package.xml similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/gnu99_package/package.xml rename to tests/plugins/tool/catkin-lint/gnu99_package/package.xml diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/test_catkin-lint_tool_plugin.py b/tests/plugins/tool/catkin-lint/test_catkin-lint_tool_plugin.py similarity index 89% rename from tests/plugins/tool/catkin-lint_tool_plugin/test_catkin-lint_tool_plugin.py rename to tests/plugins/tool/catkin-lint/test_catkin-lint_tool_plugin.py index e495e8a2..03028f4c 100644 --- a/tests/plugins/tool/catkin-lint_tool_plugin/test_catkin-lint_tool_plugin.py +++ b/tests/plugins/tool/catkin-lint/test_catkin-lint_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.catkin_lint_tool_plugin import CatkinLintToolPlugin +from statick_tool.plugins.tool.catkin_lint import CatkinLintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_catkin_lint_tool_plugin(): @@ -34,27 +38,13 @@ def setup_catkin_lint_tool_plugin(): def test_catkin_lint_tool_plugin_found(): """Test that the plugin manager finds the CatkinLint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "catkin_lint" - assert any( - plugin_info.plugin_object.get_name() == "catkin_lint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Yamllint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Catkin Lint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "catkin_lint" for _, plugin in list(plugins.items()) ) @@ -258,7 +248,7 @@ def test_catkin_lint_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.catkin_lint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.catkin_lint.subprocess.check_output") def test_catkin_lint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means catkin_lint hit an error). @@ -283,7 +273,7 @@ def test_catkin_lint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_o assert issues is None -@mock.patch("statick_tool.plugins.tool.catkin_lint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.catkin_lint.subprocess.check_output") def test_catkin_lint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means catkin_lint doesn't exist). diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/catkin-lint/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/catkin-lint/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/catkin-lint_tool_plugin/valid_package/package.xml b/tests/plugins/tool/catkin-lint/valid_package/package.xml similarity index 100% rename from tests/plugins/tool/catkin-lint_tool_plugin/valid_package/package.xml rename to tests/plugins/tool/catkin-lint/valid_package/package.xml diff --git a/tests/plugins/tool/cccc_tool_plugin/cccc.opt b/tests/plugins/tool/cccc/cccc.opt similarity index 100% rename from tests/plugins/tool/cccc_tool_plugin/cccc.opt rename to tests/plugins/tool/cccc/cccc.opt diff --git a/tests/plugins/tool/cccc_tool_plugin/test_cccc_tool_plugin.py b/tests/plugins/tool/cccc/test_cccc_tool_plugin.py similarity index 89% rename from tests/plugins/tool/cccc_tool_plugin/test_cccc_tool_plugin.py rename to tests/plugins/tool/cccc/test_cccc_tool_plugin.py index 8e5aded0..0f596250 100644 --- a/tests/plugins/tool/cccc_tool_plugin/test_cccc_tool_plugin.py +++ b/tests/plugins/tool/cccc/test_cccc_tool_plugin.py @@ -1,24 +1,27 @@ """Unit tests for the CCCC tool module.""" - from __future__ import print_function import argparse import os import shutil import subprocess +import sys import mock import pytest import xmltodict -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.cccc_tool_plugin import CCCCToolPlugin +from statick_tool.plugins.tool.cccc import CCCCToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_cccc_tool_plugin(use_plugin_context=True, binary=None, cccc_config=None): @@ -45,27 +48,13 @@ def setup_cccc_tool_plugin(use_plugin_context=True, binary=None, cccc_config=Non def test_cccc_tool_plugin_found(): """Test that the CCCC tool plugin is detected by the plugin system.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "cccc" - assert any( - plugin_info.plugin_object.get_name() == "cccc" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named CCCC Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "CCCC Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "cccc" for _, plugin in list(plugins.items()) ) @@ -245,7 +234,7 @@ def test_cccc_tool_plugin_parse_config_none(): assert not config -@mock.patch("statick_tool.plugins.tool.cccc_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cccc.subprocess.check_output") def test_cccc_tool_plugin_scan_empty_oserror(mock_subprocess_check_output): """Test what happens an OSError is hit (such as if cccc doesn't exist) @@ -263,7 +252,7 @@ def test_cccc_tool_plugin_scan_empty_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.cccc_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cccc.subprocess.check_output") def test_cccc_tool_plugin_scan_empty_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is hit (such as if cccc encounters an error). @@ -292,7 +281,7 @@ def test_cccc_tool_plugin_scan_empty_calledprocesserror(mock_subprocess_check_ou assert not issues -@mock.patch("statick_tool.plugins.tool.cccc_tool_plugin.xmltodict.parse") +@mock.patch("statick_tool.plugins.tool.cccc.xmltodict.parse") def test_cccc_tool_plugin_scan_filenotfound(mock_xmltodict_parse): """Test what happens when a FileNotFoundError is hit (such as if cccc has no output for a file). diff --git a/tests/plugins/tool/cccc_tool_plugin/valid_package/cccc-missing-names.xml b/tests/plugins/tool/cccc/valid_package/cccc-missing-names.xml similarity index 100% rename from tests/plugins/tool/cccc_tool_plugin/valid_package/cccc-missing-names.xml rename to tests/plugins/tool/cccc/valid_package/cccc-missing-names.xml diff --git a/tests/plugins/tool/cccc_tool_plugin/valid_package/cccc.xml b/tests/plugins/tool/cccc/valid_package/cccc.xml similarity index 100% rename from tests/plugins/tool/cccc_tool_plugin/valid_package/cccc.xml rename to tests/plugins/tool/cccc/valid_package/cccc.xml diff --git a/tests/plugins/tool/cccc_tool_plugin/valid_package/example.cpp b/tests/plugins/tool/cccc/valid_package/example.cpp similarity index 100% rename from tests/plugins/tool/cccc_tool_plugin/valid_package/example.cpp rename to tests/plugins/tool/cccc/valid_package/example.cpp diff --git a/tests/plugins/tool/clang-format_tool_plugin/different-clang-format.cfg b/tests/plugins/tool/clang-format/different-clang-format.cfg similarity index 100% rename from tests/plugins/tool/clang-format_tool_plugin/different-clang-format.cfg rename to tests/plugins/tool/clang-format/different-clang-format.cfg diff --git a/tests/plugins/tool/clang-format_tool_plugin/test_clang-format_tool_plugin.py b/tests/plugins/tool/clang-format/test_clang-format_tool_plugin.py similarity index 93% rename from tests/plugins/tool/clang-format_tool_plugin/test_clang-format_tool_plugin.py rename to tests/plugins/tool/clang-format/test_clang-format_tool_plugin.py index 4cc2617a..7d215f61 100644 --- a/tests/plugins/tool/clang-format_tool_plugin/test_clang-format_tool_plugin.py +++ b/tests/plugins/tool/clang-format/test_clang-format_tool_plugin.py @@ -4,20 +4,24 @@ import os import shutil import subprocess +import sys from xml.etree import ElementTree import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext +from statick_tool.plugins.tool.clang_format import ClangFormatToolPlugin from statick_tool.plugins.tool.clang_format_parser import ClangFormatXMLParser -from statick_tool.plugins.tool.clang_format_tool_plugin import ClangFormatToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_clang_format_tool_plugin( @@ -68,27 +72,13 @@ def setup_clang_format_tool_plugin( def test_clang_format_tool_plugin_found(): """Test that the plugin manager can find the clang-format plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "clang_format" - assert any( - plugin_info.plugin_object.get_name() == "clang-format" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named clang-format Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "clang-format Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "clang-format" for _, plugin in list(plugins.items()) ) @@ -349,7 +339,7 @@ def test_clang_format_tool_plugin_custom_config_diff(): @mock.patch( - "statick_tool.plugins.tool.clang_format_tool_plugin.subprocess.check_output" + "statick_tool.plugins.tool.clang_format.subprocess.check_output" ) def test_clang_format_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means clang-format @@ -385,7 +375,7 @@ def test_clang_format_tool_plugin_scan_calledprocesserror(mock_subprocess_check_ os.remove(os.path.join(os.path.expanduser("~"), "_clang-format")) -@mock.patch("statick_tool.plugins.tool.clang_format_tool_plugin.open") +@mock.patch("statick_tool.plugins.tool.clang_format.open") def test_clang_format_tool_plugin_scan_oserror_open(mock_open): """Test what happens when OSError is raised (usually means clang-format configuration is missing). @@ -412,7 +402,7 @@ def test_clang_format_tool_plugin_scan_oserror_open(mock_open): @mock.patch( - "statick_tool.plugins.tool.clang_format_tool_plugin.subprocess.check_output" + "statick_tool.plugins.tool.clang_format.subprocess.check_output" ) def test_clang_format_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means clang-format doesn't @@ -448,7 +438,7 @@ def test_clang_format_tool_plugin_scan_oserror(mock_subprocess_check_output): os.remove(os.path.join(os.path.expanduser("~"), "_clang-format")) -@mock.patch("statick_tool.plugins.tool.clang_format_tool_plugin.open") +@mock.patch("statick_tool.plugins.tool.clang_format.open") def test_clang_format_tool_plugin_check_configuration_oserror(mock_open): """Test what happens when an OSError is raised (usually means diff files don't exist). diff --git a/tests/plugins/tool/clang-format_tool_plugin/valid_package/indents.c b/tests/plugins/tool/clang-format/valid_package/indents.c similarity index 100% rename from tests/plugins/tool/clang-format_tool_plugin/valid_package/indents.c rename to tests/plugins/tool/clang-format/valid_package/indents.c diff --git a/tests/plugins/tool/clang-format_tool_plugin/valid_package/indents.h b/tests/plugins/tool/clang-format/valid_package/indents.h similarity index 100% rename from tests/plugins/tool/clang-format_tool_plugin/valid_package/indents.h rename to tests/plugins/tool/clang-format/valid_package/indents.h diff --git a/tests/plugins/tool/clang-tidy_tool_plugin/test_clang-tidy_tool_plugin.py b/tests/plugins/tool/clang-tidy/test_clang-tidy_tool_plugin.py similarity index 90% rename from tests/plugins/tool/clang-tidy_tool_plugin/test_clang-tidy_tool_plugin.py rename to tests/plugins/tool/clang-tidy/test_clang-tidy_tool_plugin.py index 0de3c10b..f6483461 100644 --- a/tests/plugins/tool/clang-tidy_tool_plugin/test_clang-tidy_tool_plugin.py +++ b/tests/plugins/tool/clang-tidy/test_clang-tidy_tool_plugin.py @@ -7,22 +7,20 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.clang_tidy_tool_plugin import ClangTidyToolPlugin +from statick_tool.plugins.tool.clang_tidy import ClangTidyToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory def setup_clang_tidy_tool_plugin(use_plugin_context=True, binary=None): @@ -49,27 +47,13 @@ def setup_clang_tidy_tool_plugin(use_plugin_context=True, binary=None): def test_clang_tidy_tool_plugin_found(): """Test that the plugin manager can find the clang-tidy plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "clang_tidy" - assert any( - plugin_info.plugin_object.get_name() == "clang-tidy" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named ClangTidy Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "clang-tidy Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "clang-tidy" for _, plugin in list(plugins.items()) ) @@ -289,7 +273,7 @@ def test_clang_tidy_tool_plugin_scan_missing_fields(): assert not issues -@mock.patch("statick_tool.plugins.tool.clang_tidy_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.clang_tidy.subprocess.check_output") def test_clang_tidy_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means clang-tidy doesn't exist). @@ -313,7 +297,7 @@ def test_clang_tidy_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.clang_tidy_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.clang_tidy.subprocess.check_output") def test_clang_tidy_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means clang-tidy hit an error). @@ -339,7 +323,7 @@ def test_clang_tidy_tool_plugin_scan_calledprocesserror(mock_subprocess_check_ou assert issues is None -@mock.patch("statick_tool.plugins.tool.clang_tidy_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.clang_tidy.subprocess.check_output") def test_clang_tidy_tool_plugin_scan_diagnosticerror(mock_subprocess_check_output): """Test that a CalledProcessError is raised when subprocess's output contains 'clang-diagnostic-error'. diff --git a/tests/plugins/tool/clang-tidy_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/clang-tidy/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/clang-tidy_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/clang-tidy/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/clang-tidy_tool_plugin/valid_package/test.c b/tests/plugins/tool/clang-tidy/valid_package/test.c similarity index 100% rename from tests/plugins/tool/clang-tidy_tool_plugin/valid_package/test.c rename to tests/plugins/tool/clang-tidy/valid_package/test.c diff --git a/tests/plugins/tool/cmakelint_tool_plugin/cmake_ext_package/CMakeLists.txt b/tests/plugins/tool/cmakelint/cmake_ext_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/cmakelint_tool_plugin/cmake_ext_package/CMakeLists.txt rename to tests/plugins/tool/cmakelint/cmake_ext_package/CMakeLists.txt diff --git a/tests/plugins/tool/cmakelint_tool_plugin/cmake_ext_package/CMakeModules/FindCython.cmake b/tests/plugins/tool/cmakelint/cmake_ext_package/CMakeModules/FindCython.cmake similarity index 100% rename from tests/plugins/tool/cmakelint_tool_plugin/cmake_ext_package/CMakeModules/FindCython.cmake rename to tests/plugins/tool/cmakelint/cmake_ext_package/CMakeModules/FindCython.cmake diff --git a/tests/plugins/tool/cmakelint_tool_plugin/test_cmakelint_tool_plugin.py b/tests/plugins/tool/cmakelint/test_cmakelint_tool_plugin.py similarity index 82% rename from tests/plugins/tool/cmakelint_tool_plugin/test_cmakelint_tool_plugin.py rename to tests/plugins/tool/cmakelint/test_cmakelint_tool_plugin.py index 5bf0b4d2..411e81ec 100644 --- a/tests/plugins/tool/cmakelint_tool_plugin/test_cmakelint_tool_plugin.py +++ b/tests/plugins/tool/cmakelint/test_cmakelint_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.cmakelint_tool_plugin import CMakelintToolPlugin +from statick_tool.plugins.tool.cmakelint import CMakelintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_cmakelint_tool_plugin(): @@ -33,27 +37,13 @@ def setup_cmakelint_tool_plugin(): def test_cmakelint_tool_plugin_found(): """Test that the plugin manager finds the cmakelint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "cmakelint" - assert any( - plugin_info.plugin_object.get_name() == "cmakelint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named cmakelint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "cmakelint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "cmakelint" for _, plugin in list(plugins.items()) ) @@ -139,7 +129,7 @@ def test_cmakelint_tool_plugin_nonexistent_file(): assert not issues -@mock.patch("statick_tool.plugins.tool.cmakelint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cmakelint.subprocess.check_output") def test_cmakelint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means cmakelint hit an error). @@ -166,7 +156,7 @@ def test_cmakelint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_out assert issues is None -@mock.patch("statick_tool.plugins.tool.cmakelint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cmakelint.subprocess.check_output") def test_cmakelint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means cmakelint doesn't exist). diff --git a/tests/plugins/tool/cmakelint_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/cmakelint/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/cmakelint_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/cmakelint/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/cppcheck_tool_plugin/test_cppcheck_tool_plugin.py b/tests/plugins/tool/cppcheck/test_cppcheck_tool_plugin.py similarity index 88% rename from tests/plugins/tool/cppcheck_tool_plugin/test_cppcheck_tool_plugin.py rename to tests/plugins/tool/cppcheck/test_cppcheck_tool_plugin.py index d11c587b..c681075a 100644 --- a/tests/plugins/tool/cppcheck_tool_plugin/test_cppcheck_tool_plugin.py +++ b/tests/plugins/tool/cppcheck/test_cppcheck_tool_plugin.py @@ -3,18 +3,23 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager +from packaging.version import Version import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.cppcheck_tool_plugin import CppcheckToolPlugin +from statick_tool.plugins.tool.cppcheck import CppcheckToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_cppcheck_tool_plugin(use_plugin_context=True, binary=None): @@ -41,27 +46,13 @@ def setup_cppcheck_tool_plugin(use_plugin_context=True, binary=None): def test_cppcheck_tool_plugin_found(): """Test that the plugin manager can find the cppcheck plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "cppcheck" + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.plugin_object.get_name() == "cppcheck" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Cppcheck Tool Plugin - assert any( - plugin_info.name == "Cppcheck Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "cppcheck" for _, plugin in list(plugins.items()) ) @@ -91,7 +82,11 @@ def test_cppcheck_tool_plugin_scan_valid(): ) assert issues[0].line_number == "4" assert issues[0].tool == "cppcheck" - assert issues[0].issue_type == "error/uninitvar" + version = cctp.get_version("cppcheck") + if Version(version) >= Version("2.8"): + assert issues[0].issue_type == "error/legacyUninitvar" + else: + assert issues[0].issue_type == "error/uninitvar" assert issues[0].severity == "5" assert issues[0].message == "Uninitialized variable: si" @@ -200,7 +195,7 @@ def test_cppcheck_tool_plugin_scan_missing_fields(): assert not issues -@mock.patch("statick_tool.plugins.tool.cppcheck_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cppcheck.subprocess.check_output") def test_cppcheck_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means cppcheck doesn't exist). @@ -234,7 +229,7 @@ def calledprocesserror_helper(*popenargs, **kwargs): raise subprocess.CalledProcessError(2, "", output="mocked error") -@mock.patch("statick_tool.plugins.tool.cppcheck_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cppcheck.subprocess.check_output") def test_cppcheck_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means cppcheck hit an error). @@ -274,7 +269,7 @@ def test_checkforexceptions_false(): assert not CppcheckToolPlugin.check_for_exceptions(mm) -@mock.patch("statick_tool.plugins.tool.cppcheck_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cppcheck.subprocess.check_output") def test_cppcheck_tool_plugin_version_match(mock_subprocess_check_output): """Test the result of passing a requested version to the plugin when that version isn't available.""" diff --git a/tests/plugins/tool/cppcheck_tool_plugin/valid_package/test.c b/tests/plugins/tool/cppcheck/valid_package/test.c similarity index 100% rename from tests/plugins/tool/cppcheck_tool_plugin/valid_package/test.c rename to tests/plugins/tool/cppcheck/valid_package/test.c diff --git a/tests/plugins/tool/cpplint_tool_plugin/test_cpplint_tool_plugin.py b/tests/plugins/tool/cpplint/test_cpplint_tool_plugin.py similarity index 85% rename from tests/plugins/tool/cpplint_tool_plugin/test_cpplint_tool_plugin.py rename to tests/plugins/tool/cpplint/test_cpplint_tool_plugin.py index 4497957a..add52b4d 100644 --- a/tests/plugins/tool/cpplint_tool_plugin/test_cpplint_tool_plugin.py +++ b/tests/plugins/tool/cpplint/test_cpplint_tool_plugin.py @@ -7,22 +7,20 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.cpplint_tool_plugin import CpplintToolPlugin +from statick_tool.plugins.tool.cpplint import CpplintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory def setup_cpplint_tool_plugin(): @@ -42,27 +40,13 @@ def setup_cpplint_tool_plugin(): def test_cpplint_tool_plugin_found(): """Test that the plugin manager can find the cpplint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "cpplint" - assert any( - plugin_info.plugin_object.get_name() == "cpplint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Cpplint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Cpplint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "cpplint" for _, plugin in list(plugins.items()) ) @@ -181,7 +165,7 @@ def test_cpplint_tool_plugin_scan_missing_fields(): assert not issues -@mock.patch("statick_tool.plugins.tool.cpplint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cpplint.subprocess.check_output") def test_cpplint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means cpplint doesn't exist). @@ -204,7 +188,7 @@ def test_cpplint_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.cpplint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.cpplint.subprocess.check_output") def test_cpplint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means cpplint hit an error). diff --git a/tests/plugins/tool/cpplint_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/cpplint/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/cpplint_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/cpplint/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/cpplint_tool_plugin/valid_package/test.c b/tests/plugins/tool/cpplint/valid_package/test.c similarity index 100% rename from tests/plugins/tool/cpplint_tool_plugin/valid_package/test.c rename to tests/plugins/tool/cpplint/valid_package/test.c diff --git a/tests/plugins/tool/do_nothing_tool_plugin/test_do_nothing_tool_plugin.py b/tests/plugins/tool/do_nothing/test_do_nothing_tool_plugin.py similarity index 59% rename from tests/plugins/tool/do_nothing_tool_plugin/test_do_nothing_tool_plugin.py rename to tests/plugins/tool/do_nothing/test_do_nothing_tool_plugin.py index 71db370b..fa62aed3 100644 --- a/tests/plugins/tool/do_nothing_tool_plugin/test_do_nothing_tool_plugin.py +++ b/tests/plugins/tool/do_nothing/test_do_nothing_tool_plugin.py @@ -1,13 +1,16 @@ """Unit tests for the do nothing tool plugin.""" import os - -from yapsy.PluginManager import PluginManager +import sys import statick_tool from statick_tool.package import Package -from statick_tool.plugins.tool.do_nothing_tool_plugin import DoNothingToolPlugin -from statick_tool.tool_plugin import ToolPlugin +from statick_tool.plugins.tool.do_nothing import DoNothingToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_do_nothing_tool_plugin(): @@ -18,25 +21,13 @@ def setup_do_nothing_tool_plugin(): def test_do_nothing_tool_plugin_found(): """Test that the plugin manager finds the do nothing tool plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - assert any( - plugin_info.plugin_object.get_name() == "do_nothing" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Do Nothing Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "do_nothing" for _, plugin in list(plugins.items()) ) @@ -53,7 +44,7 @@ def test_do_nothing_tool_plugin_process_files(): "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") ) package["python_src"] = [ - os.path.join(os.path.dirname(__file__), "valid_package", "basic.py") + os.path.join(os.path.dirname(__file__), "valid_package", "do_nothing_basic.py") ] output = plugin.process_files(package, "level", package["python_src"], []) assert not output @@ -62,6 +53,6 @@ def test_do_nothing_tool_plugin_process_files(): def test_do_nothing_tool_plugin_parse_output(): """Verify that we can parse the normal output of do_nothing.""" plugin = setup_do_nothing_tool_plugin() - output = "would reformat /home/user/valid_package/basic.py" + output = "would reformat /home/user/valid_package/do_nothing_basic.py" issues = plugin.parse_output([output]) assert not issues diff --git a/tests/plugins/tool/do_nothing_tool_plugin/valid_package/basic.py b/tests/plugins/tool/do_nothing/valid_package/do_nothing_basic.py similarity index 100% rename from tests/plugins/tool/do_nothing_tool_plugin/valid_package/basic.py rename to tests/plugins/tool/do_nothing/valid_package/do_nothing_basic.py diff --git a/tests/plugins/tool/docformatter_tool_plugin/test_docformatter_tool_plugin.py b/tests/plugins/tool/docformatter/test_docformatter_tool_plugin.py similarity index 78% rename from tests/plugins/tool/docformatter_tool_plugin/test_docformatter_tool_plugin.py rename to tests/plugins/tool/docformatter/test_docformatter_tool_plugin.py index e831258b..6c5a25f9 100644 --- a/tests/plugins/tool/docformatter_tool_plugin/test_docformatter_tool_plugin.py +++ b/tests/plugins/tool/docformatter/test_docformatter_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.docformatter_tool_plugin import DocformatterToolPlugin +from statick_tool.plugins.tool.docformatter import DocformatterToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_docformatter_tool_plugin(): @@ -34,27 +38,13 @@ def setup_docformatter_tool_plugin(): def test_docformatter_tool_plugin_found(): """Test that the plugin manager can find the Docformatter plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "docformatter" - assert any( - plugin_info.plugin_object.get_name() == "docformatter" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Docformatter Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Docformatter Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "docformatter" for _, plugin in list(plugins.items()) ) @@ -108,7 +98,7 @@ def test_docformatter_tool_plugin_parse_invalid(): @mock.patch( - "statick_tool.plugins.tool.docformatter_tool_plugin.subprocess.check_output" + "statick_tool.plugins.tool.docformatter.subprocess.check_output" ) def test_docformatter_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means docformatter doesn't @@ -129,7 +119,7 @@ def test_docformatter_tool_plugin_scan_oserror(mock_subprocess_check_output): @mock.patch( - "statick_tool.plugins.tool.docformatter_tool_plugin.subprocess.check_output" + "statick_tool.plugins.tool.docformatter.subprocess.check_output" ) def test_docformatter_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means docformatter diff --git a/tests/plugins/tool/docformatter_tool_plugin/valid_package/wrong.py b/tests/plugins/tool/docformatter/valid_package/wrong.py similarity index 100% rename from tests/plugins/tool/docformatter_tool_plugin/valid_package/wrong.py rename to tests/plugins/tool/docformatter/valid_package/wrong.py diff --git a/tests/plugins/tool/flawfinder_tool_plugin/test_flawfinder_tool_plugin.py b/tests/plugins/tool/flawfinder/test_flawfinder_tool_plugin.py similarity index 80% rename from tests/plugins/tool/flawfinder_tool_plugin/test_flawfinder_tool_plugin.py rename to tests/plugins/tool/flawfinder/test_flawfinder_tool_plugin.py index 76e37f45..9d8df4d1 100644 --- a/tests/plugins/tool/flawfinder_tool_plugin/test_flawfinder_tool_plugin.py +++ b/tests/plugins/tool/flawfinder/test_flawfinder_tool_plugin.py @@ -7,15 +7,18 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.flawfinder_tool_plugin import FlawfinderToolPlugin +from statick_tool.plugins.tool.flawfinder import FlawfinderToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_flawfinder_tool_plugin(): @@ -39,27 +42,13 @@ def setup_flawfinder_tool_plugin(): def test_flawfinder_tool_plugin_found(): """Test that the plugin manager can find the flawfinder plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "flawfinder" - assert any( - plugin_info.plugin_object.get_name() == "flawfinder" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Flawfinder Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Flawfinder Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "flawfinder" for _, plugin in list(plugins.items()) ) @@ -92,7 +81,7 @@ def test_flawfinder_tool_plugin_scan_missing_c_src(): assert not issues -@mock.patch("statick_tool.plugins.tool.flawfinder_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.flawfinder.subprocess.check_output") def test_flawfinder_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means flawfinder doesn't exist). @@ -109,7 +98,7 @@ def test_flawfinder_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.flawfinder_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.flawfinder.subprocess.check_output") def test_flawfinder_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means flawfinder hit an error). diff --git a/tests/plugins/tool/flawfinder_tool_plugin/valid_package/strlen.c b/tests/plugins/tool/flawfinder/valid_package/strlen.c similarity index 100% rename from tests/plugins/tool/flawfinder_tool_plugin/valid_package/strlen.c rename to tests/plugins/tool/flawfinder/valid_package/strlen.c diff --git a/tests/plugins/tool/groovylint_tool_plugin/test_groovylint_tool_plugin.py b/tests/plugins/tool/groovylint/test_groovylint_tool_plugin.py similarity index 84% rename from tests/plugins/tool/groovylint_tool_plugin/test_groovylint_tool_plugin.py rename to tests/plugins/tool/groovylint/test_groovylint_tool_plugin.py index 19d33c5d..62f9fce0 100644 --- a/tests/plugins/tool/groovylint_tool_plugin/test_groovylint_tool_plugin.py +++ b/tests/plugins/tool/groovylint/test_groovylint_tool_plugin.py @@ -1,20 +1,23 @@ """Unit tests for the groovylint plugin.""" - import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.groovylint_tool_plugin import GroovyLintToolPlugin +from statick_tool.plugins.tool.groovylint import GroovyLintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_groovylint_tool_plugin(): @@ -43,27 +46,13 @@ def setup_groovylint_tool_plugin(): def test_groovylint_tool_plugin_found(): """Test that the plugin manager can find the groovylint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "groovylint" - assert any( - plugin_info.plugin_object.get_name() == "groovylint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named NPM Groovy Lint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "NPM Groovy Lint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "groovylint" for _, plugin in list(plugins.items()) ) @@ -137,7 +126,7 @@ def test_groovylint_tool_plugin_parse_no_summary(): assert not issues -@mock.patch("statick_tool.plugins.tool.groovylint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.groovylint.subprocess.check_output") def test_groovylint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means groovylint hit an error). @@ -164,7 +153,7 @@ def test_groovylint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_ou assert not issues -@mock.patch("statick_tool.plugins.tool.groovylint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.groovylint.subprocess.check_output") def test_groovylint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means groovylint doesn't exist). diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/Jenkinsfile b/tests/plugins/tool/groovylint/valid_package/Jenkinsfile similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/Jenkinsfile rename to tests/plugins/tool/groovylint/valid_package/Jenkinsfile diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/rsc/.groovylintrc.json b/tests/plugins/tool/groovylint/valid_package/rsc/.groovylintrc.json similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/rsc/.groovylintrc.json rename to tests/plugins/tool/groovylint/valid_package/rsc/.groovylintrc.json diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/rsc/config.yaml b/tests/plugins/tool/groovylint/valid_package/rsc/config.yaml similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/rsc/config.yaml rename to tests/plugins/tool/groovylint/valid_package/rsc/config.yaml diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/test.gradle b/tests/plugins/tool/groovylint/valid_package/test.gradle similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/test.gradle rename to tests/plugins/tool/groovylint/valid_package/test.gradle diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/test.groovy b/tests/plugins/tool/groovylint/valid_package/test.groovy similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/test.groovy rename to tests/plugins/tool/groovylint/valid_package/test.groovy diff --git a/tests/plugins/tool/groovylint_tool_plugin/valid_package/test_errors.groovy b/tests/plugins/tool/groovylint/valid_package/test_errors.groovy similarity index 100% rename from tests/plugins/tool/groovylint_tool_plugin/valid_package/test_errors.groovy rename to tests/plugins/tool/groovylint/valid_package/test_errors.groovy diff --git a/tests/plugins/tool/isort_tool_plugin/rsc/config.yaml b/tests/plugins/tool/isort/rsc/config.yaml similarity index 100% rename from tests/plugins/tool/isort_tool_plugin/rsc/config.yaml rename to tests/plugins/tool/isort/rsc/config.yaml diff --git a/tests/plugins/tool/isort_tool_plugin/test_isort_tool_plugin.py b/tests/plugins/tool/isort/test_isort_tool_plugin.py similarity index 76% rename from tests/plugins/tool/isort_tool_plugin/test_isort_tool_plugin.py rename to tests/plugins/tool/isort/test_isort_tool_plugin.py index 4dc10039..3a5a62b9 100644 --- a/tests/plugins/tool/isort_tool_plugin/test_isort_tool_plugin.py +++ b/tests/plugins/tool/isort/test_isort_tool_plugin.py @@ -7,15 +7,18 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.isort_tool_plugin import IsortToolPlugin +from statick_tool.plugins.tool.isort import IsortToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_isort_tool_plugin(custom_rsc_path=None): @@ -38,29 +41,13 @@ def setup_isort_tool_plugin(custom_rsc_path=None): def test_isort_tool_plugin_found(): """Test that the plugin manager can find the Isort plugin.""" - if sys.version_info.major == 3 and sys.version_info.minor < 6: - pytest.skip("isort is only available for Python 3.6+, unable to test") - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "isort" - assert any( - plugin_info.plugin_object.get_name() == "isort" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Isort Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Isort Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "isort" for _, plugin in list(plugins.items()) ) @@ -110,7 +97,7 @@ def test_isort_tool_plugin_parse_valid(): assert issues[1].filename == "/tmp/y.py" -@mock.patch("statick_tool.plugins.tool.isort_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.isort.subprocess.check_output") def test_isort_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means isort doesn't exist). @@ -128,7 +115,7 @@ def test_isort_tool_plugin_scan_oserror(mock_subprocess_check_output): assert not issues -@mock.patch("statick_tool.plugins.tool.isort_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.isort.subprocess.check_output") def test_isort_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means isort hit an error). diff --git a/tests/plugins/tool/isort_tool_plugin/valid_package/sample.py b/tests/plugins/tool/isort/valid_package/sample.py similarity index 100% rename from tests/plugins/tool/isort_tool_plugin/valid_package/sample.py rename to tests/plugins/tool/isort/valid_package/sample.py diff --git a/tests/plugins/tool/isort_tool_plugin/valid_package/whitespace.py b/tests/plugins/tool/isort/valid_package/whitespace.py similarity index 100% rename from tests/plugins/tool/isort_tool_plugin/valid_package/whitespace.py rename to tests/plugins/tool/isort/valid_package/whitespace.py diff --git a/tests/plugins/tool/lizard_tool_plugin/rsc/config.yaml b/tests/plugins/tool/lizard/rsc/config.yaml similarity index 100% rename from tests/plugins/tool/lizard_tool_plugin/rsc/config.yaml rename to tests/plugins/tool/lizard/rsc/config.yaml diff --git a/tests/plugins/tool/lizard_tool_plugin/rsc/profile.yaml b/tests/plugins/tool/lizard/rsc/profile.yaml similarity index 100% rename from tests/plugins/tool/lizard_tool_plugin/rsc/profile.yaml rename to tests/plugins/tool/lizard/rsc/profile.yaml diff --git a/tests/plugins/tool/lizard_tool_plugin/test_lizard_tool_plugin.py b/tests/plugins/tool/lizard/test_lizard_tool_plugin.py similarity index 79% rename from tests/plugins/tool/lizard_tool_plugin/test_lizard_tool_plugin.py rename to tests/plugins/tool/lizard/test_lizard_tool_plugin.py index 93504bb5..675878d5 100644 --- a/tests/plugins/tool/lizard_tool_plugin/test_lizard_tool_plugin.py +++ b/tests/plugins/tool/lizard/test_lizard_tool_plugin.py @@ -2,17 +2,21 @@ import argparse import os +import sys import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.lizard_tool_plugin import LizardToolPlugin +from statick_tool.plugins.tool.lizard import LizardToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_lizard_tool_plugin(custom_rsc_path=None): @@ -35,27 +39,13 @@ def setup_lizard_tool_plugin(custom_rsc_path=None): def test_lizard_tool_plugin_found(): """Test that the plugin manager can find the lizard plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "lizard" - assert any( - plugin_info.plugin_object.get_name() == "lizard" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Lizard Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Lizard Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "lizard" for _, plugin in list(plugins.items()) ) diff --git a/tests/plugins/tool/lizard_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/lizard/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/lizard_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/lizard/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/lizard_tool_plugin/valid_package/test.c b/tests/plugins/tool/lizard/valid_package/test.c similarity index 100% rename from tests/plugins/tool/lizard_tool_plugin/valid_package/test.c rename to tests/plugins/tool/lizard/valid_package/test.c diff --git a/tests/plugins/tool/make_tool_plugin/test_make_tool_plugin.py b/tests/plugins/tool/make/test_make_tool_plugin.py similarity index 87% rename from tests/plugins/tool/make_tool_plugin/test_make_tool_plugin.py rename to tests/plugins/tool/make/test_make_tool_plugin.py index 682ae773..2aa763f3 100644 --- a/tests/plugins/tool/make_tool_plugin/test_make_tool_plugin.py +++ b/tests/plugins/tool/make/test_make_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.make_tool_plugin import MakeToolPlugin +from statick_tool.plugins.tool.make import MakeToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_make_tool_plugin(): @@ -37,27 +41,13 @@ def setup_make_tool_plugin(): def test_make_tool_plugin_found(): """Test that the plugin manager finds the Make plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "make" - assert any( - plugin_info.plugin_object.get_name() == "make" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Yamllint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Make Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "make" for _, plugin in list(plugins.items()) ) @@ -195,7 +185,7 @@ def test_make_tool_plugin_parse_warnings_mapping(): assert issues[0].cert_reference == "OOP53-CPP" -@mock.patch("statick_tool.plugins.tool.make_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.make.subprocess.check_output") def test_make_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means make hit an error). @@ -214,7 +204,7 @@ def test_make_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): assert not issues -@mock.patch("statick_tool.plugins.tool.make_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.make.subprocess.check_output") def test_make_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means make doesn't exist). diff --git a/tests/plugins/tool/make_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/make/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/make_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/make/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/make_tool_plugin/valid_package/hello.cpp b/tests/plugins/tool/make/valid_package/hello.cpp similarity index 100% rename from tests/plugins/tool/make_tool_plugin/valid_package/hello.cpp rename to tests/plugins/tool/make/valid_package/hello.cpp diff --git a/tests/plugins/tool/mypy_tool_plugin/test_mypy_tool_plugin.py b/tests/plugins/tool/mypy/test_mypy_tool_plugin.py similarity index 79% rename from tests/plugins/tool/mypy_tool_plugin/test_mypy_tool_plugin.py rename to tests/plugins/tool/mypy/test_mypy_tool_plugin.py index b24df573..351746fa 100644 --- a/tests/plugins/tool/mypy_tool_plugin/test_mypy_tool_plugin.py +++ b/tests/plugins/tool/mypy/test_mypy_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.mypy_tool_plugin import MypyToolPlugin +from statick_tool.plugins.tool.mypy import MypyToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_mypy_tool_plugin(): @@ -34,27 +38,13 @@ def setup_mypy_tool_plugin(): def test_mypy_tool_plugin_found(): """Test that the plugin manager can find the Mypy plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "mypy" - assert any( - plugin_info.plugin_object.get_name() == "mypy" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Mypy Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Mypy Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "mypy" for _, plugin in list(plugins.items()) ) @@ -110,7 +100,7 @@ def test_mypy_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.mypy_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.mypy.subprocess.check_output") def test_mypy_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means mypy doesn't exist). @@ -128,7 +118,7 @@ def test_mypy_tool_plugin_scan_oserror(mock_subprocess_check_output): assert not issues -@mock.patch("statick_tool.plugins.tool.mypy_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.mypy.subprocess.check_output") def test_mypy_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means mypy hit an error). diff --git a/tests/plugins/tool/mypy_tool_plugin/valid_package/wrong_mypy.py b/tests/plugins/tool/mypy/valid_package/wrong_mypy.py similarity index 100% rename from tests/plugins/tool/mypy_tool_plugin/valid_package/wrong_mypy.py rename to tests/plugins/tool/mypy/valid_package/wrong_mypy.py diff --git a/tests/plugins/tool/perlcritic_tool_plugin/test_perlcritic_tool_plugin.py b/tests/plugins/tool/perlcritic/test_perlcritic_tool_plugin.py similarity index 83% rename from tests/plugins/tool/perlcritic_tool_plugin/test_perlcritic_tool_plugin.py rename to tests/plugins/tool/perlcritic/test_perlcritic_tool_plugin.py index 66602f58..1f3fcfc0 100644 --- a/tests/plugins/tool/perlcritic_tool_plugin/test_perlcritic_tool_plugin.py +++ b/tests/plugins/tool/perlcritic/test_perlcritic_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.perlcritic_tool_plugin import PerlCriticToolPlugin +from statick_tool.plugins.tool.perlcritic import PerlCriticToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_perlcritic_tool_plugin(binary=None): @@ -40,27 +44,13 @@ def setup_perlcritic_tool_plugin(binary=None): def test_perlcritic_tool_plugin_found(): """Test that the plugin manager can find the perlcritic plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "perlcritic" - assert any( - plugin_info.plugin_object.get_name() == "perlcritic" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named PerlCritic Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Perl::Critic Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "perlcritic" for _, plugin in list(plugins.items()) ) @@ -149,7 +139,7 @@ def test_perlcritic_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.perlcritic_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.perlcritic.subprocess.check_output") def test_perlcritic_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means perlcritic doesn't exist). @@ -168,7 +158,7 @@ def test_perlcritic_tool_plugin_scan_oserror(mock_subprocess_check_output): assert not issues -@mock.patch("statick_tool.plugins.tool.perlcritic_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.perlcritic.subprocess.check_output") def test_perlcritic_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means perlcritic hit an error). diff --git a/tests/plugins/tool/perlcritic_tool_plugin/valid_package/test.pl b/tests/plugins/tool/perlcritic/valid_package/test.pl similarity index 100% rename from tests/plugins/tool/perlcritic_tool_plugin/valid_package/test.pl rename to tests/plugins/tool/perlcritic/valid_package/test.pl diff --git a/tests/plugins/tool/pycodestyle_tool_plugin/test_pycodestyle_tool_plugin.py b/tests/plugins/tool/pycodestyle/test_pycodestyle_tool_plugin.py similarity index 78% rename from tests/plugins/tool/pycodestyle_tool_plugin/test_pycodestyle_tool_plugin.py rename to tests/plugins/tool/pycodestyle/test_pycodestyle_tool_plugin.py index 9ea91a1c..66e11953 100644 --- a/tests/plugins/tool/pycodestyle_tool_plugin/test_pycodestyle_tool_plugin.py +++ b/tests/plugins/tool/pycodestyle/test_pycodestyle_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.pycodestyle_tool_plugin import PycodestyleToolPlugin +from statick_tool.plugins.tool.pycodestyle import PycodestyleToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_pycodestyle_tool_plugin(): @@ -33,27 +37,13 @@ def setup_pycodestyle_tool_plugin(): def test_pycodestyle_tool_plugin_found(): """Test that the plugin manager can find the PyCodeStyle plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "pycodestyle" - assert any( - plugin_info.plugin_object.get_name() == "pycodestyle" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Pycodestyle Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Pycodestyle Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "pycodestyle" for _, plugin in list(plugins.items()) ) @@ -106,7 +96,7 @@ def test_pycodestyle_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.pycodestyle_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pycodestyle.subprocess.check_output") def test_pycodestyle_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means pycodestyle doesn't exist). @@ -125,7 +115,7 @@ def test_pycodestyle_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.pycodestyle_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pycodestyle.subprocess.check_output") def test_pycodestyle_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means pycodestyle hit an error). diff --git a/tests/plugins/tool/pycodestyle_tool_plugin/valid_package/e501.py b/tests/plugins/tool/pycodestyle/valid_package/e501.py similarity index 100% rename from tests/plugins/tool/pycodestyle_tool_plugin/valid_package/e501.py rename to tests/plugins/tool/pycodestyle/valid_package/e501.py diff --git a/tests/plugins/tool/pydocstyle_tool_plugin/test_pydocstyle_tool_plugin.py b/tests/plugins/tool/pydocstyle/test_pydocstyle_tool_plugin.py similarity index 76% rename from tests/plugins/tool/pydocstyle_tool_plugin/test_pydocstyle_tool_plugin.py rename to tests/plugins/tool/pydocstyle/test_pydocstyle_tool_plugin.py index 7c601eef..22894cfc 100644 --- a/tests/plugins/tool/pydocstyle_tool_plugin/test_pydocstyle_tool_plugin.py +++ b/tests/plugins/tool/pydocstyle/test_pydocstyle_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.pydocstyle_tool_plugin import PydocstyleToolPlugin +from statick_tool.plugins.tool.pydocstyle import PydocstyleToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_pydocstyle_tool_plugin(): @@ -33,27 +37,13 @@ def setup_pydocstyle_tool_plugin(): def test_pydocstyle_tool_plugin_found(): """Test that the plugin manager can find the PyDocStyle plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "pydocstyle" - assert any( - plugin_info.plugin_object.get_name() == "pydocstyle" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Pydocstyle Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Pydocstyle Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "pydocstyle" for _, plugin in list(plugins.items()) ) @@ -93,7 +83,7 @@ def test_pydocstyle_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.pydocstyle_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pydocstyle.subprocess.check_output") def test_pydocstyle_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means tool hit an error). @@ -120,7 +110,7 @@ def test_pydocstyle_tool_plugin_scan_calledprocesserror(mock_subprocess_check_ou assert not issues -@mock.patch("statick_tool.plugins.tool.pydocstyle_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pydocstyle.subprocess.check_output") def test_pydocstyle_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means tool doesn't exist). diff --git a/tests/plugins/tool/pydocstyle_tool_plugin/valid_package/d103.py b/tests/plugins/tool/pydocstyle/valid_package/d103.py similarity index 100% rename from tests/plugins/tool/pydocstyle_tool_plugin/valid_package/d103.py rename to tests/plugins/tool/pydocstyle/valid_package/d103.py diff --git a/tests/plugins/tool/pyflakes_tool_plugin/test_pyflakes_tool_plugin.py b/tests/plugins/tool/pyflakes/test_pyflakes_tool_plugin.py similarity index 80% rename from tests/plugins/tool/pyflakes_tool_plugin/test_pyflakes_tool_plugin.py rename to tests/plugins/tool/pyflakes/test_pyflakes_tool_plugin.py index c725c5e7..81d7b2ef 100644 --- a/tests/plugins/tool/pyflakes_tool_plugin/test_pyflakes_tool_plugin.py +++ b/tests/plugins/tool/pyflakes/test_pyflakes_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.pyflakes_tool_plugin import PyflakesToolPlugin +from statick_tool.plugins.tool.pyflakes import PyflakesToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_pyflakes_tool_plugin(): @@ -33,27 +37,13 @@ def setup_pyflakes_tool_plugin(): def test_pyflakes_tool_plugin_found(): """Test that the plugin manager can find the Pyflakes plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "pyflakes" - assert any( - plugin_info.plugin_object.get_name() == "pyflakes" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Pyflakes Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Pyflakes Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "pyflakes" for _, plugin in list(plugins.items()) ) @@ -115,7 +105,7 @@ def test_pyflakes_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.pyflakes_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pyflakes.subprocess.check_output") def test_pyflakes_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means pyflakes hit an error). @@ -142,7 +132,7 @@ def test_pyflakes_tool_plugin_scan_calledprocesserror(mock_subprocess_check_outp assert issues is None -@mock.patch("statick_tool.plugins.tool.pyflakes_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pyflakes.subprocess.check_output") def test_pyflakes_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means pyflakes doesn't exist). diff --git a/tests/plugins/tool/pyflakes_tool_plugin/valid_package/pyflakes_test.py b/tests/plugins/tool/pyflakes/valid_package/pyflakes_test.py similarity index 100% rename from tests/plugins/tool/pyflakes_tool_plugin/valid_package/pyflakes_test.py rename to tests/plugins/tool/pyflakes/valid_package/pyflakes_test.py diff --git a/tests/plugins/tool/pylint_tool_plugin/test_pylint_tool_plugin.py b/tests/plugins/tool/pylint/test_pylint_tool_plugin.py similarity index 76% rename from tests/plugins/tool/pylint_tool_plugin/test_pylint_tool_plugin.py rename to tests/plugins/tool/pylint/test_pylint_tool_plugin.py index c30afd35..b41144a8 100644 --- a/tests/plugins/tool/pylint_tool_plugin/test_pylint_tool_plugin.py +++ b/tests/plugins/tool/pylint/test_pylint_tool_plugin.py @@ -4,17 +4,21 @@ import multiprocessing import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.pylint_tool_plugin import PylintToolPlugin +from statick_tool.plugins.tool.pylint import PylintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_pylint_tool_plugin(max_procs=1): @@ -35,27 +39,13 @@ def setup_pylint_tool_plugin(max_procs=1): def test_pylint_tool_plugin_found(): """Test that the plugin manager finds the Pylint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "pylint" - assert any( - plugin_info.plugin_object.get_name() == "pylint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Pylint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Pylint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "pylint" for _, plugin in list(plugins.items()) ) @@ -66,7 +56,7 @@ def test_pylint_tool_plugin_scan_valid(): "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") ) package["python_src"] = [ - os.path.join(os.path.dirname(__file__), "valid_package", "basic.py") + os.path.join(os.path.dirname(__file__), "valid_package", "pylint_basic.py") ] issues = pltp.scan(package, "level") # We expect to have missing docstring and unused import warnings. @@ -82,7 +72,7 @@ def test_pylint_tool_plugin_scan_valid_max_cpu_cores(): "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") ) package["python_src"] = [ - os.path.join(os.path.dirname(__file__), "valid_package", "basic.py") + os.path.join(os.path.dirname(__file__), "valid_package", "pylint_basic.py") ] issues = pltp.scan(package, "level") # We expect to have missing docstring and unused import warnings. @@ -92,21 +82,21 @@ def test_pylint_tool_plugin_scan_valid_max_cpu_cores(): def test_pylint_tool_plugin_parse_valid(): """Verify that we can parse the normal output of pylint.""" pltp = setup_pylint_tool_plugin() - output = "basic.py:1: [W0611(unused-import), ] Unused import subprocess" + output = "pylint_basic.py:1: [W0611(unused-import), ] Unused import subprocess" issues = pltp.parse_output([output]) assert len(issues) == 1 - assert issues[0].filename == "basic.py" + assert issues[0].filename == "pylint_basic.py" assert issues[0].line_number == "1" assert issues[0].tool == "pylint" assert issues[0].issue_type == "W0611(unused-import)" assert issues[0].severity == "5" assert issues[0].message == "Unused import subprocess" - output = "basic.py:1: [W0611(unused-import)] Unused import subprocess" + output = "pylint_basic.py:1: [W0611(unused-import)] Unused import subprocess" issues = pltp.parse_output([output]) assert issues[0].message == "Unused import subprocess" - output = "basic.py:1: [W0611(unused-import), not-empty] Unused import subprocess" + output = "pylint_basic.py:1: [W0611(unused-import), not-empty] Unused import subprocess" issues = pltp.parse_output([output]) assert issues[0].message == "not-empty: Unused import subprocess" @@ -119,7 +109,7 @@ def test_pylint_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.pylint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pylint.subprocess.check_output") def test_pylint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means pylint hit an error). @@ -146,7 +136,7 @@ def test_pylint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output assert issues is None -@mock.patch("statick_tool.plugins.tool.pylint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.pylint.subprocess.check_output") def test_pylint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means pylint doesn't exist). diff --git a/tests/plugins/tool/pylint_tool_plugin/valid_package/basic.py b/tests/plugins/tool/pylint/valid_package/pylint_basic.py similarity index 100% rename from tests/plugins/tool/pylint_tool_plugin/valid_package/basic.py rename to tests/plugins/tool/pylint/valid_package/pylint_basic.py diff --git a/tests/plugins/tool/ruff_tool_plugin/test_ruff_tool_plugin.py b/tests/plugins/tool/ruff/test_ruff_tool_plugin.py similarity index 78% rename from tests/plugins/tool/ruff_tool_plugin/test_ruff_tool_plugin.py rename to tests/plugins/tool/ruff/test_ruff_tool_plugin.py index ec5de924..f2f4d46f 100644 --- a/tests/plugins/tool/ruff_tool_plugin/test_ruff_tool_plugin.py +++ b/tests/plugins/tool/ruff/test_ruff_tool_plugin.py @@ -3,17 +3,21 @@ import argparse import os import subprocess +import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.ruff_tool_plugin import RuffToolPlugin +from statick_tool.plugins.tool.ruff import RuffToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_ruff_tool_plugin(): @@ -33,27 +37,13 @@ def setup_ruff_tool_plugin(): def test_ruff_tool_plugin_found(): """Test that the plugin manager can find the ruff plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "ruff" - assert any( - plugin_info.plugin_object.get_name() == "ruff" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named ruff Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Ruff Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "ruff" for _, plugin in list(plugins.items()) ) @@ -102,7 +92,7 @@ def test_ruff_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.ruff_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.ruff.subprocess.check_output") def test_ruff_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means ruff hit an error). @@ -129,7 +119,7 @@ def test_ruff_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): assert not issues -@mock.patch("statick_tool.plugins.tool.ruff_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.ruff.subprocess.check_output") def test_ruff_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means ruff doesn't exist). diff --git a/tests/plugins/tool/ruff_tool_plugin/valid_package/ruff_test.py b/tests/plugins/tool/ruff/valid_package/ruff_test.py similarity index 100% rename from tests/plugins/tool/ruff_tool_plugin/valid_package/ruff_test.py rename to tests/plugins/tool/ruff/valid_package/ruff_test.py diff --git a/tests/plugins/tool/shellcheck_tool_plugin/test_shellcheck_tool_plugin.py b/tests/plugins/tool/shellcheck/test_shellcheck_tool_plugin.py similarity index 88% rename from tests/plugins/tool/shellcheck_tool_plugin/test_shellcheck_tool_plugin.py rename to tests/plugins/tool/shellcheck/test_shellcheck_tool_plugin.py index 22e47623..a78ce54b 100644 --- a/tests/plugins/tool/shellcheck_tool_plugin/test_shellcheck_tool_plugin.py +++ b/tests/plugins/tool/shellcheck/test_shellcheck_tool_plugin.py @@ -7,15 +7,18 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.shellcheck_tool_plugin import ShellcheckToolPlugin +from statick_tool.plugins.tool.shellcheck import ShellcheckToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_shellcheck_tool_plugin(binary=None): @@ -38,27 +41,13 @@ def setup_shellcheck_tool_plugin(binary=None): def test_shellcheck_tool_plugin_found(): """Test that the plugin manager finds the Shellcheck plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "shellcheck" - assert any( - plugin_info.plugin_object.get_name() == "shellcheck" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Shellcheck Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Shellcheck Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "shellcheck" for _, plugin in list(plugins.items()) ) @@ -250,7 +239,7 @@ def test_shellcheck_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.shellcheck_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.shellcheck.subprocess.check_output") def test_shellcheck_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means shellcheck hit an error). @@ -282,7 +271,7 @@ def test_shellcheck_tool_plugin_scan_calledprocesserror(mock_subprocess_check_ou assert issues is None -@mock.patch("statick_tool.plugins.tool.shellcheck_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.shellcheck.subprocess.check_output") def test_shellcheck_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means shellcheck doesn't exist). diff --git a/tests/plugins/tool/shellcheck_tool_plugin/valid_package/basic.sh b/tests/plugins/tool/shellcheck/valid_package/basic.sh similarity index 100% rename from tests/plugins/tool/shellcheck_tool_plugin/valid_package/basic.sh rename to tests/plugins/tool/shellcheck/valid_package/basic.sh diff --git a/tests/plugins/tool/spotbugs_tool_plugin/rsc/config.yaml b/tests/plugins/tool/spotbugs/rsc/config.yaml similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/rsc/config.yaml rename to tests/plugins/tool/spotbugs/rsc/config.yaml diff --git a/tests/plugins/tool/spotbugs_tool_plugin/rsc/profile.yaml b/tests/plugins/tool/spotbugs/rsc/profile.yaml similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/rsc/profile.yaml rename to tests/plugins/tool/spotbugs/rsc/profile.yaml diff --git a/tests/plugins/tool/spotbugs_tool_plugin/rsc/spotbugs-exclude.xml b/tests/plugins/tool/spotbugs/rsc/spotbugs-exclude.xml similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/rsc/spotbugs-exclude.xml rename to tests/plugins/tool/spotbugs/rsc/spotbugs-exclude.xml diff --git a/tests/plugins/tool/spotbugs_tool_plugin/test_spotbugs_tool_plugin.py b/tests/plugins/tool/spotbugs/test_spotbugs_tool_plugin.py similarity index 89% rename from tests/plugins/tool/spotbugs_tool_plugin/test_spotbugs_tool_plugin.py rename to tests/plugins/tool/spotbugs/test_spotbugs_tool_plugin.py index 7b58961f..56465e50 100644 --- a/tests/plugins/tool/spotbugs_tool_plugin/test_spotbugs_tool_plugin.py +++ b/tests/plugins/tool/spotbugs/test_spotbugs_tool_plugin.py @@ -7,15 +7,18 @@ import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.spotbugs_tool_plugin import SpotbugsToolPlugin +from statick_tool.plugins.tool.spotbugs import SpotbugsToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_spotbugs_tool_plugin(use_plugin_context=True, custom_rsc_path=None): @@ -42,27 +45,13 @@ def setup_spotbugs_tool_plugin(use_plugin_context=True, custom_rsc_path=None): def test_spotbugs_tool_plugin_found(): """Test that the plugin manager can find the spotbugs plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "spotbugs" - assert any( - plugin_info.plugin_object.get_name() == "spotbugs" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Spotbugs Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Spotbugs Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "spotbugs" for _, plugin in list(plugins.items()) ) @@ -230,7 +219,7 @@ def test_spotbugs_tool_plugin_parse_wrong_file_path(): assert issues[0].filename == "Test.java" -@mock.patch("statick_tool.plugins.tool.spotbugs_tool_plugin.ToolPlugin.command_exists") +@mock.patch("statick_tool.plugins.tool.spotbugs.ToolPlugin.command_exists") def test_spotbugs_tool_plugin_scan_commandnotfound(mock_command_exists): """Test what happens when self.command_exists returns False. @@ -245,7 +234,7 @@ def test_spotbugs_tool_plugin_scan_commandnotfound(mock_command_exists): assert not issues -@mock.patch("statick_tool.plugins.tool.spotbugs_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.spotbugs.subprocess.check_output") def test_spotbugs_tool_plugin_scan_oserror(mock_subprocess_check_output): """ Test what happens when an OSError is raised (usually means maven doesn't exist - unlikely). @@ -263,7 +252,7 @@ def test_spotbugs_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.spotbugs_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.spotbugs.subprocess.check_output") def test_spotbugs_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means maven hit an error). diff --git a/tests/plugins/tool/spotbugs_tool_plugin/valid_package/.gitignore b/tests/plugins/tool/spotbugs/valid_package/.gitignore similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/valid_package/.gitignore rename to tests/plugins/tool/spotbugs/valid_package/.gitignore diff --git a/tests/plugins/tool/spotbugs_tool_plugin/valid_package/pom.xml b/tests/plugins/tool/spotbugs/valid_package/pom.xml similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/valid_package/pom.xml rename to tests/plugins/tool/spotbugs/valid_package/pom.xml diff --git a/tests/plugins/tool/spotbugs_tool_plugin/valid_package/src/main/java/Test.java b/tests/plugins/tool/spotbugs/valid_package/src/main/java/Test.java similarity index 100% rename from tests/plugins/tool/spotbugs_tool_plugin/valid_package/src/main/java/Test.java rename to tests/plugins/tool/spotbugs/valid_package/src/main/java/Test.java diff --git a/tests/plugins/tool/uncrustify_tool_plugin/test_uncrustify_tool_plugin.py b/tests/plugins/tool/uncrustify/test_uncrustify_tool_plugin.py similarity index 84% rename from tests/plugins/tool/uncrustify_tool_plugin/test_uncrustify_tool_plugin.py rename to tests/plugins/tool/uncrustify/test_uncrustify_tool_plugin.py index 8e70c53b..b429741e 100644 --- a/tests/plugins/tool/uncrustify_tool_plugin/test_uncrustify_tool_plugin.py +++ b/tests/plugins/tool/uncrustify/test_uncrustify_tool_plugin.py @@ -3,25 +3,24 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.uncrustify_tool_plugin import UncrustifyToolPlugin +from statick_tool.plugins.tool.uncrustify import UncrustifyToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + +from tempfile import TemporaryDirectory def setup_uncrustify_tool_plugin(extra_path=None, use_plugin_context=True, binary=None): @@ -47,27 +46,13 @@ def setup_uncrustify_tool_plugin(extra_path=None, use_plugin_context=True, binar def test_uncrustify_tool_plugin_found(): """Test that the plugin manager can find the uncrustify plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "uncrustify" - assert any( - plugin_info.plugin_object.get_name() == "uncrustify" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Uncrustify Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "Uncrustify Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "uncrustify" for _, plugin in list(plugins.items()) ) @@ -190,7 +175,7 @@ def test_uncrustify_tool_plugin_scan_missing_fields(): assert not issues -@mock.patch("statick_tool.plugins.tool.uncrustify_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.uncrustify.subprocess.check_output") def test_uncrustify_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means uncrustify doesn't exist). @@ -213,7 +198,7 @@ def test_uncrustify_tool_plugin_scan_oserror(mock_subprocess_check_output): assert issues is None -@mock.patch("statick_tool.plugins.tool.uncrustify_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.uncrustify.subprocess.check_output") def test_uncrustify_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means uncrustify hit an error). diff --git a/tests/plugins/tool/uncrustify_tool_plugin/valid_package/CMakeLists.txt b/tests/plugins/tool/uncrustify/valid_package/CMakeLists.txt similarity index 100% rename from tests/plugins/tool/uncrustify_tool_plugin/valid_package/CMakeLists.txt rename to tests/plugins/tool/uncrustify/valid_package/CMakeLists.txt diff --git a/tests/plugins/tool/uncrustify_tool_plugin/valid_package/rsc/uncrustify.cfg b/tests/plugins/tool/uncrustify/valid_package/rsc/uncrustify.cfg similarity index 100% rename from tests/plugins/tool/uncrustify_tool_plugin/valid_package/rsc/uncrustify.cfg rename to tests/plugins/tool/uncrustify/valid_package/rsc/uncrustify.cfg diff --git a/tests/plugins/tool/uncrustify_tool_plugin/valid_package/test.c b/tests/plugins/tool/uncrustify/valid_package/test.c similarity index 100% rename from tests/plugins/tool/uncrustify_tool_plugin/valid_package/test.c rename to tests/plugins/tool/uncrustify/valid_package/test.c diff --git a/tests/plugins/tool/xmllint_tool_plugin/test_xmllint_tool_plugin.py b/tests/plugins/tool/xmllint/test_xmllint_tool_plugin.py similarity index 76% rename from tests/plugins/tool/xmllint_tool_plugin/test_xmllint_tool_plugin.py rename to tests/plugins/tool/xmllint/test_xmllint_tool_plugin.py index 500dceb3..901627ff 100644 --- a/tests/plugins/tool/xmllint_tool_plugin/test_xmllint_tool_plugin.py +++ b/tests/plugins/tool/xmllint/test_xmllint_tool_plugin.py @@ -3,18 +3,22 @@ import argparse import os import subprocess +import sys import mock import pytest -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.xmllint_tool_plugin import XmllintToolPlugin +from statick_tool.plugins.tool.xmllint import XmllintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_xmllint_tool_plugin(): @@ -34,27 +38,13 @@ def setup_xmllint_tool_plugin(): def test_xmllint_tool_plugin_found(): """Test that the plugin manager finds the xmllint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "xmllint" - assert any( - plugin_info.plugin_object.get_name() == "xmllint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Xmllint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "xmllint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "xmllint" for _, plugin in list(plugins.items()) ) @@ -97,7 +87,7 @@ def test_xmllint_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.xmllint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.xmllint.subprocess.check_output") def test_xmllint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means xmllint hit an error). @@ -118,7 +108,7 @@ def test_xmllint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_outpu assert issues is None -@mock.patch("statick_tool.plugins.tool.xmllint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.xmllint.subprocess.check_output") def test_xmllint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means xmllint doesn't exist). diff --git a/tests/plugins/tool/xmllint_tool_plugin/valid_package/premature_end.xml b/tests/plugins/tool/xmllint/valid_package/premature_end.xml similarity index 100% rename from tests/plugins/tool/xmllint_tool_plugin/valid_package/premature_end.xml rename to tests/plugins/tool/xmllint/valid_package/premature_end.xml diff --git a/tests/plugins/tool/yamllint_tool_plugin/test_yamllint_tool_plugin.py b/tests/plugins/tool/yamllint/test_yamllint_tool_plugin.py similarity index 78% rename from tests/plugins/tool/yamllint_tool_plugin/test_yamllint_tool_plugin.py rename to tests/plugins/tool/yamllint/test_yamllint_tool_plugin.py index 10c4d4a4..96b4f38f 100644 --- a/tests/plugins/tool/yamllint_tool_plugin/test_yamllint_tool_plugin.py +++ b/tests/plugins/tool/yamllint/test_yamllint_tool_plugin.py @@ -6,15 +6,18 @@ import sys import mock -from yapsy.PluginManager import PluginManager import statick_tool from statick_tool.config import Config from statick_tool.package import Package from statick_tool.plugin_context import PluginContext -from statick_tool.plugins.tool.yamllint_tool_plugin import YamllintToolPlugin +from statick_tool.plugins.tool.yamllint import YamllintToolPlugin from statick_tool.resources import Resources -from statick_tool.tool_plugin import ToolPlugin + +if sys.version_info < (3, 10): + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points def setup_yamllint_tool_plugin(): @@ -34,27 +37,13 @@ def setup_yamllint_tool_plugin(): def test_yamllint_tool_plugin_found(): """Test that the plugin manager finds the YAMLLint plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Tool": ToolPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "yamllint" - assert any( - plugin_info.plugin_object.get_name() == "yamllint" - for plugin_info in manager.getPluginsOfCategory("Tool") - ) - # While we're at it, verify that a plugin is named Yamllint Tool Plugin + plugins = {} + tool_plugins = entry_points(group="statick_tool.plugins.tool") + for plugin_type in tool_plugins: + plugin = plugin_type.load() + plugins[plugin_type.name] = plugin() assert any( - plugin_info.name == "yamllint Tool Plugin" - for plugin_info in manager.getPluginsOfCategory("Tool") + plugin.get_name() == "yamllint" for _, plugin in list(plugins.items()) ) @@ -100,7 +89,7 @@ def test_yamllint_tool_plugin_parse_invalid(): assert not issues -@mock.patch("statick_tool.plugins.tool.yamllint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.yamllint.subprocess.check_output") def test_yamllint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_output): """Test what happens when a CalledProcessError is raised (usually means yamllint hit an error). @@ -127,7 +116,7 @@ def test_yamllint_tool_plugin_scan_calledprocesserror(mock_subprocess_check_outp assert issues is None -@mock.patch("statick_tool.plugins.tool.yamllint_tool_plugin.subprocess.check_output") +@mock.patch("statick_tool.plugins.tool.yamllint.subprocess.check_output") def test_yamllint_tool_plugin_scan_oserror(mock_subprocess_check_output): """Test what happens when an OSError is raised (usually means yamllint doesn't exist). diff --git a/tests/plugins/tool/yamllint_tool_plugin/valid_package/document-start.yaml b/tests/plugins/tool/yamllint/valid_package/document-start.yaml similarity index 100% rename from tests/plugins/tool/yamllint_tool_plugin/valid_package/document-start.yaml rename to tests/plugins/tool/yamllint/valid_package/document-start.yaml diff --git a/tests/resources/test_resources.py b/tests/resources/test_resources.py index 161debb1..a750c6b6 100644 --- a/tests/resources/test_resources.py +++ b/tests/resources/test_resources.py @@ -3,17 +3,11 @@ import logging import os import tempfile +from tempfile import TemporaryDirectory import statick_tool from statick_tool.resources import Resources -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) - LOGGER = logging.getLogger(__name__) diff --git a/tests/statick/rsc/config-discovery-dependency.yaml b/tests/statick/rsc/config-discovery-dependency.yaml deleted file mode 100644 index 905cf7ff..00000000 --- a/tests/statick/rsc/config-discovery-dependency.yaml +++ /dev/null @@ -1,6 +0,0 @@ -levels: - custom: - discovery: - - cmake - tool: - - do_nothing diff --git a/tests/statick_tool/rsc/config-discovery-dependency.yaml b/tests/statick_tool/rsc/config-discovery-dependency.yaml new file mode 100644 index 00000000..914d59e7 --- /dev/null +++ b/tests/statick_tool/rsc/config-discovery-dependency.yaml @@ -0,0 +1,8 @@ +levels: + custom: + discovery: + # We want to check that a dependency is not run a second time if it runs before the plugin that depends on it. + - ros # Put ros first so it runs before cmake. + - cmake # Put cmake second since it depends on ros. The ros plugin should not run twice. + tool: + - do_nothing diff --git a/tests/statick/rsc/config-enabled-dependency.yaml b/tests/statick_tool/rsc/config-enabled-dependency.yaml similarity index 100% rename from tests/statick/rsc/config-enabled-dependency.yaml rename to tests/statick_tool/rsc/config-enabled-dependency.yaml diff --git a/tests/statick/rsc/config-invalid-reporting-plugins.yaml b/tests/statick_tool/rsc/config-invalid-reporting-plugins.yaml similarity index 100% rename from tests/statick/rsc/config-invalid-reporting-plugins.yaml rename to tests/statick_tool/rsc/config-invalid-reporting-plugins.yaml diff --git a/tests/statick/rsc/config-missing-tool-dependency.yaml b/tests/statick_tool/rsc/config-missing-tool-dependency.yaml similarity index 100% rename from tests/statick/rsc/config-missing-tool-dependency.yaml rename to tests/statick_tool/rsc/config-missing-tool-dependency.yaml diff --git a/tests/statick/rsc/config-missing-tool.yaml b/tests/statick_tool/rsc/config-missing-tool.yaml similarity index 100% rename from tests/statick/rsc/config-missing-tool.yaml rename to tests/statick_tool/rsc/config-missing-tool.yaml diff --git a/tests/statick/rsc/config-no-reporting-plugins.yaml b/tests/statick_tool/rsc/config-no-reporting-plugins.yaml similarity index 100% rename from tests/statick/rsc/config-no-reporting-plugins.yaml rename to tests/statick_tool/rsc/config-no-reporting-plugins.yaml diff --git a/tests/statick/rsc/config-test.yaml b/tests/statick_tool/rsc/config-test.yaml similarity index 100% rename from tests/statick/rsc/config-test.yaml rename to tests/statick_tool/rsc/config-test.yaml diff --git a/tests/statick/rsc/config.yaml b/tests/statick_tool/rsc/config.yaml similarity index 100% rename from tests/statick/rsc/config.yaml rename to tests/statick_tool/rsc/config.yaml diff --git a/tests/statick/rsc/exceptions-test.yaml b/tests/statick_tool/rsc/exceptions-test.yaml similarity index 100% rename from tests/statick/rsc/exceptions-test.yaml rename to tests/statick_tool/rsc/exceptions-test.yaml diff --git a/tests/statick/rsc/exceptions.yaml b/tests/statick_tool/rsc/exceptions.yaml similarity index 100% rename from tests/statick/rsc/exceptions.yaml rename to tests/statick_tool/rsc/exceptions.yaml diff --git a/tests/statick/rsc/packages-file-test.txt b/tests/statick_tool/rsc/packages-file-test.txt similarity index 100% rename from tests/statick/rsc/packages-file-test.txt rename to tests/statick_tool/rsc/packages-file-test.txt diff --git a/tests/statick/rsc/profile-custom.yaml b/tests/statick_tool/rsc/profile-custom.yaml similarity index 100% rename from tests/statick/rsc/profile-custom.yaml rename to tests/statick_tool/rsc/profile-custom.yaml diff --git a/tests/statick/rsc/profile-missing-reporting-plugin.yaml b/tests/statick_tool/rsc/profile-missing-reporting-plugin.yaml similarity index 100% rename from tests/statick/rsc/profile-missing-reporting-plugin.yaml rename to tests/statick_tool/rsc/profile-missing-reporting-plugin.yaml diff --git a/tests/statick/rsc/profile-missing-tool.yaml b/tests/statick_tool/rsc/profile-missing-tool.yaml similarity index 100% rename from tests/statick/rsc/profile-missing-tool.yaml rename to tests/statick_tool/rsc/profile-missing-tool.yaml diff --git a/tests/statick/rsc/profile-test.yaml b/tests/statick_tool/rsc/profile-test.yaml similarity index 100% rename from tests/statick/rsc/profile-test.yaml rename to tests/statick_tool/rsc/profile-test.yaml diff --git a/tests/statick/test_package/hello b/tests/statick_tool/test_package/hello similarity index 100% rename from tests/statick/test_package/hello rename to tests/statick_tool/test_package/hello diff --git a/tests/statick/test_statick.py b/tests/statick_tool/test_statick_tool.py similarity index 98% rename from tests/statick/test_statick.py rename to tests/statick_tool/test_statick_tool.py index 60a81442..7ba691f6 100644 --- a/tests/statick/test_statick.py +++ b/tests/statick_tool/test_statick_tool.py @@ -1,5 +1,4 @@ -"""Unit tests of statick.py.""" - +"""Unit tests of statick_tool.py.""" import contextlib import logging import multiprocessing @@ -15,8 +14,8 @@ from statick_tool.args import Args from statick_tool.discovery_plugin import DiscoveryPlugin from statick_tool.package import Package -from statick_tool.plugins.tool.clang_tidy_tool_plugin import ClangTidyToolPlugin -from statick_tool.statick import Statick +from statick_tool.plugins.tool.clang_tidy import ClangTidyToolPlugin +from statick_tool.statick_tool import Statick LOGGER = logging.getLogger(__name__) @@ -160,7 +159,7 @@ def test_get_level_nonexistent_file(init_statick): assert level is None -@mock.patch("statick_tool.statick.Profile") +@mock.patch("statick_tool.statick_tool.Profile") def test_get_level_ioerror(mocked_profile_constructor, init_statick): """Test the behavior when Profile throws an OSError. @@ -176,7 +175,7 @@ def test_get_level_ioerror(mocked_profile_constructor, init_statick): assert level is None -@mock.patch("statick_tool.statick.Profile") +@mock.patch("statick_tool.statick_tool.Profile") def test_get_level_valueerror(mocked_profile_constructor, init_statick): """Test the behavior when Profile throws a ValueError.""" mocked_profile_constructor.side_effect = ValueError("error") @@ -226,7 +225,7 @@ def test_custom_config_file(init_statick): assert has_level -@mock.patch("statick_tool.statick.Config") +@mock.patch("statick_tool.statick_tool.Config") def test_get_config_valueerror(mocked_config_constructor, init_statick): """Test the behavior when Config throws a ValueError.""" mocked_config_constructor.side_effect = ValueError("error") @@ -238,7 +237,7 @@ def test_get_config_valueerror(mocked_config_constructor, init_statick): assert init_statick.config is None -@mock.patch("statick_tool.statick.Config") +@mock.patch("statick_tool.statick_tool.Config") def test_get_config_oserror(mocked_config_constructor, init_statick): """Test the behavior when Config throws a OSError.""" mocked_config_constructor.side_effect = OSError("error") @@ -250,7 +249,7 @@ def test_get_config_oserror(mocked_config_constructor, init_statick): assert init_statick.config is None -@mock.patch("statick_tool.statick.Exceptions") +@mock.patch("statick_tool.statick_tool.Exceptions") def test_get_exceptions_valueerror(mocked_exceptions_constructor, init_statick): """Test the behavior when Exceptions throws a ValueError.""" mocked_exceptions_constructor.side_effect = ValueError("error") @@ -262,7 +261,7 @@ def test_get_exceptions_valueerror(mocked_exceptions_constructor, init_statick): assert init_statick.exceptions is None -@mock.patch("statick_tool.statick.Exceptions") +@mock.patch("statick_tool.statick_tool.Exceptions") def test_get_exceptions_oserror(mocked_exceptions_constructor, init_statick): """Test the behavior when Exceptions throws a OSError.""" mocked_exceptions_constructor.side_effect = OSError("error") @@ -296,7 +295,7 @@ def test_run(): for tool in issues: assert not issues[tool] try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -315,7 +314,7 @@ def test_run_missing_path(init_statick): assert issues is None assert not success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -341,7 +340,7 @@ def test_run_missing_config(init_statick): assert issues is None assert not success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default_value")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -369,7 +368,7 @@ def test_run_output_is_not_directory(mocked_mkdir, init_statick): assert issues is None assert not success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -392,7 +391,7 @@ def test_run_force_tool_list(init_statick): assert not issues[tool] assert success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -421,7 +420,7 @@ def test_run_package_is_ignored(init_statick): assert not issues assert success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -558,6 +557,7 @@ def test_run_tool_dependency(init_statick): path = parsed_args.path statick.get_config(parsed_args) statick.get_exceptions(parsed_args) + print(f"tool plugins: {statick.tool_plugins}") issues, success = statick.run(path, parsed_args) for tool in issues: assert not issues[tool] @@ -734,7 +734,7 @@ def test_run_invalid_level(init_statick): assert issues is None assert not success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -765,7 +765,7 @@ def test_run_mkdir_oserror(mocked_mkdir, init_statick): assert issues is None assert not success try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -832,7 +832,7 @@ def test_run_called_process_error(mock_subprocess_check_output): for tool in issues: assert not issues[tool] try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") @@ -1338,7 +1338,7 @@ def test_scan_package(init_statick_ws): assert issues is None try: - shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick-default")) + shutil.rmtree(os.path.join(os.path.dirname(__file__), "statick_tool-default")) except OSError as ex: print(f"Error: {ex}") diff --git a/tests/statick/test_workspace/ignore_package/AMENT_IGNORE b/tests/statick_tool/test_workspace/ignore_package/AMENT_IGNORE similarity index 100% rename from tests/statick/test_workspace/ignore_package/AMENT_IGNORE rename to tests/statick_tool/test_workspace/ignore_package/AMENT_IGNORE diff --git a/tests/statick/test_workspace/ignore_package/package.xml b/tests/statick_tool/test_workspace/ignore_package/package.xml similarity index 100% rename from tests/statick/test_workspace/ignore_package/package.xml rename to tests/statick_tool/test_workspace/ignore_package/package.xml diff --git a/tests/statick/test_workspace/test_package/hello b/tests/statick_tool/test_workspace/test_package/hello similarity index 100% rename from tests/statick/test_workspace/test_package/hello rename to tests/statick_tool/test_workspace/test_package/hello diff --git a/tests/statick/test_workspace/test_package/package.xml b/tests/statick_tool/test_workspace/test_package/package.xml similarity index 100% rename from tests/statick/test_workspace/test_package/package.xml rename to tests/statick_tool/test_workspace/test_package/package.xml diff --git a/tests/statick/test_workspace/test_package2/hello b/tests/statick_tool/test_workspace/test_package2/hello similarity index 100% rename from tests/statick/test_workspace/test_package2/hello rename to tests/statick_tool/test_workspace/test_package2/hello diff --git a/tests/statick/test_workspace/test_package2/package.xml b/tests/statick_tool/test_workspace/test_package2/package.xml similarity index 100% rename from tests/statick/test_workspace/test_package2/package.xml rename to tests/statick_tool/test_workspace/test_package2/package.xml diff --git a/tests/tool_plugin/test_tool_plugin.py b/tests/tool_plugin/test_tool_plugin.py index 25f13231..f6c0ed36 100644 --- a/tests/tool_plugin/test_tool_plugin.py +++ b/tests/tool_plugin/test_tool_plugin.py @@ -5,6 +5,7 @@ import stat import sys import tempfile +from tempfile import TemporaryDirectory import pytest @@ -13,13 +14,6 @@ from statick_tool.resources import Resources from statick_tool.tool_plugin import ToolPlugin -try: - from tempfile import TemporaryDirectory -except: # pylint: disable=bare-except # noqa: E722 # NOLINT - from backports.tempfile import ( # pylint: disable=wrong-import-order - TemporaryDirectory, - ) - def test_tool_plugin_load_mapping_valid(): """Test that we can load the warnings mapping.""" diff --git a/tox.ini b/tox.ini index 1497befa..70799a4b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,54 +1,25 @@ [tox] -envlist = py39, py310, py311 +envlist = py39, py310, py311, py312, py313 skip_missing_interpreters = true [pytest] norecursedirs = .tox build docs examples -# To work with black some items must be ignored. -# https://github.com/psf/black#how-black-wraps-lines -# We also set a HUGE maximum line length so that black is in charge of our line lengths, not flake8. -[flake8] -exclude = .tox,tests/plugins/tool/black_tool_plugin/valid_package/format_errors.py,tests/plugins/tool/isort_tool_plugin/valid_package/*.py -ignore = E126, E203, E231, E241, W503, W504 -max-line-length = 9000 - -# To work with black a specific configuration is required. -# https://github.com/psf/black#how-black-wraps-lines -[isort] -known_first_party = statick_tool -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -use_parentheses = True -line_length = 88 -honor_noqa = True -skip_glob = **/tests/plugins/tool/isort_tool_plugin/valid_package/*.py - [gh-actions] python = 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 + 3.13: py313 [testenv] changedir = {toxinidir}/output-{envname} -passenv = CI -setenv = PY_IGNORE_IMPORTMISMATCH = 1 deps = - deprecated - flake8<5 # Pin until https://github.com/tholo/pytest-flake8/issues/87 is fixed. - flake8-pep3101 - pycodestyle - pydocstyle - pytest - pytest-cov - pytest-flake8 - pytest-isort .[test] commands = pytest \ - --cov={toxinidir}/statick_tool \ + --cov={toxinidir}/src/statick_tool \ --cov-report term-missing \ --doctest-modules \ --junit-xml=statick-{envname}-junit.xml \