Skip to content

Commit

Permalink
TA#63117 [IMP] Add precommit, flake8 and github workflow (#109)
Browse files Browse the repository at this point in the history
* TA#63117 [IMP] Add precommit, flake8 and github workflow

* TA#63117 [IMP] Correct flake8 errors
  • Loading branch information
majouda authored Mar 4, 2024
1 parent 0d52fda commit b539c2d
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 161 deletions.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
max-line-length = 88
max-complexity = 16
# B = bugbear
# B9 = bugbear opinionated (incl line length)
select = C,E,F,W,B,B9
# E203: whitespace before ':' (black behaviour)
# E501: flake8 line length (covered by bugbear B950)
# W503: line break before binary operator (black behaviour)
ignore = E203,E501,W503,F821
per-file-ignores=
__init__.py:F401
36 changes: 36 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: pre-commit

on:
pull_request:
branches:
- "14.0*"
push:
branches:
- "14.0"

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always
- name: Check that all files generated by pre-commit are in git
run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)"
if [ "$newfiles" != "" ] ; then
echo "Please check-in the following files:"
echo "$newfiles"
exit 1
fi
37 changes: 28 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
# We don't want to mess with tool-generated files
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|
# Maybe reactivate this when all README files include prettier ignore tags?
^README\.md$|
# Library files can have extraneous formatting (even minimized)
/static/(src/)?lib/|
# Repos using Sphinx to generate docs don't need prettying
^docs/_templates/.*\.html$|
# Don't bother non-technical authors with formatting issues in docs
readme/.*\.(rst|md)$|
# Ignore build and dist directories in addons
/build/|/dist/|
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)
default_language_version:
python: python3
node: "14.13.0"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
17 changes: 0 additions & 17 deletions .unported_addons/web_search_input_many2many/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions .unported_addons/web_search_input_many2many/__init__.py

This file was deleted.

18 changes: 0 additions & 18 deletions .unported_addons/web_search_input_many2many/__manifest__.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
environment:
- LOG_ODOO=/var/log/odoo
db:
image: postgres:9.6
image: postgres:16.0
environment:
- POSTGRES_PASSWORD=odoo
- POSTGRES_USER=odoo
Expand Down
5 changes: 4 additions & 1 deletion google_attachment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"depends": ["base_setup", "mail"],
"data": ["views/assets.xml", "views/res_config_settings.xml",],
"data": [
"views/assets.xml",
"views/res_config_settings.xml"
],
"qweb": [
"static/src/components/google_attachment.xml",
"static/src/components/attachment_box.xml",
Expand Down
12 changes: 10 additions & 2 deletions web_custom_label/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ def _set_single_custom_field_helper(label, fields):


def _iter_field_labels_with_position(labels, position):
return (l for l in labels if l['type_'] == 'field' and l['position'] == position)
return (
label
for label in labels
if label["type_"] == "field" and label["position"] == position
)


def _set_custom_selection_labels(labels, fields):
selection_labels = (l for l in labels if l['type_'] == 'field' and l['position'] == 'selection')
selection_labels = (
label
for label in labels
if label["type_"] == "field" and label["position"] == "selection"
)
for label in selection_labels:
_set_single_custom_selection_label(label, fields)

Expand Down
12 changes: 9 additions & 3 deletions web_custom_label/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from lxml import etree
from odoo import api, models
from odoo import models
from .common import set_custom_labels_on_fields


Expand All @@ -11,7 +11,9 @@ class ViewWithCustomLabels(models.Model):
_inherit = 'ir.ui.view'

def _postprocess_view(self, node, model, validate=True, editable=True):
arch, name_manager = super()._postprocess_view(node, model, validate=validate, editable=editable)
arch, name_manager = super()._postprocess_view(
node, model, validate=validate, editable=editable
)
lang = self.env.context.get('lang') or self.env.user.lang
labels = self.env['web.custom.label'].get(model, lang)

Expand All @@ -21,7 +23,11 @@ def _postprocess_view(self, node, model, validate=True, editable=True):


def _add_custom_labels_to_view_arch(labels, arch):
labels_to_apply = [l for l in labels if l['position'] in ('string', 'placeholder', 'help')]
labels_to_apply = [
label
for label in labels
if label["position"] in ("string", "placeholder", "help")
]

if not labels_to_apply:
return arch
Expand Down
4 changes: 3 additions & 1 deletion web_custom_modifier/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def postprocess(self, node, current_node_path, editable, name_manager):
modifiers, node)
set_custom_modifiers_on_fields(modifiers, name_manager.available_fields)
self.clear_caches() # Clear the cache in order to recompute _get_active_rules
return super().postprocess(node_with_custom_modifiers, current_node_path, editable, name_manager)
return super().postprocess(
node_with_custom_modifiers, current_node_path, editable, name_manager
)


