Enhanced resiliency of PyPI scanning tool
PATCH 1/1 Enhanced resiliency of PyPI scanning tool
In reply to a message not in the archiveHi Malachi,
Quoted 4 lines · Malachi Burke
Specifically during scenarios where (probably older) python packages don't explicitly specify their name during
setup.pyprocessing, we can fallback and usemetadata_nameto tracksetup_args
Please provide URL for such a package.
Quoted 38 lines
Signed-off-by Malachi Burke <[email protected]>--- utils/scanpypi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)utils/scanpypi +12
-2@@ -45,6 +45,13 @@ except ImportError: liclookup = None +# Ugly global representing currently evaluating package +# need this because some packages don't specify their name +# fortunately BuildrootPackage operates iteratively and not +# recursively, so managing this is straightforward +current_package = None + + def setup_decorator(func, method): """ Decorator for distutils.core.setup and setuptools.setup.@@ -60,8 +67,11 @@ def setup_decorator(func, method): def closure(*args, **kwargs): # Any python packages calls its setup function to be installed. # Argument 'name' of this setup function is the package's name - BuildrootPackage.setup_args[kwargs['name']] = kwargs - BuildrootPackage.setup_args[kwargs['name']]['method'] = method + # When 'name' isn't available, we query current_package + name = kwargs.get('name', current_package.metadata_name) + + BuildrootPackage.setup_args[name] = kwargs + BuildrootPackage.setup_args[name]['method'] = method return closure # monkey patch
utils/scanpypi class BuildrootPackage(): · line 291
Quoted 4 lines
utils/scanpypi +1
-0@@ -278,6 +288,8 @@ class BuildrootPackage(): current_dir = os.getcwd() os.chdir(self.tmp_extract) sys.path.append(self.tmp_extract) + global current_package
Can we avoid using 'global' construct?
Yegor
Quoted 7 lines
utils/scanpypi +1
-1+ current_package = self s_file, s_path, s_desc = imp.find_module('setup', [self.tmp_extract]) setup = imp.load_module('setup', s_file, s_path, s_desc) try: --2.18.0
PATCH 1/1 Enhanced resiliency of PyPI scanning tool
Hi Thomas,
Quoted 46 lines · Yegor Yefremov
Hi Malachi,
Quoted 4 lines · Malachi Burke
Specifically during scenarios where (probably older) python packages don't explicitly specify their name during
setup.pyprocessing, we can fallback and usemetadata_nameto tracksetup_argsPlease provide URL for such a package.
Quoted 36 lines
Signed-off-by Malachi Burke <[email protected]>--- utils/scanpypi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)utils/scanpypi +12
-2@@ -45,6 +45,13 @@ except ImportError: liclookup = None +# Ugly global representing currently evaluating package +# need this because some packages don't specify their name +# fortunately BuildrootPackage operates iteratively and not +# recursively, so managing this is straightforward +current_package = None + + def setup_decorator(func, method): """ Decorator for distutils.core.setup and setuptools.setup.@@ -60,8 +67,11 @@ def setup_decorator(func, method): def closure(*args, **kwargs): # Any python packages calls its setup function to be installed. # Argument 'name' of this setup function is the package's name - BuildrootPackage.setup_args[kwargs['name']] = kwargs - BuildrootPackage.setup_args[kwargs['name']]['method'] = method + # When 'name' isn't available, we query current_package + name = kwargs.get('name', current_package.metadata_name) + + BuildrootPackage.setup_args[name] = kwargs + BuildrootPackage.setup_args[name]['method'] = method return closure
Quoted 8 lines
utils/scanpypi class BuildrootPackage(): · line 291
Quoted 6 lines
utils/scanpypi +1
-0# monkey patch@@ -278,6 +288,8 @@ class BuildrootPackage(): current_dir = os.getcwd() os.chdir(self.tmp_extract) sys.path.append(self.tmp_extract) + global current_packageCan we avoid using 'global' construct?
What do you think about this patch/issue?
Malachi pointed me to the mock package [1]. Its setup.py is missing 'name' keyword. I've sent a PR [2] fixing this, but the project doesn't seem to actively maintained.
We already had a similar discussion [3]. The decision was to avoid fixing such things by scanpypi and just to inform the user, that the package is malformed. I could add related error messages to the except clauses.
[1] https://github.com/testing-cabal/mock
[2] https://github.com/testing-cabal/mock/pull/433
[3] http://lists.busybox.net/pipermail/buildroot/2018-January/212333.html
Regards,
Yegor