Skip to content

Commit

Permalink
[FIX] misc.py: Properly support python namespace package when detecti…
Browse files Browse the repository at this point in the history
…ng the odoo addon directory (#317)

More info about http://peak.telecommunity.com/DevCenter/setuptools#namespace-packagestry

fix #316
  • Loading branch information
lmignon committed Jan 19, 2021
1 parent 9504bf0 commit 1ac6e49
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pylint_odoo/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def get_manifest_file(self, node):
# Get 'module' part from node.name 'module.models.file'
module_path = node.file
node_name = node.name
if "odoo.addons." in node_name:
# we are into a namespace package...
node_name = node_name.split("odoo.addons.")[1]
if os.path.basename(node.file) == '__init__.py':
node_name += '.__init__'
for _ in range(node_name.count('.')):
Expand Down Expand Up @@ -186,6 +189,9 @@ def _check_{NAME_KEY}(self, module_path)
self.odoo_node = node
self.odoo_module_name = os.path.basename(
os.path.dirname(manifest_file))
self.odoo_module_name_with_ns = "odoo.addons.{}".format(
self.odoo_module_name
)
with open(self.manifest_file) as f_manifest:
self.manifest_dict = ast.literal_eval(f_manifest.read())
elif self.odoo_node and os.path.commonprefix(
Expand All @@ -199,7 +205,10 @@ def _check_{NAME_KEY}(self, module_path)
self.manifest_dict = {}
self.manifest_file = None
self.is_main_odoo_module = False
if self.manifest_file and node.name.count('.') == 0:
if self.manifest_file and (
node.name.count('.') == 0 or
node.name.endswith(self.odoo_module_name_with_ns)
):
self.is_main_odoo_module = True
self.node = node
self.module_path = os.path.dirname(node.file)
Expand Down
16 changes: 16 additions & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def setUp(self):
root, dirs, _ = six.next(os.walk(path_modules))
for path in dirs:
self.paths_modules.append(os.path.join(root, path))
self.odoo_namespace_addons_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
'test_repo_odoo_namespace', 'odoo')
self.default_extra_params = [
'--disable=all',
'--enable=odoolint,pointless-statement,trailing-newlines',
Expand Down Expand Up @@ -342,6 +345,19 @@ def test_120_import_error_skip(self):
real_errors_120 = pylint_res.linter.stats['by_msg']
self.assertFalse(real_errors_120)

def test_130_odoo_namespace_repo(self):
extra_params = [
'--valid_odoo_versions=12.0',
'--disable=all',
'--enable=po-msgstr-variables,missing-readme',
]
pylint_res = self.run_pylint([self.odoo_namespace_addons_path], extra_params)
real_errors = pylint_res.linter.stats['by_msg']
self.assertDictEqual(
real_errors,
{"po-msgstr-variables": 1, "missing-readme": 1}
)


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions pylint_odoo/test_repo_odoo_namespace/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
7 changes: 7 additions & 0 deletions pylint_odoo/test_repo_odoo_namespace/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'name': 'Namespace package module for tests',
'license': 'AGPL-3',
'author': u'Vauxoo,Odoo Community Association (OCA)',
'version': '12.0.1.0.0',
'depends': [
'base',
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 1985-04-14 17:12+0000\n"
"PO-Revision-Date: 1985-04-14 02:03+0000\n"
"Last-Translator: Moisés López <moylop260@vauxoo.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: test_module
#: model:ir.model.fields,field_description2:test_module.field_description2
#: model:ir.model.fields,field_description2:test_module.field_description2
#, python-format
msgid "Correct variables %s"
msgstr "Correct variables"

0 comments on commit 1ac6e49

Please sign in to comment.