def _add_custom_modifiers_to_view_arch(modifiers, arch):
Expand Down
4 changes: 3 additions & 1 deletion web_editor_backend_context/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"category": "Web",
"summary": "Fix the user context for web editor assets",
"depends": ["web_editor"],
"data": ["views/assets.xml",],
"data": [
"views/assets.xml"
],
"installable": True,
"auto_install": True,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class ControlPanelExtension extends ControlPanel {

_addDateRangeFilters() {
const pregroup = [...this.dateRangeFilters]
this._createGroupOfFilters(pregroup);
if (pregroup.length) {
this._createGroupOfFilters(pregroup);
}
}

_enrichFilterCopy(filter, filterQueryElements) {
Expand Down
4 changes: 3 additions & 1 deletion web_search_date_range/tests/test_search_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def setUpClass(cls):
cls.field = cls.env.ref('base.field_res_partner__create_date')

def _eval_filter_domain(self, range_ref):
date_range = self.env.ref('web_search_date_range.{range_ref}'.format(range_ref=range_ref))
date_range = self.env.ref(
"web_search_date_range.{range_ref}".format(range_ref=range_ref)
)
return date_range.generate_domain(self.field.name)

def test_eval_domain_for_range_before_today(self):
Expand Down
4 changes: 3 additions & 1 deletion web_search_date_range_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"category": "Project",
"summary": "Add accounting date range filters.",
"depends": ["web_search_date_range", "account"],
"data": ["data/search_date_range.xml",],
"data": [
"data/search_date_range.xml"
],
"installable": True,
}
2 changes: 1 addition & 1 deletion web_search_date_range_account/tests/test_date_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUpClass(cls):
cls.model = cls.env.ref("base.model_res_partner")
cls.field = cls.env.ref("base.field_res_partner__create_date")
cls.env.user.company_id.write(
{"fiscalyear_last_month": "3", "fiscalyear_last_day": "31",}
{"fiscalyear_last_month": "3", "fiscalyear_last_day": "31"}
)

def _eval_filter_domain(self, range_ref):
Expand Down
29 changes: 23 additions & 6 deletions website_blog_internal/controllers/website_blog_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,34 @@ class WebsiteBlogInternal(WebsiteBlog):
def blog(self, blog=None, tag=None, page=1, search=None, **opt):
if not http.request.env.user.has_group("base.group_user"):
raise NotFound()
return super(WebsiteBlogInternal, self).blog(blog=blog, tag=tag, page=page, **opt)
return super(WebsiteBlogInternal, self).blog(
blog=blog, tag=tag, page=page, **opt
)

@http.route(['''/blog/<model("blog.blog"):blog>/feed'''], type='http', auth="user", website=True, sitemap=True)
@http.route(
["""/blog/<model("blog.blog"):blog>/feed"""],
type="http",
auth="user",
website=True,
sitemap=True,
)
def blog_feed(self, blog, limit="15", **kwargs):
if not http.request.env.user.has_group("base.group_user"):
raise NotFound()
return super(WebsiteBlogInternal, self).blog_feed(blog=blog, limit=limit, **kwargs)
return super(WebsiteBlogInternal, self).blog_feed(
blog=blog, limit=limit, **kwargs
)

@http.route([
'''/blog/<model("blog.blog"):blog>/<model("blog.post", "[('blog_id','=',blog.id)]"):blog_post>''',
], type='http', auth="user", website=True, sitemap=True)
@http.route(
[
"""/blog/<model("blog.blog"):blog>/<model("blog.post",
"[('blog_id','=',blog.id)]"):blog_post>"""
],
type="http",
auth="user",
website=True,
sitemap=True,
)
def blog_post(
self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **post
):
Expand Down
Loading

0 comments on commit b539c2d

Please sign in to comment.