Skip to content

Commit

Permalink
[REF] website-manifest-key-not-valid-uri: Remove dependency to valida…
Browse files Browse the repository at this point in the history
…tors

Adding the same regex to validate URL
  • Loading branch information
moylop260 committed Jan 15, 2025
1 parent a203775 commit aa5207f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ translation-too-few-args | Not enough arguments for odoo._ format string | E8306
translation-too-many-args | Too many arguments for odoo._ format string | E8305
translation-unsupported-format | Unsupported odoo._ format character %r (%#02x) at index %d | E8300
use-vim-comment | Use of vim comment | W8202
website-manifest-key-not-valid-uri | Website "%s" in manifest key is not a valid URI | W8114
website-manifest-key-not-valid-uri | Website "%s" in manifest key is not a valid URI. %s | W8114


[//]: # (end-checks)
Expand Down Expand Up @@ -394,7 +394,8 @@ Checks valid only for odoo <= 13.0

* website-manifest-key-not-valid-uri

- https://github.com/OCA/pylint-odoo/blob/v9.3.1/testing/resources/test_repo/broken_module3/__openerp__.py#L7 Website "htt://odoo-community.com" in manifest key is not a valid URI
- https://github.com/OCA/pylint-odoo/blob/v9.3.1/testing/resources/test_repo/broken_module2/__openerp__.py#L7 Website "https://odoo-community.org,https://odoo.com" in manifest key is not a valid URI. Domain 'odoo-community.org,https:' contains invalid characters
- https://github.com/OCA/pylint-odoo/blob/v9.3.1/testing/resources/test_repo/broken_module3/__openerp__.py#L7 Website "htt://odoo-community.com" in manifest key is not a valid URI. URL needs to start with 'http[s]://'

[//]: # (end-example)

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pylint-plugin-utils==0.8.*
pylint==3.3.*
validators==0.34.*
18 changes: 12 additions & 6 deletions src/pylint_odoo/checkers/odoo_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
import string
from collections import Counter, defaultdict

import validators
from astroid import ClassDef, FunctionDef, NodeNG, nodes
from pylint.checkers import BaseChecker, utils
from pylint.lint import PyLinter
Expand Down Expand Up @@ -217,7 +216,7 @@
CHECK_DESCRIPTION,
),
"W8114": (
'Website "%s" in manifest key is not a valid URI',
'Website "%s" in manifest key is not a valid URI. %s',
"website-manifest-key-not-valid-uri",
CHECK_DESCRIPTION,
),
Expand Down Expand Up @@ -1157,11 +1156,18 @@ def visit_dict(self, node):
self.add_message("missing-readme", args=(self.linter.config.readme_template_url,), node=node)

# Check if the website is valid URI
website = manifest_dict.get("website", "")
url_is_valid = bool(validators.url(website))
if website and "," not in website and not url_is_valid:
website = manifest_dict.get("website") or ""
msg = ""
url_is_valid = False
try:
url_is_valid = misc.validate_url(website)
except misc.InvalidURL as url_exc:
msg = str(url_exc)
if website and not url_is_valid:
self.add_message(
"website-manifest-key-not-valid-uri", node=manifest_keys_nodes.get("website") or node, args=(website)
"website-manifest-key-not-valid-uri",
node=manifest_keys_nodes.get("website") or node,
args=(website, msg),
)

# Check valid development_status values
Expand Down
2 changes: 2 additions & 0 deletions src/pylint_odoo/misc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import re
import subprocess
import sys
from contextlib import contextmanager
from functools import lru_cache
from pathlib import Path
from urllib.parse import urlsplit

MANIFEST_DATA_KEYS = ["data", "demo", "demo_xml", "init_xml", "test", "update_xml"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"translation-too-many-args": 2,
"translation-unsupported-format": 2,
"use-vim-comment": 1,
"website-manifest-key-not-valid-uri": 1,
"website-manifest-key-not-valid-uri": 2,
"no-raise-unlink": 2,
"deprecated-odoo-model-method": 2,
"manifest-behind-migrations": 3,
Expand Down

0 comments on commit aa5207f

Please sign in to comment.