From 838fd91aa99893319c6f6f6b3cd0725209c5ba9e Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 11:02:49 +0200 Subject: [PATCH 01/13] Use namespace `mlx/coverity` instead of `mlx` --- .gitignore | 1 + MANIFEST.in | 6 +----- example/conf.py | 4 ++-- mlx/__init__.py | 3 --- mlx/coverity/__init__.py | 21 +++++++++++++++++++ mlx/{ => coverity}/coverity.py | 10 ++++----- .../coverity_directives/__init__.py | 0 .../coverity_defect_list.py | 4 ++-- mlx/{ => coverity}/coverity_item_element.py | 2 +- mlx/{ => coverity}/coverity_logging.py | 0 mlx/{ => coverity}/coverity_services.py | 0 setup.py | 7 ++++--- tests/test_coverity.py | 4 ++-- 13 files changed, 39 insertions(+), 23 deletions(-) delete mode 100644 mlx/__init__.py create mode 100644 mlx/coverity/__init__.py rename mlx/{ => coverity}/coverity.py (96%) rename mlx/{ => coverity}/coverity_directives/__init__.py (100%) rename mlx/{ => coverity}/coverity_directives/coverity_defect_list.py (99%) rename mlx/{ => coverity}/coverity_item_element.py (99%) rename mlx/{ => coverity}/coverity_logging.py (100%) rename mlx/{ => coverity}/coverity_services.py (100%) diff --git a/.gitignore b/.gitignore index 5344b5a0..3080417e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tests/docs/autodoc/docs/_build .coverage coverage.xml .env +mlx/coverity/__coverity_version__.py diff --git a/MANIFEST.in b/MANIFEST.in index f2d3fbf6..dd552957 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,15 +1,11 @@ # Include the readme file include README.rst -# Include the assets - javascript -# include mlx/assets/*.js - - # added by check_manifest.py include LICENSE include NOTICE include tox.ini -recursive-include mlx *.py +recursive-include mlx/coverity *.py recursive-include example *.bat recursive-include example *.py recursive-include example *.rst diff --git a/example/conf.py b/example/conf.py index 8033ffa4..d6a7e18c 100644 --- a/example/conf.py +++ b/example/conf.py @@ -15,11 +15,11 @@ import sys import mlx.coverity +from mlx.coverity import __version__ import mlx.traceability from decouple import config -from pkg_resources import get_distribution -pkg_version = get_distribution("mlx.coverity").version +pkg_version = __version__ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/mlx/__init__.py b/mlx/__init__.py deleted file mode 100644 index 622bca20..00000000 --- a/mlx/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- - -__import__("pkg_resources").declare_namespace(__name__) diff --git a/mlx/coverity/__init__.py b/mlx/coverity/__init__.py new file mode 100644 index 00000000..47bdd17f --- /dev/null +++ b/mlx/coverity/__init__.py @@ -0,0 +1,21 @@ +""" Melexis sphinx coverity extention """ + +__all__ = [ + "CoverityDefect", + "CoverityDefectListDirective", + "CoverityDefectService", + "ItemElement", + "report_info", + "report_warning", + "SphinxCoverityConnector", +] + +from .__coverity_verion__ import __version__ +from .coverity_logging import report_info, report_warning +from .coverity import SphinxCoverityConnector +from .coverity_services import CoverityDefectService +from .coverity_item_element import ItemElement +from .coverity_directives.coverity_defect_list import CoverityDefect, CoverityDefectListDirective + +# provide setup function here for Sphinx +from .coverity import setup # noqa: unused-import diff --git a/mlx/coverity.py b/mlx/coverity/coverity.py similarity index 96% rename from mlx/coverity.py rename to mlx/coverity/coverity.py index 5e198246..e89a988b 100644 --- a/mlx/coverity.py +++ b/mlx/coverity/coverity.py @@ -11,11 +11,11 @@ from urllib.error import URLError, HTTPError from docutils import nodes -import pkg_resources -from mlx.coverity_logging import report_info, report_warning -from mlx.coverity_services import CoverityDefectService -from mlx.coverity_directives.coverity_defect_list import ( +from .__coverity_version__ import __version__ +from .coverity_logging import report_info, report_warning +from .coverity_services import CoverityDefectService +from .coverity_directives.coverity_defect_list import ( CoverityDefect, CoverityDefectListDirective, ) @@ -177,7 +177,7 @@ def setup(app): app.connect("builder-inited", sphinx_coverity_connector.initialize_environment) try: - version = pkg_resources.require("mlx.coverity")[0].version + version = __version__ except LookupError: version = "dev" return { diff --git a/mlx/coverity_directives/__init__.py b/mlx/coverity/coverity_directives/__init__.py similarity index 100% rename from mlx/coverity_directives/__init__.py rename to mlx/coverity/coverity_directives/__init__.py diff --git a/mlx/coverity_directives/coverity_defect_list.py b/mlx/coverity/coverity_directives/coverity_defect_list.py similarity index 99% rename from mlx/coverity_directives/coverity_defect_list.py rename to mlx/coverity/coverity_directives/coverity_defect_list.py index 89e2bcd1..9cd54479 100644 --- a/mlx/coverity_directives/coverity_defect_list.py +++ b/mlx/coverity/coverity_directives/coverity_defect_list.py @@ -12,8 +12,8 @@ mpl.use("Agg") import matplotlib.pyplot as plt -from mlx.coverity_logging import report_info, report_warning -from mlx.coverity_item_element import ItemElement +from ..coverity_logging import report_info, report_warning +from ..coverity_item_element import ItemElement def pct_wrapper(sizes): diff --git a/mlx/coverity_item_element.py b/mlx/coverity/coverity_item_element.py similarity index 99% rename from mlx/coverity_item_element.py rename to mlx/coverity/coverity_item_element.py index 65b6137a..314c8a1a 100644 --- a/mlx/coverity_item_element.py +++ b/mlx/coverity/coverity_item_element.py @@ -6,7 +6,7 @@ from sphinx.errors import NoUri from urlextract import URLExtract -from mlx.coverity_logging import report_warning +from .coverity_logging import report_warning class ItemElement(nodes.General, nodes.Element): diff --git a/mlx/coverity_logging.py b/mlx/coverity/coverity_logging.py similarity index 100% rename from mlx/coverity_logging.py rename to mlx/coverity/coverity_logging.py diff --git a/mlx/coverity_services.py b/mlx/coverity/coverity_services.py similarity index 100% rename from mlx/coverity_services.py rename to mlx/coverity/coverity_services.py diff --git a/setup.py b/setup.py index 75680f9d..98ef0cb5 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from setuptools import setup, find_packages +from setuptools import setup, find_namespace_packages project_url = "https://github.com/melexis/sphinx-coverity-extension" @@ -16,7 +16,8 @@ setup( name="mlx.coverity", - use_scm_version=True, + use_scm_version={ + "write_to": "mlx/coverity/__coverity_version__.py"}, url=project_url, license="GNU General Public License v3 (GPLv3)", author="Crt Mori", @@ -44,7 +45,7 @@ "Topic :: Utilities", ], platforms="any", - packages=find_packages(exclude=["tests", "example"]), + packages=find_namespace_packages(include=["mlx.*"]), include_package_data=True, install_requires=requires, namespace_packages=["mlx"], diff --git a/tests/test_coverity.py b/tests/test_coverity.py index 467a18f1..04dd69e8 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -10,8 +10,8 @@ import requests_mock from urllib.parse import urlencode -import mlx.coverity -import mlx.coverity_services +import mlx.coverity.coverity +import mlx.coverity.coverity_services class TestCoverity(TestCase): From db1670785673615c3f14adf2dddd3680c6ac9c72 Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 11:09:43 +0200 Subject: [PATCH 02/13] Fix typo in version --- mlx/coverity/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlx/coverity/__init__.py b/mlx/coverity/__init__.py index 47bdd17f..31a2db2d 100644 --- a/mlx/coverity/__init__.py +++ b/mlx/coverity/__init__.py @@ -10,7 +10,7 @@ "SphinxCoverityConnector", ] -from .__coverity_verion__ import __version__ +from .__coverity_version__ import __version__ from .coverity_logging import report_info, report_warning from .coverity import SphinxCoverityConnector from .coverity_services import CoverityDefectService From 997488cc376513b23892296b5e1664d4aa29293c Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 11:15:14 +0200 Subject: [PATCH 03/13] Fix naming in test --- tests/test_coverity.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_coverity.py b/tests/test_coverity.py index 04dd69e8..d58631f0 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -10,31 +10,31 @@ import requests_mock from urllib.parse import urlencode -import mlx.coverity.coverity -import mlx.coverity.coverity_services +import mlx.coverity.coverity as coverity +import mlx.coverity.coverity_services as coverity_services class TestCoverity(TestCase): def setUp(self): """SetUp to be run before each test to provide clean working env""" - @patch("mlx.coverity_services.requests") + @patch("coverity_services.requests") def test_session_login(self, mock_requests): """Test login function of CoverityDefectService""" mock_requests.return_value = MagicMock(spec=requests) # Get the base url - coverity_conf_service = mlx.coverity_services.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = coverity_services.CoverityDefectService("scan.coverity.com/") self.assertEqual("https://scan.coverity.com/api/v2", coverity_conf_service.api_endpoint) # Login to Coverity coverity_conf_service.login("user", "password") mock_requests.Session.assert_called_once() - @patch.object(mlx.coverity_services.requests.Session, "get") + @patch.object(coverity_services.requests.Session, "get") def test_retrieve_checkers(self, mock_get): """Test retrieving checkers (CoverityDefectService)""" - coverity_conf_service = mlx.coverity_services.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = coverity_services.CoverityDefectService("scan.coverity.com/") # Login to Coverity coverity_conf_service.login("user", "password") @@ -62,7 +62,7 @@ def test_get_defects(self): "checkerAttributedata": [{"key": "checker_key", "value": "checker_value"}], } fake_stream = "test_stream" - coverity_conf_service = mlx.coverity.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = coverity.CoverityDefectService("scan.coverity.com/") # Login to Coverity coverity_conf_service.login("user", "password") @@ -120,7 +120,7 @@ def test_get_defects(self): def test_failed_login(self): fake_stream = "test_stream" - coverity_conf_service = mlx.coverity.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = coverity.CoverityDefectService("scan.coverity.com/") stream_url = f"{coverity_conf_service.api_endpoint.rstrip('/')}/streams/{fake_stream}" with requests_mock.mock() as mocker: From b60647e2e95734b5a33f8eab6c208fdf454beba1 Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 11:30:03 +0200 Subject: [PATCH 04/13] Don't use other names when importing to solve problems importing package with mock --- tests/test_coverity.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_coverity.py b/tests/test_coverity.py index d58631f0..3924ec48 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -10,31 +10,31 @@ import requests_mock from urllib.parse import urlencode -import mlx.coverity.coverity as coverity -import mlx.coverity.coverity_services as coverity_services +import mlx.coverity.coverity +import mlx.coverity.coverity_services class TestCoverity(TestCase): def setUp(self): """SetUp to be run before each test to provide clean working env""" - @patch("coverity_services.requests") + @patch("mlx.coverity.coverity_services.requests") def test_session_login(self, mock_requests): """Test login function of CoverityDefectService""" mock_requests.return_value = MagicMock(spec=requests) # Get the base url - coverity_conf_service = coverity_services.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = mlx.coverity.coverity_services.CoverityDefectService("scan.coverity.com/") self.assertEqual("https://scan.coverity.com/api/v2", coverity_conf_service.api_endpoint) # Login to Coverity coverity_conf_service.login("user", "password") mock_requests.Session.assert_called_once() - @patch.object(coverity_services.requests.Session, "get") + @patch.object(mlx.coverity.coverity_services.requests.Session, "get") def test_retrieve_checkers(self, mock_get): """Test retrieving checkers (CoverityDefectService)""" - coverity_conf_service = coverity_services.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = mlx.coverity.coverity_services.CoverityDefectService("scan.coverity.com/") # Login to Coverity coverity_conf_service.login("user", "password") @@ -62,7 +62,7 @@ def test_get_defects(self): "checkerAttributedata": [{"key": "checker_key", "value": "checker_value"}], } fake_stream = "test_stream" - coverity_conf_service = coverity.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = mlx.coverity.coverity.CoverityDefectService("scan.coverity.com/") # Login to Coverity coverity_conf_service.login("user", "password") @@ -120,7 +120,7 @@ def test_get_defects(self): def test_failed_login(self): fake_stream = "test_stream" - coverity_conf_service = coverity.CoverityDefectService("scan.coverity.com/") + coverity_conf_service = mlx.coverity.coverity.CoverityDefectService("scan.coverity.com/") stream_url = f"{coverity_conf_service.api_endpoint.rstrip('/')}/streams/{fake_stream}" with requests_mock.mock() as mocker: From 8f713e49deb5a9c07545780c1aa5f8ff55c7656f Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 12:47:40 +0200 Subject: [PATCH 05/13] Move write_to for version to toml file --- pyproject.toml | 3 +++ setup.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 17cc83aa..f7a8ec9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ [build-system] requires = ["setuptools-scm", "setuptools"] build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "mlx/coverity/__coverity_version__.py" diff --git a/setup.py b/setup.py index 98ef0cb5..4606626c 100644 --- a/setup.py +++ b/setup.py @@ -16,8 +16,6 @@ setup( name="mlx.coverity", - use_scm_version={ - "write_to": "mlx/coverity/__coverity_version__.py"}, url=project_url, license="GNU General Public License v3 (GPLv3)", author="Crt Mori", From 87d3a53bbada9151f8b0bbc937152fad206dece6 Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 12:48:02 +0200 Subject: [PATCH 06/13] Address deprecation warning about namespace_packages --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 4606626c..4ae06070 100644 --- a/setup.py +++ b/setup.py @@ -43,10 +43,10 @@ "Topic :: Utilities", ], platforms="any", - packages=find_namespace_packages(include=["mlx.*"]), + packages=find_namespace_packages(where="."), + package_dir={"":"."}, include_package_data=True, install_requires=requires, - namespace_packages=["mlx"], keywords=[ "coverity", "reporting", From f95d859cd014b02f81e2915c9d5d7db956035702 Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 16:10:56 +0200 Subject: [PATCH 07/13] Exclude __coverity_version__.py in MANIFEST --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index dd552957..db37a39d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,6 +6,7 @@ include LICENSE include NOTICE include tox.ini recursive-include mlx/coverity *.py +exclude mlx/coverity/__coverity_version__.py recursive-include example *.bat recursive-include example *.py recursive-include example *.rst From c9ad92bd6cd21c4fe6b41a14acade640bb7b4a58 Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 16:16:20 +0200 Subject: [PATCH 08/13] Ignore F401 --- mlx/coverity/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlx/coverity/__init__.py b/mlx/coverity/__init__.py index 31a2db2d..d9fa3e3e 100644 --- a/mlx/coverity/__init__.py +++ b/mlx/coverity/__init__.py @@ -18,4 +18,4 @@ from .coverity_directives.coverity_defect_list import CoverityDefect, CoverityDefectListDirective # provide setup function here for Sphinx -from .coverity import setup # noqa: unused-import +from .coverity import setup # noqa: F401 From c23ba2e08bf31418d900f16b35565d31d3f5560b Mon Sep 17 00:00:00 2001 From: JWM Date: Wed, 14 Aug 2024 16:23:39 +0200 Subject: [PATCH 09/13] Ignore E402 in configuration file --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 0c7e1d90..b6294664 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,7 +11,7 @@ norecursedirs= .tox exclude = .git,*conf.py,build,dist,tests/docs max-line-length = 120 per-file-ignores = - mlx/coverity_directives/coverity_defect_list.py:E402 + */__init__.py: F401 [check-manifest] ignore= From 189c373c36903340d16a03db210b56f90caa8e8f Mon Sep 17 00:00:00 2001 From: JWM Date: Fri, 16 Aug 2024 10:24:00 +0200 Subject: [PATCH 10/13] Fix Flake8 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4ae06070..41942990 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ ], platforms="any", packages=find_namespace_packages(where="."), - package_dir={"":"."}, + package_dir={"": "."}, include_package_data=True, install_requires=requires, keywords=[ From 0a76d720f4e8efe4c8741aa94bb0927083c11307 Mon Sep 17 00:00:00 2001 From: JWM Date: Thu, 22 Aug 2024 11:18:08 +0200 Subject: [PATCH 11/13] Fix import --- tests/test_coverity.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_coverity.py b/tests/test_coverity.py index 7b0b9397..5cfec11a 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -9,8 +9,7 @@ from parameterized import parameterized -from mlx.coverity import SphinxCoverityConnector -from mlx.coverity_services import CoverityDefectService +from mlx.coverity import SphinxCoverityConnector, CoverityDefectService from .filters import test_defect_filter_0, test_defect_filter_1, test_defect_filter_2, test_defect_filter_3 TEST_FOLDER = Path(__file__).parent From bc6b7048d9d88dad90c76fce39af9d502acc3eb0 Mon Sep 17 00:00:00 2001 From: JWM Date: Thu, 22 Aug 2024 11:28:11 +0200 Subject: [PATCH 12/13] Fix patch --- tests/test_coverity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_coverity.py b/tests/test_coverity.py index 5cfec11a..25b63b7e 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -71,7 +71,7 @@ def test_session_by_stream_validation(self): stream_request = mocker.last_request assert stream_request.headers["Authorization"] == requests.auth._basic_auth_str("user", "password") - @patch("mlx.coverity_services.requests") + @patch("mlx.coverity.coverity_services.requests") def test_stream_validation(self, mock_requests): mock_requests.return_value = MagicMock(spec=requests) From f394ba93a6992c0ede406423577537b189e757d7 Mon Sep 17 00:00:00 2001 From: JWM Date: Fri, 23 Aug 2024 14:11:16 +0200 Subject: [PATCH 13/13] Fix importing report_info --- mlx/coverity/coverity_services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlx/coverity/coverity_services.py b/mlx/coverity/coverity_services.py index 5e2ef0df..12132243 100644 --- a/mlx/coverity/coverity_services.py +++ b/mlx/coverity/coverity_services.py @@ -9,7 +9,7 @@ import requests from sphinx.util.logging import getLogger -from mlx.coverity_logging import report_info +from mlx.coverity import report_info # Coverity built in Impact statuses IMPACT_LIST = ["High", "Medium", "Low"]