From 34e1f8cd89a9d274a380afb8a81732167205f2a1 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 10 Apr 2026 12:19:03 -0700 Subject: [PATCH 1/7] remove star import in __init__ --- mkl/__init__.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/mkl/__init__.py b/mkl/__init__.py index 635b707..df70f04 100644 --- a/mkl/__init__.py +++ b/mkl/__init__.py @@ -57,7 +57,83 @@ def __exit__(self, *args): del RTLD_for_MKL del sys -from ._py_mkl_service import * +from ._py_mkl_service import ( + get_version, + get_version_string, + set_num_threads, + domain_set_num_threads, + set_num_threads_local, + set_dynamic, + get_max_threads, + domain_get_max_threads, + get_dynamic, + set_num_stripes, + get_num_stripes, + second, + dsecnd, + get_cpu_clocks, + get_cpu_frequency, + get_max_cpu_frequency, + get_clocks_frequency, + free_buffers, + thread_free_buffers, + disable_fast_mm, + mem_stat, + peak_mem_usage, + set_memory_limit, + cbwr_set, + cbwr_get, + cbwr_get_auto_branch, + enable_instructions, + set_env_mode, + get_env_mode, + verbose, + set_mpi, + vml_set_mode, + vml_get_mode, + vml_set_err_status, + vml_get_err_status, + vml_clear_err_status, +) from ._version import __version__ +__all__ = [ + "get_version", + "get_version_string", + "set_num_threads", + "domain_set_num_threads", + "set_num_threads_local", + "set_dynamic", + "get_max_threads", + "domain_get_max_threads", + "get_dynamic", + "set_num_stripes", + "get_num_stripes", + "second", + "dsecnd", + "get_cpu_clocks", + "get_cpu_frequency", + "get_max_cpu_frequency", + "get_clocks_frequency", + "free_buffers", + "thread_free_buffers", + "disable_fast_mm", + "mem_stat", + "peak_mem_usage", + "set_memory_limit", + "cbwr_set", + "cbwr_get", + "cbwr_get_auto_branch", + "enable_instructions", + "set_env_mode", + "get_env_mode", + "verbose", + "set_mpi", + "vml_set_mode", + "vml_get_mode", + "vml_set_err_status", + "vml_get_err_status", + "vml_clear_err_status" +] + del _init_helper From b8584cc8d50a960f9c3528736d25ae75cb78ab76 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 10 Apr 2026 17:24:41 -0700 Subject: [PATCH 2/7] add black and isort settings to pyproject.toml --- pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index cb8a5f2..f14b964 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,6 +72,17 @@ test = ["pytest"] Download = "http://github.com/IntelPython/mkl-service" Homepage = "http://github.com/IntelPython/mkl-service" +[tool.black] +line-length = 80 + +[tool.isort] +ensure_newline_before_comments = true +force_grid_wrap = 0 +include_trailing_comma = true +line_length = 80 +multi_line_output = 3 +use_parentheses = true + [tool.setuptools] include-package-data = true packages = ["mkl"] From 5045ed9c6b39fa1747cdae2719477e5a596f0d3b Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 10 Apr 2026 17:24:50 -0700 Subject: [PATCH 3/7] fix setup.py for linter --- setup.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 23bac56..0362197 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,10 @@ def extensions(): if mkl_root: mkl_info = { "include_dirs": [join(mkl_root, "include")], - "library_dirs": [join(mkl_root, "lib"), join(mkl_root, "lib", "intel64")], + "library_dirs": [ + join(mkl_root, "lib"), + join(mkl_root, "lib", "intel64"), + ], "libraries": ["mkl_rt"], } else: @@ -62,7 +65,8 @@ def extensions(): "mkl._mklinit", sources=[join("mkl", "_mklinitmodule.c")], include_dirs=mkl_include_dirs, - libraries=mkl_libraries + (["pthread"] if os.name == "posix" else []), + libraries=mkl_libraries + + (["pthread"] if os.name == "posix" else []), library_dirs=mkl_library_dirs, runtime_library_dirs=mkl_rpaths, extra_compile_args=[ From ff26c3b2394de86cca466e11519f4e9f1b596602 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 10 Apr 2026 17:25:46 -0700 Subject: [PATCH 4/7] lazily import sys in RTLD_for_MKL prevents linter from triggering --- mkl/__init__.py | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/mkl/__init__.py b/mkl/__init__.py index df70f04..c0eb2ae 100644 --- a/mkl/__init__.py +++ b/mkl/__init__.py @@ -23,8 +23,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import sys - from . import _init_helper @@ -34,6 +32,7 @@ def __init__(self): def __enter__(self): import ctypes + import sys try: self.saved_rtld = sys.getdlopenflags() @@ -46,6 +45,8 @@ def __enter__(self): del ctypes def __exit__(self, *args): + import sys + if self.saved_rtld: sys.setdlopenflags(self.saved_rtld) self.saved_rtld = None @@ -55,45 +56,44 @@ def __exit__(self, *args): from . import _mklinit del RTLD_for_MKL -del sys from ._py_mkl_service import ( - get_version, - get_version_string, - set_num_threads, - domain_set_num_threads, - set_num_threads_local, - set_dynamic, - get_max_threads, + cbwr_get, + cbwr_get_auto_branch, + cbwr_set, + disable_fast_mm, domain_get_max_threads, - get_dynamic, - set_num_stripes, - get_num_stripes, - second, + domain_set_num_threads, dsecnd, + enable_instructions, + free_buffers, + get_clocks_frequency, get_cpu_clocks, get_cpu_frequency, + get_dynamic, + get_env_mode, get_max_cpu_frequency, - get_clocks_frequency, - free_buffers, - thread_free_buffers, - disable_fast_mm, + get_max_threads, + get_num_stripes, + get_version, + get_version_string, mem_stat, peak_mem_usage, - set_memory_limit, - cbwr_set, - cbwr_get, - cbwr_get_auto_branch, - enable_instructions, + second, + set_dynamic, set_env_mode, - get_env_mode, - verbose, + set_memory_limit, set_mpi, - vml_set_mode, + set_num_stripes, + set_num_threads, + set_num_threads_local, + thread_free_buffers, + verbose, + vml_clear_err_status, + vml_get_err_status, vml_get_mode, vml_set_err_status, - vml_get_err_status, - vml_clear_err_status, + vml_set_mode, ) from ._version import __version__ @@ -133,7 +133,7 @@ def __exit__(self, *args): "vml_get_mode", "vml_set_err_status", "vml_get_err_status", - "vml_clear_err_status" + "vml_clear_err_status", ] del _init_helper From b0752ec982e832117a703e9ea5c225225982389e Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 10 Apr 2026 17:26:56 -0700 Subject: [PATCH 5/7] add setup.py linting commit to git-blame-ignore --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index dee049e..4af13c8 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -8,3 +8,6 @@ # Move to clang-format-22 6056b26ff82dfd156708fd7d3680470d9ba3c9ce + +# Clean up in setup.py +5045ed9c6b39fa1747cdae2719477e5a596f0d3b From d68825c90adc9597f896b02fbafc802ec2356e89 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sun, 12 Apr 2026 12:05:59 -0700 Subject: [PATCH 6/7] add gh-178 to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7994fc..8e8f882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Dropped support for Python 3.9 [gh-118](https://github.com/IntelPython/mkl-service/pull/118) * Dropped support for `"ssse3"`, `"sse4_1"`, `"avx"`, `"avx512_mic"`, `"avx512_mic,strict"`, and `"avx512_mic_e1"` cbwr branches [gh-173](https://github.com/IntelPython/mkl-service/pull/173) +### Fixed +* Removed use of star import in `mkl-service` initialization, which removes imported module pollution from the namespace [gh-178](https://github.com/IntelPython/mkl-service/pull/178) + ## [2.6.1] (11/25/2025) ### Fixed From ac1a385ef522ae76df17b4ec4721906fced8a963 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 13 Apr 2026 10:41:50 -0700 Subject: [PATCH 7/7] address review comments --- .flake8 | 2 -- pyproject.toml | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.flake8 b/.flake8 index adfe1ae..2d37f05 100644 --- a/.flake8 +++ b/.flake8 @@ -4,8 +4,6 @@ extend-ignore = E203, # line too long (in docstrings): E501, - # ‘from module import *’ used; unable to detect undefined names: - F403, # doc line too long (105 > 80 characters): W505, # missing docstring in public module: diff --git a/pyproject.toml b/pyproject.toml index f14b964..fcf5cf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,12 +76,8 @@ Homepage = "http://github.com/IntelPython/mkl-service" line-length = 80 [tool.isort] -ensure_newline_before_comments = true -force_grid_wrap = 0 -include_trailing_comma = true line_length = 80 -multi_line_output = 3 -use_parentheses = true +profile = "black" [tool.setuptools] include-package-data = true