Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
141
Merge Requests
141
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
fd6fa4a6
Commit
fd6fa4a6
authored
Mar 28, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type: more pylint / astroid fixes
parent
77286e35
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
40 deletions
+44
-40
product/ERP5Type/Tool/ComponentTool.py
product/ERP5Type/Tool/ComponentTool.py
+1
-2
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+2
-3
product/ERP5Type/patches/pylint.py
product/ERP5Type/patches/pylint.py
+34
-25
product/ERP5Type/tests/testDynamicClassGeneration.py
product/ERP5Type/tests/testDynamicClassGeneration.py
+7
-10
No files found.
product/ERP5Type/Tool/ComponentTool.py
View file @
fd6fa4a6
...
...
@@ -163,8 +163,7 @@ class ComponentTool(BaseTool):
if
six
.
PY2
:
from
astroid.builder
import
MANAGER
else
:
from
astroid.builder
import
AstroidManager
MANAGER
=
AstroidManager
()
from
astroid.astroid_manager
import
MANAGER
astroid_cache
=
MANAGER
.
astroid_cache
for
k
in
list
(
astroid_cache
.
keys
()):
if
k
.
startswith
(
'erp5.component.'
)
and
k
not
in
component_package_list
:
...
...
product/ERP5Type/Utils.py
View file @
fd6fa4a6
...
...
@@ -581,10 +581,9 @@ def checkPythonSourceCode(source_code_str, portal_type=None):
finally
:
if
six
.
PY2
:
from
astroid.builder
import
MANAGER
astroid_cache
=
MANAGER
.
astroid_cache
else
:
from
astroid.
manager
import
AstroidManager
astroid_cache
=
AstroidManager
()
.
astroid_cache
from
astroid.
astroid_manager
import
MANAGER
astroid_cache
=
MANAGER
.
astroid_cache
astroid_cache
.
pop
(
os
.
path
.
splitext
(
os
.
path
.
basename
(
input_file
.
name
))[
0
],
None
)
...
...
product/ERP5Type/patches/pylint.py
View file @
fd6fa4a6
...
...
@@ -32,27 +32,25 @@ sys.modules.setdefault('isort', None)
## All arguments are passed as arguments and this needlessly outputs a 'No
## config file found, using default configuration' message on stderr.
try
:
if
six
.
PY2
:
from
logilab.common.configuration
import
OptionsManagerMixIn
except
ImportError
:
# pylint 2.x (python3)
from
pylint.config
import
OptionsManagerMixIn
OptionsManagerMixIn
.
read_config_file
=
lambda
*
args
,
**
kw
:
None
OptionsManagerMixIn
.
read_config_file
=
lambda
*
args
,
**
kw
:
None
## Pylint transforms and plugin to generate AST for ZODB Components
from
astroid.builder
import
AstroidBuilder
from
astroid.exceptions
import
AstroidBuildingException
if
six
.
PY2
:
from
astroid.exceptions
import
AstroidBuildingException
as
AstroidBuildingError
else
:
from
astroid.exceptions
import
AstroidBuildingError
from
astroid
import
node_classes
if
six
.
PY2
:
from
astroid
import
MANAGER
else
:
from
astroid
import
AstroidManager
MANAGER
=
AstroidManager
()
from
astroid.astroid_manager
import
MANAGER
try
:
if
six
.
PY2
:
from
astroid.builder
import
_guess_encoding
except
ImportError
:
# XXX: With python3, tokenize.detect_encoding() is used instead. This
# should do the same instead of copying/pasting legacy code...
import
re
...
...
@@ -67,7 +65,7 @@ except ImportError:
match
=
_ENCODING_RGX
.
match
(
line
)
if
match
is
not
None
:
return
match
.
group
(
1
)
def
string_build
(
self
,
data
,
modname
=
''
,
path
=
None
):
def
string_build
(
self
,
data
,
modname
=
''
,
path
=
None
):
"""
build astroid from source code string and return rebuilded astroid
...
...
@@ -101,11 +99,11 @@ def string_build(self, data, modname='', path=None):
LOG
(
"Products.ERP5Type.patches.pylint"
,
WARNING
,
"%s: Considered as not importable: Wrong encoding? (%r)"
%
(
modname
,
exc
))
raise
AstroidBuildingE
xception
(
exc
)
raise
AstroidBuildingE
rror
(
exc
)
module
=
self
.
_data_build
(
data
,
modname
,
path
)
module
.
file_bytes
=
data
return
self
.
_post_build
(
module
,
encoding
)
AstroidBuilder
.
string_build
=
string_build
AstroidBuilder
.
string_build
=
string_build
# patch node_classes.const_factory not to fail on LazyModules that e.g.
# pygolang installs for pytest and ipython into sys.modules dict:
...
...
@@ -160,17 +158,17 @@ def _buildAstroidModuleFromComponentModuleName(modname):
obj
=
getattr
(
component_tool
,
component_id
.
replace
(
'_version'
,
''
,
1
))
except
AttributeError
:
raise
AstroidBuildingE
xception
()
raise
AstroidBuildingE
rror
()
if
obj
.
getValidationState
()
in
(
'modified'
,
'validated'
):
component_obj
=
obj
else
:
raise
AstroidBuildingE
xception
()
raise
AstroidBuildingE
rror
()
else
:
try
:
package
,
reference
=
component_id
.
split
(
'.'
,
1
)
except
ValueError
:
raise
AstroidBuildingE
xception
()
raise
AstroidBuildingE
rror
()
for
version
in
portal
.
getVersionPriorityNameList
():
try
:
obj
=
getattr
(
component_tool
,
...
...
@@ -189,7 +187,7 @@ def _buildAstroidModuleFromComponentModuleName(modname):
return
module
if
component_obj
is
None
:
raise
AstroidBuildingE
xception
()
raise
AstroidBuildingE
rror
()
# module_build() could also be used but this requires importing
# the ZODB Component and also monkey-patch it to support PEP-302
...
...
@@ -201,7 +199,7 @@ def _buildAstroidModuleFromComponentModuleName(modname):
def
fail_hook_erp5_component
(
modname
):
if
not
modname
.
startswith
(
'erp5.'
):
raise
AstroidBuildingE
xception
()
raise
AstroidBuildingE
rror
()
if
(
modname
in
(
'erp5.portal_type'
,
'erp5.component'
,
...
...
@@ -229,8 +227,11 @@ MANAGER.register_failed_import_hook(fail_hook_erp5_component)
## transforms but this would require either checking dynamically which
## attributes has been added (much more complex than the current approach)
## or listing them statically (inconvenient).
from
astroid.exceptions
import
NotFoundError
from
astroid.scoped_nodes
import
Module
from
astroid.exceptions
import
AstroidError
,
NotFoundError
if
six
.
PY2
:
from
astroid.scoped_nodes
import
Module
else
:
from
astroid.nodes
import
Module
Module_getattr
=
Module
.
getattr
def
_getattr
(
self
,
name
,
*
args
,
**
kw
):
try
:
...
...
@@ -271,17 +272,25 @@ def _getattr(self, name, *args, **kw):
if
self
.
name
==
origin_module_name
:
raise
# ast_from_class() actually works for any attribute of a Module
# ast_from_class() actually works for any attribute of a Module,
# but it raises some AssertionError when the class is defined
# dynamically, for example with zope.hookable.hookable , which
# (in version 6.0) is defined as:
#
# if _PURE_PYTHON or _c_hookable is None:
# hookable = _py_hookable
# else: # pragma: no cover
# hookable = _c_hookable
try
:
ast
=
MANAGER
.
ast_from_class
(
attr
)
except
AstroidBuildingException
:
except
(
AssertionError
,
AstroidError
)
:
raise
e
self
.
locals
[
name
]
=
[
ast
]
return
[
ast
]
Module
.
getattr
=
_getattr
if
s
ys
.
version_info
<
(
2
,
8
)
:
if
s
ix
.
PY2
:
from
astroid.node_classes
import
From
def
_absolute_import_activated
(
self
):
if
(
self
.
name
.
startswith
(
'checkPythonSourceCode'
)
or
...
...
@@ -428,7 +437,7 @@ _inspected_modules = {}
def fail_hook_BTrees(modname):
# Only consider BTrees.OOBTree pattern
if not modname.startswith('
BTrees
.
') or len(modname.split('
.
')) != 2:
raise AstroidBuildingE
xception
()
raise AstroidBuildingE
rror
()
if modname not in _inspected_modules:
try:
modcode = build_stub(
...
...
@@ -444,7 +453,7 @@ def fail_hook_BTrees(modname):
else:
astng = _inspected_modules[modname]
if astng is None:
raise AstroidBuildingE
xception
('
Failed
to
import
module
%
r' % modname)
raise AstroidBuildingE
rror
('
Failed
to
import
module
%
r' % modname)
return astng
MANAGER.register_failed_import_hook(fail_hook_BTrees)
...
...
product/ERP5Type/tests/testDynamicClassGeneration.py
View file @
fd6fa4a6
...
...
@@ -1950,11 +1950,10 @@ class TestZodbModuleComponent(SecurityTestCase):
[
ComponentMixin
.
_message_text_content_not_set
],
[],
[]),
(
"""def foobar(*args, **kwargs)
return 42
(
"""None()
"""
+
valid_code
,
[
"Error in Source Code: E: 1, 0:
invalid syntax (syntax-error
)"
],
[
"E: 1, 0:
invalid syntax (syntax-error
)"
],
[
"Error in Source Code: E: 1, 0:
None is not callable (not-callable
)"
],
[
"E: 1, 0:
None is not callable (not-callable
)"
],
[]),
# Make sure that foobar NameError is at the end to make sure that after
# defining foobar function, it is not available at all
...
...
@@ -2227,8 +2226,7 @@ def function_foo(*args, **kwargs):
if
six
.
PY2
:
from
astroid.builder
import
MANAGER
else
:
from
astroid.builder
import
AstroidManager
MANAGER
=
AstroidManager
()
from
astroid.astroid_manager
import
MANAGER
should_not_be_in_cache_list
=
[]
for
modname
in
MANAGER
.
astroid_cache
:
if
(
modname
.
startswith
(
'checkPythonSourceCode'
)
or
...
...
@@ -2492,8 +2490,8 @@ def hoge():
component
=
self
.
_newComponent
(
reference
)
component
.
setTextContent
(
component
.
getTextContent
()
+
"""
from %(namespace)s import %(reference)s
from %(namespace)s.bar_version import %(reference)s
from %(namespace)s.erp5_version import %(reference)s
from %(namespace)s.bar_version import %(reference)s
# pylint:disable=reimported
from %(namespace)s.erp5_version import %(reference)s
# pylint:disable=reimported
# To avoid 'unused-import' warning...
%(reference)s.hoge()
...
...
@@ -2504,8 +2502,7 @@ from %(namespace)s.erp5_version import %(reference)s
if
six
.
PY2
:
from
astroid.builder
import
MANAGER
else
:
from
astroid.builder
import
AstroidManager
MANAGER
=
AstroidManager
()
from
astroid.astroid_manager
import
MANAGER
imported_module
=
self
.
_getComponentFullModuleName
(
imported_reference
)
self
.
assertEqual
(
MANAGER
.
astroid_cache
[
self
.
_getComponentFullModuleName
(
imported_reference
,
version
=
'bar'
)],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment