Merge PR #176 into 14.0

Signed-off-by thomaspaulb
This commit is contained in:
OCA-git-bot 2023-12-19 20:38:09 +00:00
commit bbcd058061
14 changed files with 86 additions and 78 deletions

View File

@ -1,8 +1,9 @@
# Do NOT update manually; changes here will be overwritten by Copier # Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.14.2 _commit: v1.20
_src_path: gh:oca/oca-addons-repo-template _src_path: gh:oca/oca-addons-repo-template
additional_ruff_rules: []
ci: GitHub ci: GitHub
dependency_installation_mode: PIP convert_readme_fragments_to_markdown: false
generate_requirements_txt: true generate_requirements_txt: true
github_check_license: true github_check_license: true
github_ci_extra_env: {} github_ci_extra_env: {}
@ -11,15 +12,15 @@ github_enable_makepot: true
github_enable_stale_action: true github_enable_stale_action: true
github_enforce_dev_status_compatibility: true github_enforce_dev_status_compatibility: true
include_wkhtmltopdf: false include_wkhtmltopdf: false
odoo_test_flavor: Both
odoo_version: 14.0 odoo_version: 14.0
org_name: Odoo Community Association (OCA) org_name: Odoo Community Association (OCA)
org_slug: OCA org_slug: OCA
rebel_module_groups: [] rebel_module_groups: []
repo_description: null repo_description: Tools to manage environment-dependent configuration
repo_name: server-env repo_name: server-env
repo_slug: server-env repo_slug: server-env
repo_website: https://github.com/OCA/server-env repo_website: https://github.com/OCA/server-env
travis_apt_packages: use_pyproject_toml: false
- xmlsec1 use_ruff: true
travis_apt_sources: []

View File

@ -22,6 +22,7 @@ globals:
odoo: readonly odoo: readonly
openerp: readonly openerp: readonly
owl: readonly owl: readonly
luxon: readonly
# Styling is handled by Prettier, so we only need to enable AST rules; # Styling is handled by Prettier, so we only need to enable AST rules;
# see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890 # see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890

12
.flake8
View File

@ -1,12 +0,0 @@
[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
per-file-ignores=
__init__.py:F401

View File

@ -13,8 +13,10 @@ jobs:
pre-commit: pre-commit:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-python@v2 - uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Get python version - name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1 - uses: actions/cache@v1
@ -25,6 +27,15 @@ jobs:
run: pip install pre-commit run: pip install pre-commit
- name: Run pre-commit - name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always run: pre-commit run --all-files --show-diff-on-failure --color=always
env:
# Consider valid a PR that changes README fragments but doesn't
# change the README.rst file itself. It's not really a problem
# because the bot will update it anyway after merge. This way, we
# lower the barrier for functional contributors that want to fix the
# readme fragments, while still letting developers get README
# auto-generated (which also helps functionals when using runboat).
# DOCS https://pre-commit.com/#temporarily-disabling-hooks
SKIP: oca-gen-addon-readme
- name: Check that all files generated by pre-commit are in git - name: Check that all files generated by pre-commit are in git
run: | run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)" newfiles="$(git ls-files --others --exclude-from=.gitignore)"

View File

@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Detect unreleased dependencies name: Detect unreleased dependencies
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- run: | - run: |
for reqfile in requirements.txt test-requirements.txt ; do for reqfile in requirements.txt test-requirements.txt ; do
if [ -f ${reqfile} ] ; then if [ -f ${reqfile} ] ; then
@ -36,10 +36,10 @@ jobs:
matrix: matrix:
include: include:
- container: ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest - container: ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest
makepot: "true"
name: test with Odoo name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb14.0:latest - container: ghcr.io/oca/oca-ci/py3.6-ocb14.0:latest
name: test with OCB name: test with OCB
makepot: "true"
services: services:
postgres: postgres:
image: postgres:9.6 image: postgres:9.6
@ -50,7 +50,7 @@ jobs:
ports: ports:
- 5432:5432 - 5432:5432
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
persist-credentials: false persist-credentials: false
- name: Install addons and dependencies - name: Install addons and dependencies

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ __pycache__/
*.py[cod] *.py[cod]
/.venv /.venv
/.pytest_cache /.pytest_cache
/.ruff_cache
# C extensions # C extensions
*.so *.so

View File

@ -1,13 +0,0 @@
[settings]
; see https://github.com/psf/black
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
use_parentheses=True
line_length=88
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
default_section=THIRDPARTY
ensure_newline_before_comments = True

2
.oca_hooks.cfg Normal file
View File

@ -0,0 +1,2 @@
[MESSAGES_CONTROL]
disable=xml-deprecated-data-node,xml-deprecated-tree-attribute

View File

