aboutcode-org / cwe2

Common weakness enumeration library for Python (maintained fork of https://github.com/Julian-Nash/cwe )
MIT License
11 stars 3 forks source link

Try to cover all CWE List #5

Closed ziadhany closed 1 year ago

pombredanne commented 1 year ago

Here is a patch to avoid using the stdlib for importlib.resources:

diff --git a/requirements.txt b/requirements.txt
index e69de29..7e49a26 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+importlib_resources==5.10.2
+zipp==3.11.0
\ No newline at end of file
diff --git a/setup.cfg b/setup.cfg
index 1e0645c..2addd47 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -40,8 +40,10 @@

 setup_requires = setuptools_scm[toml] >= 4

-python_requires = >=3.6.*
+python_requires = >=3.7

+install_requires =
+    importlib_resources>=5.10.2

 [options.packages.find]
 where = src
diff --git a/src/cwe2/mappings.py b/src/cwe2/mappings.py
index 02428f3..ba5cf9c 100644
--- a/src/cwe2/mappings.py
+++ b/src/cwe2/mappings.py
@@ -5,7 +5,7 @@
 # See https://github.com/nexB/cwe2 for support or download.
 # See https://aboutcode.org for more information about nexB OSS projects.
 #
-import importlib.resources
+import importlib_resources
 import os

@@ -24,12 +24,12 @@
     :raises FileNotFoundError: In case the file in `resource` is not
                                found in the package.
     """
-    # Guard against non-existing files, or else importlib.resources.path
+    # Guard against non-existing files, or else importlib_resources.path
     # may raise a confusing TypeError.
-    if not importlib.resources.is_resource(package, resource):
+    if not importlib_resources.is_resource(package, resource):
         raise FileNotFoundError(f"Python package '{package}' resource '{resource}' not found.")

-    with importlib.resources.path(package, resource) as resource_path:
+    with importlib_resources.path(package, resource) as resource_path:
         return os.fspath(resource_path)