@ -14,6 +14,10 @@ exclude: |
/tests/fixtures/| /tests/fixtures/|
# Repos using Sphinx to generate docs don't need prettying # Repos using Sphinx to generate docs don't need prettying
^docs/_templates/.*\.html$| ^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 # You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*) (LICENSE.*|COPYING.*)
default_language_version: default_language_version:
@ -35,27 +39,25 @@ repos:
language: fail language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$' files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools - repo: https://github.com/oca/maintainer-tools
rev: ab1d7f6 rev: 9a170331575a265c092ee6b24b845ec508e8ef75
hooks: hooks:
# update the NOT INSTALLABLE ADDONS section above # update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons - id: oca-update-pre-commit-excluded-addons
- id: oca-fix-manifest-website - id: oca-fix-manifest-website
args: ["https://github.com/OCA/server-env"] args: ["https://github.com/OCA/server-env"]
- repo: https://github.com/myint/autoflake - id: oca-gen-addon-readme
rev: v1.4
hooks:
- id: autoflake
args: args:
- --expand-star-imports - --addons-dir=.
- --ignore-init-module-imports - --branch=14.0
- --in-place - --org-name=OCA
- --remove-all-unused-imports - --repo-name=server-env
- --remove-duplicate-keys - --if-source-changed
- --remove-unused-variables - --keep-source-digest
- repo: https://github.com/psf/black - repo: https://github.com/OCA/odoo-pre-commit-hooks
rev: 22.3.0 rev: v0.0.25
hooks: hooks:
- id: black - id: oca-checks-odoo-module
- id: oca-checks-po
- repo: https://github.com/pre-commit/mirrors-prettier - repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.1.2 rev: v2.1.2
hooks: hooks:
@ -102,14 +104,6 @@ repos:
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: ["--keep-percent-format"] args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
- repo: https://github.com/acsone/setuptools-odoo - repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.8 rev: 3.1.8
hooks: hooks:
@ -120,12 +114,12 @@ repos:
- requirements.txt - requirements.txt
- --header - --header
- "# generated from manifests external_dependencies" - "# generated from manifests external_dependencies"
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/astral-sh/ruff-pre-commit
rev: 3.8.3 rev: v0.1.3
hooks: hooks:
- id: flake8 - id: ruff
name: flake8 args: [--fix, --exit-non-zero-on-fix]
additional_dependencies: ["flake8-bugbear==20.1.4"] - id: ruff-format
- repo: https://github.com/OCA/pylint-odoo - repo: https://github.com/OCA/pylint-odoo
rev: 7.0.2 rev: 7.0.2
hooks: hooks:

28
.ruff.toml Normal file
View File

@ -0,0 +1,28 @@
fix = true
[lint]
extend-select = [
"B",
"C90",
"E501", # line too long (default 88)
"I", # isort
]
exclude = ["setup/*"]
[format]
exclude = ["setup/*"]
[per-file-ignores]
"__init__.py" = ["F401", "I001"] # ignore unused and unsorted imports in __init__.py
"__manifest__.py" = ["B018"] # useless expression
[isort]
section-order = ["future", "standard-library", "third-party", "odoo", "odoo-addons", "first-party", "local-folder"]
[isort.sections]
"odoo" = ["odoo"]
"odoo-addons" = ["odoo.addons"]
[mccabe]
max-complexity = 16

View File

@ -44,14 +44,14 @@ class EncryptedData(models.Model):
cipher = self._get_cipher(env) cipher = self._get_cipher(env)
try: try:
return cipher.decrypt(self.encrypted_data).decode() return cipher.decrypt(self.encrypted_data).decode()
except InvalidToken: except InvalidToken as err:
raise ValidationError( raise ValidationError(
_( _(
"Password has been encrypted with a different " "Password has been encrypted with a different "
"key. Unless you can recover the previous key, " "key. Unless you can recover the previous key, "
"this password is unreadable." "this password is unreadable."
) )
) ) from err
@api.model @api.model
@ormcache("self._uid", "name", "env") @ormcache("self._uid", "name", "env")
@ -77,10 +77,10 @@ class EncryptedData(models.Model):
return {} return {}
try: try:
return json.loads(data) return json.loads(data)
except (ValueError, TypeError): except (ValueError, TypeError) as err:
raise ValidationError( raise ValidationError(
_("The data you are trying to read are not in a json format") _("The data you are trying to read are not in a json format")
) ) from err
@staticmethod @staticmethod
def _retrieve_env(): def _retrieve_env():

View File

@ -118,7 +118,9 @@ def _load_config_from_server_env_files(config_p):
try: try:
config_p.read(conf_files) config_p.read(conf_files)
except Exception as e: except Exception as e:
raise Exception('Cannot read config files "{}": {}'.format(conf_files, e)) raise Exception(
'Cannot read config files "{}": {}'.format(conf_files, e)
) from e
def _load_config_from_rcfile(config_p): def _load_config_from_rcfile(config_p):
@ -135,7 +137,7 @@ def _load_config_from_env(config_p):
except configparser.Error as err: except configparser.Error as err:
raise Exception( raise Exception(
"{} content could not be parsed: {}".format(varname, err) "{} content could not be parsed: {}".format(varname, err)
) ) from err
def _load_config(): def _load_config():

View File

@ -105,9 +105,7 @@ class ServerEnvMixin(models.AbstractModel):
<strong>{}</strong> <strong>{}</strong>
</div> </div>
</div> </div>
""".format( """.format("alert-danger", warning_string)
"alert-danger", warning_string
)
) )
return elem return elem
@ -120,9 +118,7 @@ class ServerEnvMixin(models.AbstractModel):
type="object" string="{}{}" type="object" string="{}{}"
class="btn btn-lg btn-primary ml-2" class="btn btn-lg btn-primary ml-2"
context="{}"/> context="{}"/>
""".format( """.format(button_string, environment, {"environment": environment})
button_string, environment, {"environment": environment}
)
button_div += "{}".format(button) button_div += "{}".format(button)
button_div += "</div>" button_div += "</div>"
alert_string = _("Modify values for {} environment").format(current_env) alert_string = _("Modify values for {} environment").format(current_env)
@ -137,9 +133,7 @@ class ServerEnvMixin(models.AbstractModel):
</div> </div>
{} {}
</div> </div>
""".format( """.format(alert_type, alert_string, button_div)
alert_type, alert_string, button_div
)
) )
return elem return elem

View File

@ -10,7 +10,6 @@ SECTION = "ir.config_parameter"
class IrConfigParameter(models.Model): class IrConfigParameter(models.Model):
_inherit = "ir.config_parameter" _inherit = "ir.config_parameter"
is_environment = fields.Boolean( is_environment = fields.Boolean(