From c36188f1e84a1d108b2d7157a6262f3bb894fda2 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 09:56:38 +0200 Subject: [PATCH 01/20] [IMP] checklog-odoo - move up folder refs #1 --- checklog-odoo/{src => }/checklog_odoo/__about__.py | 0 checklog-odoo/{src => }/checklog_odoo/__init__.py | 0 checklog-odoo/{src => }/checklog_odoo/__main__.py | 0 checklog-odoo/{src => }/checklog_odoo/cli/__init__.py | 0 checklog-odoo/{src => }/checklog_odoo/cli/checklog.py | 0 checklog-odoo/{src => }/checklog_odoo/config.py | 0 checklog-odoo/pyproject.toml | 8 ++++---- 7 files changed, 4 insertions(+), 4 deletions(-) rename checklog-odoo/{src => }/checklog_odoo/__about__.py (100%) rename checklog-odoo/{src => }/checklog_odoo/__init__.py (100%) rename checklog-odoo/{src => }/checklog_odoo/__main__.py (100%) rename checklog-odoo/{src => }/checklog_odoo/cli/__init__.py (100%) rename checklog-odoo/{src => }/checklog_odoo/cli/checklog.py (100%) rename checklog-odoo/{src => }/checklog_odoo/config.py (100%) diff --git a/checklog-odoo/src/checklog_odoo/__about__.py b/checklog-odoo/checklog_odoo/__about__.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/__about__.py rename to checklog-odoo/checklog_odoo/__about__.py diff --git a/checklog-odoo/src/checklog_odoo/__init__.py b/checklog-odoo/checklog_odoo/__init__.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/__init__.py rename to checklog-odoo/checklog_odoo/__init__.py diff --git a/checklog-odoo/src/checklog_odoo/__main__.py b/checklog-odoo/checklog_odoo/__main__.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/__main__.py rename to checklog-odoo/checklog_odoo/__main__.py diff --git a/checklog-odoo/src/checklog_odoo/cli/__init__.py b/checklog-odoo/checklog_odoo/cli/__init__.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/cli/__init__.py rename to checklog-odoo/checklog_odoo/cli/__init__.py diff --git a/checklog-odoo/src/checklog_odoo/cli/checklog.py b/checklog-odoo/checklog_odoo/cli/checklog.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/cli/checklog.py rename to checklog-odoo/checklog_odoo/cli/checklog.py diff --git a/checklog-odoo/src/checklog_odoo/config.py b/checklog-odoo/checklog_odoo/config.py similarity index 100% rename from checklog-odoo/src/checklog_odoo/config.py rename to checklog-odoo/checklog_odoo/config.py diff --git a/checklog-odoo/pyproject.toml b/checklog-odoo/pyproject.toml index 0540456..955de0e 100644 --- a/checklog-odoo/pyproject.toml +++ b/checklog-odoo/pyproject.toml @@ -38,7 +38,7 @@ Source = "https://github.com/unknown/checklog-odoo" checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo" [tool.hatch.version] -path = "src/checklog_odoo/__about__.py" +path = "checklog_odoo/__about__.py" [tool.hatch.envs.default] dependencies = [ @@ -68,7 +68,7 @@ dependencies = [ "ruff>=0.0.243", ] [tool.hatch.envs.lint.scripts] -typing = "mypy --install-types --non-interactive {args:src/checklog_odoo tests}" +typing = "mypy --install-types --non-interactive {args:checklog_odoo tests}" style = [ "ruff {args:.}", "black --check --diff {args:.}", @@ -148,11 +148,11 @@ source_pkgs = ["checklog_odoo", "tests"] branch = true parallel = true omit = [ - "src/checklog_odoo/__about__.py", + "checklog_odoo/__about__.py", ] [tool.coverage.paths] -checklog_odoo = ["src/checklog_odoo", "*/checklog-odoo/src/checklog_odoo"] +checklog_odoo = ["checklog_odoo", "*/checklog-odoo/checklog_odoo"] tests = ["tests", "*/checklog-odoo/tests"] [tool.coverage.report] From b34d8f7324d260d9cb836fbb39168610b494fc5c Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 10:07:59 +0200 Subject: [PATCH 02/20] [IMP] checklog-odoo - add a github workflow for tests refs #1 --- .github/workflows/ci.yml | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..01bb37b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +--- +name: CI + +on: + push: + branches: ["main"] + tags: ["*"] + pull_request: + +jobs: + tests: + name: "Python ${{ matrix.python-version }}" + runs-on: ${{ matrix.machine }} + strategy: + fail-fast: false + matrix: + include: + - python-version: "3.6" + machine: ubuntu-20.04 + - python-version: "3.7" + machine: ubuntu-22.04 + - python-version: "3.8" + machine: ubuntu-22.04 + - python-version: "3.9" + machine: ubuntu-22.04 + - python-version: "3.10" + machine: ubuntu-22.04 + - python-version: "3.11" + machine: ubuntu-22.04 + - python-version: "3.12" + machine: ubuntu-22.04 + steps: + - uses: "actions/checkout@v3" + - uses: "actions/setup-python@v4" + with: + python-version: "${{ matrix.python-version }}" + allow-prereleases: true + - name: "Install dependencies" + run: | + set -xe + python -VV + python -m site + python -m pip install --upgrade pip wheel + python -m pip install --upgrade tox tox-gh-actions + - name: "Run tox targets for ${{ matrix.python-version }}" + run: | + python -m tox + - uses: codecov/codecov-action@v3 + From 4c2d6a9666fe2d2e0d7e6e8a77f6258e44da3537 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 10:39:01 +0200 Subject: [PATCH 03/20] [IMP] checklog-odoo - adapt structure to mimic manifestoo-core --- .github/workflows/ci.yml | 3 --- LICENSE | 21 --------------- checklog-odoo/LICENSE.txt => LICENSE.txt | 0 README.md | 27 ++++++++++++++++++- checklog-odoo/README.md | 21 --------------- .../pyproject.toml => pyproject.toml | 4 +-- .../checklog_odoo/__about__.py | 0 .../checklog_odoo/__init__.py | 0 .../checklog_odoo/__main__.py | 0 .../checklog_odoo/cli/__init__.py | 0 .../checklog_odoo/cli/checklog.py | 0 .../checklog_odoo/config.py | 0 {checklog-odoo/tests => tests}/__init__.py | 0 .../tests => tests}/data/odoo/__init__.py | 0 .../data/odoo/addons/__init__.py | 0 .../data/odoo/addons/addon1/__init__.py | 0 .../data/odoo/addons/addon1/__manifest__.py | 0 .../data/odoo/addons/addon2/__init__.py | 0 .../data/odoo/addons/addon2/__manifest__.py | 0 {checklog-odoo/tests => tests}/data/test1.cfg | 0 .../tests => tests}/data/test_checklog.cfg | 0 .../tests => tests}/test_checklog.py | 0 22 files changed, 28 insertions(+), 48 deletions(-) delete mode 100644 LICENSE rename checklog-odoo/LICENSE.txt => LICENSE.txt (100%) delete mode 100644 checklog-odoo/README.md rename checklog-odoo/pyproject.toml => pyproject.toml (97%) rename {checklog-odoo => src}/checklog_odoo/__about__.py (100%) rename {checklog-odoo => src}/checklog_odoo/__init__.py (100%) rename {checklog-odoo => src}/checklog_odoo/__main__.py (100%) rename {checklog-odoo => src}/checklog_odoo/cli/__init__.py (100%) rename {checklog-odoo => src}/checklog_odoo/cli/checklog.py (100%) rename {checklog-odoo => src}/checklog_odoo/config.py (100%) rename {checklog-odoo/tests => tests}/__init__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/__init__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/addons/__init__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/addons/addon1/__init__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/addons/addon1/__manifest__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/addons/addon2/__init__.py (100%) rename {checklog-odoo/tests => tests}/data/odoo/addons/addon2/__manifest__.py (100%) rename {checklog-odoo/tests => tests}/data/test1.cfg (100%) rename {checklog-odoo/tests => tests}/data/test_checklog.cfg (100%) rename {checklog-odoo/tests => tests}/test_checklog.py (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01bb37b..693635b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,6 @@ jobs: fail-fast: false matrix: include: - - python-version: "3.6" - machine: ubuntu-20.04 - python-version: "3.7" machine: ubuntu-22.04 - python-version: "3.8" @@ -46,4 +44,3 @@ jobs: run: | python -m tox - uses: codecov/codecov-action@v3 - diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 01b3519..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 baimont - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/checklog-odoo/LICENSE.txt b/LICENSE.txt similarity index 100% rename from checklog-odoo/LICENSE.txt rename to LICENSE.txt diff --git a/README.md b/README.md index a8a1f43..fba8e02 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ # checklog-odoo -Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions. + +[![PyPI - Version](https://img.shields.io/pypi/v/checklog-odoo.svg)](https://pypi.org/project/checklog-odoo) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/checklog-odoo.svg)](https://pypi.org/project/checklog-odoo) + +----- + + + +Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions.. + + + +**Table of Contents** + +- [Installation](#installation) +- [License](#license) + +## Installation + +```console +pip install checklog-odoo +``` + +## License + +`checklog-odoo` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/checklog-odoo/README.md b/checklog-odoo/README.md deleted file mode 100644 index 97c07be..0000000 --- a/checklog-odoo/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# checklog-odoo - -[![PyPI - Version](https://img.shields.io/pypi/v/checklog-odoo.svg)](https://pypi.org/project/checklog-odoo) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/checklog-odoo.svg)](https://pypi.org/project/checklog-odoo) - ------ - -**Table of Contents** - -- [Installation](#installation) -- [License](#license) - -## Installation - -```console -pip install checklog-odoo -``` - -## License - -`checklog-odoo` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/checklog-odoo/pyproject.toml b/pyproject.toml similarity index 97% rename from checklog-odoo/pyproject.toml rename to pyproject.toml index 955de0e..32cc89c 100644 --- a/checklog-odoo/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ Source = "https://github.com/unknown/checklog-odoo" checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo" [tool.hatch.version] -path = "checklog_odoo/__about__.py" +path = "src/checklog_odoo/__about__.py" [tool.hatch.envs.default] dependencies = [ @@ -148,7 +148,7 @@ source_pkgs = ["checklog_odoo", "tests"] branch = true parallel = true omit = [ - "checklog_odoo/__about__.py", + "src/checklog_odoo/__about__.py", ] [tool.coverage.paths] diff --git a/checklog-odoo/checklog_odoo/__about__.py b/src/checklog_odoo/__about__.py similarity index 100% rename from checklog-odoo/checklog_odoo/__about__.py rename to src/checklog_odoo/__about__.py diff --git a/checklog-odoo/checklog_odoo/__init__.py b/src/checklog_odoo/__init__.py similarity index 100% rename from checklog-odoo/checklog_odoo/__init__.py rename to src/checklog_odoo/__init__.py diff --git a/checklog-odoo/checklog_odoo/__main__.py b/src/checklog_odoo/__main__.py similarity index 100% rename from checklog-odoo/checklog_odoo/__main__.py rename to src/checklog_odoo/__main__.py diff --git a/checklog-odoo/checklog_odoo/cli/__init__.py b/src/checklog_odoo/cli/__init__.py similarity index 100% rename from checklog-odoo/checklog_odoo/cli/__init__.py rename to src/checklog_odoo/cli/__init__.py diff --git a/checklog-odoo/checklog_odoo/cli/checklog.py b/src/checklog_odoo/cli/checklog.py similarity index 100% rename from checklog-odoo/checklog_odoo/cli/checklog.py rename to src/checklog_odoo/cli/checklog.py diff --git a/checklog-odoo/checklog_odoo/config.py b/src/checklog_odoo/config.py similarity index 100% rename from checklog-odoo/checklog_odoo/config.py rename to src/checklog_odoo/config.py diff --git a/checklog-odoo/tests/__init__.py b/tests/__init__.py similarity index 100% rename from checklog-odoo/tests/__init__.py rename to tests/__init__.py diff --git a/checklog-odoo/tests/data/odoo/__init__.py b/tests/data/odoo/__init__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/__init__.py rename to tests/data/odoo/__init__.py diff --git a/checklog-odoo/tests/data/odoo/addons/__init__.py b/tests/data/odoo/addons/__init__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/addons/__init__.py rename to tests/data/odoo/addons/__init__.py diff --git a/checklog-odoo/tests/data/odoo/addons/addon1/__init__.py b/tests/data/odoo/addons/addon1/__init__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/addons/addon1/__init__.py rename to tests/data/odoo/addons/addon1/__init__.py diff --git a/checklog-odoo/tests/data/odoo/addons/addon1/__manifest__.py b/tests/data/odoo/addons/addon1/__manifest__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/addons/addon1/__manifest__.py rename to tests/data/odoo/addons/addon1/__manifest__.py diff --git a/checklog-odoo/tests/data/odoo/addons/addon2/__init__.py b/tests/data/odoo/addons/addon2/__init__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/addons/addon2/__init__.py rename to tests/data/odoo/addons/addon2/__init__.py diff --git a/checklog-odoo/tests/data/odoo/addons/addon2/__manifest__.py b/tests/data/odoo/addons/addon2/__manifest__.py similarity index 100% rename from checklog-odoo/tests/data/odoo/addons/addon2/__manifest__.py rename to tests/data/odoo/addons/addon2/__manifest__.py diff --git a/checklog-odoo/tests/data/test1.cfg b/tests/data/test1.cfg similarity index 100% rename from checklog-odoo/tests/data/test1.cfg rename to tests/data/test1.cfg diff --git a/checklog-odoo/tests/data/test_checklog.cfg b/tests/data/test_checklog.cfg similarity index 100% rename from checklog-odoo/tests/data/test_checklog.cfg rename to tests/data/test_checklog.cfg diff --git a/checklog-odoo/tests/test_checklog.py b/tests/test_checklog.py similarity index 100% rename from checklog-odoo/tests/test_checklog.py rename to tests/test_checklog.py From 065d312d03c79adc25a8fd0302250a370a3f4961 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 11:39:21 +0200 Subject: [PATCH 04/20] [IMP] checklog-odoo - add tox.ini --- tox.ini | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..999b6d7 --- /dev/null +++ b/tox.ini @@ -0,0 +1,28 @@ +[gh-actions] +python = + 3.7: py37 + 3.8: py38 + 3.9: py39 + 3.10: py310 + 3.11: py311 + 3.12: py312 + +[tox] +isolated_build = True +envlist = + py37 + py38 + py39 + py310 + py311 + py312 + +[testenv] +skip_missing_interpreters = True +extras = + test + metadata +commands = + coverage run -m unittest discover + coverage xml + coverage html From 92ab4f1ad1780b0b79e4cf5aeb510a1d8d081760 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 11:43:59 +0200 Subject: [PATCH 05/20] [IMP] checklog-odoo - use pytest instead of unittest refs #1 --- .coveragerc | 3 ++ .github/workflows/ci.yml | 2 +- README.md | 2 +- pyproject.toml | 27 +++++----- tests/test_checklog.py | 104 +++++++++++++++++++-------------------- tox.ini | 2 +- 6 files changed, 71 insertions(+), 69 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..8e8f519 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +source = + checklog-odoo diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 693635b..60a0edb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - python-version: "3.12" machine: ubuntu-22.04 steps: - - uses: "actions/checkout@v3" + - uses: "actions/checkout@v4" - uses: "actions/setup-python@v4" with: python-version: "${{ matrix.python-version }}" diff --git a/README.md b/README.md index fba8e02..f71f76e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ -Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions.. +Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions. diff --git a/pyproject.toml b/pyproject.toml index 32cc89c..da1380a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "checklog-odoo" dynamic = ["version"] -description = '' +description = 'Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions' readme = "README.md" requires-python = ">=3.7" license = "MIT" @@ -41,10 +41,15 @@ checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo" path = "src/checklog_odoo/__about__.py" [tool.hatch.envs.default] -dependencies = [ - "coverage[toml]>=6.5", - "pytest", +dependencies = [] + +[project.optional-dependencies] +metadata = [] +test = [ + "pytest", + "coverage[toml]", ] + [tool.hatch.envs.default.scripts] test = "pytest {args:tests}" test-cov = "coverage run -m pytest {args:tests}" @@ -144,20 +149,14 @@ ban-relative-imports = "all" "tests/**/*" = ["PLR2004", "S101", "TID252"] [tool.coverage.run] -source_pkgs = ["checklog_odoo", "tests"] branch = true -parallel = true -omit = [ - "src/checklog_odoo/__about__.py", -] +source_pkgs = ["checklog-odoo"] [tool.coverage.paths] -checklog_odoo = ["checklog_odoo", "*/checklog-odoo/checklog_odoo"] -tests = ["tests", "*/checklog-odoo/tests"] +source = ["src", ".tox/*/site-packages"] [tool.coverage.report] +show_missing = true exclude_lines = [ - "no cov", - "if __name__ == .__main__.:", - "if TYPE_CHECKING:", + "pragma: no cover", ] diff --git a/tests/test_checklog.py b/tests/test_checklog.py index cc2a3cf..1d98fa7 100644 --- a/tests/test_checklog.py +++ b/tests/test_checklog.py @@ -4,7 +4,6 @@ # SPDX-License-Identifier: MIT import os -import unittest from click.testing import CliRunner @@ -13,58 +12,59 @@ DATA_DIR = os.path.join(os.path.dirname(__file__), "data") -class TestChecklog(unittest.TestCase): - def test1(self): - runner = CliRunner() - res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "test1.log")]) - assert res.exit_code != 0 - expected = "errors that caused failure (2):" - assert expected in res.output +def test1(): + runner = CliRunner() + res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "test1.log")]) + assert res.exit_code != 0 + expected = "errors that caused failure (2):" + assert expected in res.output - def test2(self): - runner = CliRunner() - res = runner.invoke( - checklog_odoo, ["--ignore", " ERROR ", os.path.join(DATA_DIR, "test1.log")] - ) - assert res.exit_code != 0 - expected = "errors that caused failure (1):" - assert expected in res.output - expected = "errors that did not cause failure (1):" - assert expected in res.output +def test2(): + runner = CliRunner() + res = runner.invoke( + checklog_odoo, + ["--ignore", " ERROR ", os.path.join(DATA_DIR, "test1.log")] + ) + assert res.exit_code != 0 + expected = "errors that caused failure (1):" + assert expected in res.output + expected = "errors that did not cause failure (1):" + assert expected in res.output - def test3(self): - runner = CliRunner() - res = runner.invoke( - checklog_odoo, - ["-i", " ERROR ", "-i", " CRITICAL ", os.path.join(DATA_DIR, "test1.log")], - ) - assert res.exit_code == 0 - expected = "errors that did not cause failure (2):" - assert expected in res.output +def test3(): + runner = CliRunner() + res = runner.invoke( + checklog_odoo, + ["-i", " ERROR ", "-i", " CRITICAL ", + os.path.join(DATA_DIR, "test1.log")], + ) + assert res.exit_code == 0 + expected = "errors that did not cause failure (2):" + assert expected in res.output - def test4(self): - runner = CliRunner() - res = runner.invoke( - checklog_odoo, - [ - "-c", - os.path.join(DATA_DIR, "test_checklog.cfg"), - os.path.join(DATA_DIR, "test1.log"), - ], - ) - assert res.exit_code != 0 - expected = "errors that caused failure (1):" - assert expected in res.output - expected = "errors that did not cause failure (1):" - assert expected in res.output +def test4(): + runner = CliRunner() + res = runner.invoke( + checklog_odoo, + [ + "-c", + os.path.join(DATA_DIR, "test_checklog.cfg"), + os.path.join(DATA_DIR, "test1.log"), + ], + ) + assert res.exit_code != 0 + expected = "errors that caused failure (1):" + assert expected in res.output + expected = "errors that did not cause failure (1):" + assert expected in res.output - def test_empty(self): - runner = CliRunner() - res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "empty.log")]) - assert res.exit_code != 0 - expected = "No Odoo log record found in input." - assert expected in res.output - res = runner.invoke( - checklog_odoo, ["--no-err-if-empty", os.path.join(DATA_DIR, "empty.log")] - ) - assert res.exit_code == 0 +def test_empty(): + runner = CliRunner() + res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "empty.log")]) + assert res.exit_code != 0 + expected = "No Odoo log record found in input." + assert expected in res.output + res = runner.invoke( + checklog_odoo, ["--no-err-if-empty", os.path.join(DATA_DIR, "empty.log")] + ) + assert res.exit_code == 0 diff --git a/tox.ini b/tox.ini index 999b6d7..8b9e62b 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,6 @@ extras = test metadata commands = - coverage run -m unittest discover + coverage run -m pytest {posargs} coverage xml coverage html From 10f1b02daea8aa86e05f4adf91493a8ec035874b Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Tue, 10 Oct 2023 16:24:31 +0200 Subject: [PATCH 06/20] [IMP] checklog-odoo - use hatch-vcs --- pyproject.toml | 4 ++-- src/checklog_odoo/__about__.py | 4 ---- src/checklog_odoo/cli/checklog.py | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 src/checklog_odoo/__about__.py diff --git a/pyproject.toml b/pyproject.toml index da1380a..84d971b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] @@ -38,7 +38,7 @@ Source = "https://github.com/unknown/checklog-odoo" checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo" [tool.hatch.version] -path = "src/checklog_odoo/__about__.py" +source = "vcs" [tool.hatch.envs.default] dependencies = [] diff --git a/src/checklog_odoo/__about__.py b/src/checklog_odoo/__about__.py deleted file mode 100644 index 7fdf20b..0000000 --- a/src/checklog_odoo/__about__.py +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont -# -# SPDX-License-Identifier: MIT -__version__ = "0.0.1" diff --git a/src/checklog_odoo/cli/checklog.py b/src/checklog_odoo/cli/checklog.py index 24afc6e..d1a4336 100644 --- a/src/checklog_odoo/cli/checklog.py +++ b/src/checklog_odoo/cli/checklog.py @@ -2,8 +2,6 @@ # # SPDX-License-Identifier: MIT -from checklog_odoo.__about__ import __version__ - import logging import re import sys @@ -118,7 +116,6 @@ def format(self, record): help="Check an odoo log file for errors. When no filename " "or - is provided, read from stdin." ) -@click.version_option(version=__version__, prog_name="checklog-odoo") @click.option( "--ignore", "-i", From 1fc44f9faefc1318e1d41f755c73c3a556de755f Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 11 Oct 2023 11:04:46 +0200 Subject: [PATCH 07/20] [RMV] checklog-odoo - remove unnecessary files --- tests/data/odoo/__init__.py | 1 - tests/data/odoo/addons/__init__.py | 1 - tests/data/odoo/addons/addon1/__init__.py | 0 tests/data/odoo/addons/addon1/__manifest__.py | 7 ------- tests/data/odoo/addons/addon2/__init__.py | 0 tests/data/odoo/addons/addon2/__manifest__.py | 2 -- 6 files changed, 11 deletions(-) delete mode 100644 tests/data/odoo/__init__.py delete mode 100644 tests/data/odoo/addons/__init__.py delete mode 100644 tests/data/odoo/addons/addon1/__init__.py delete mode 100644 tests/data/odoo/addons/addon1/__manifest__.py delete mode 100644 tests/data/odoo/addons/addon2/__init__.py delete mode 100644 tests/data/odoo/addons/addon2/__manifest__.py diff --git a/tests/data/odoo/__init__.py b/tests/data/odoo/__init__.py deleted file mode 100644 index 5284146..0000000 --- a/tests/data/odoo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/tests/data/odoo/addons/__init__.py b/tests/data/odoo/addons/__init__.py deleted file mode 100644 index 5284146..0000000 --- a/tests/data/odoo/addons/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/tests/data/odoo/addons/addon1/__init__.py b/tests/data/odoo/addons/addon1/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/data/odoo/addons/addon1/__manifest__.py b/tests/data/odoo/addons/addon1/__manifest__.py deleted file mode 100644 index 49eb6d3..0000000 --- a/tests/data/odoo/addons/addon1/__manifest__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -{ - "author": "ACSONE SA/NV", - "version": "", - # TODO ... - "depends": ["base"], -} diff --git a/tests/data/odoo/addons/addon2/__init__.py b/tests/data/odoo/addons/addon2/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/data/odoo/addons/addon2/__manifest__.py b/tests/data/odoo/addons/addon2/__manifest__.py deleted file mode 100644 index 825a34e..0000000 --- a/tests/data/odoo/addons/addon2/__manifest__.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -{"author": "ACSONE SA/NV", "license": "AGPL-3", "version": "", "depends": ["base"]} From 11fc9c3457ff868d601346e1fd55b2447dccf157 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 11 Oct 2023 11:07:29 +0200 Subject: [PATCH 08/20] [IMP] checklog-odoo - adapt licenses --- LICENSE.txt | 2 +- src/checklog_odoo/__init__.py | 2 +- src/checklog_odoo/__main__.py | 2 +- src/checklog_odoo/cli/__init__.py | 2 +- src/checklog_odoo/cli/checklog.py | 2 +- src/checklog_odoo/config.py | 2 +- tests/__init__.py | 2 +- tests/test_checklog.py | 1 - 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 9f48452..dc84bbf 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023-present Benoit Aimont +Copyright (c) 2023-present ACSONE SA/NV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/checklog_odoo/__init__.py b/src/checklog_odoo/__init__.py index f750b9e..d2d41bd 100644 --- a/src/checklog_odoo/__init__.py +++ b/src/checklog_odoo/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/src/checklog_odoo/__main__.py b/src/checklog_odoo/__main__.py index a6e828f..9a92b07 100644 --- a/src/checklog_odoo/__main__.py +++ b/src/checklog_odoo/__main__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT import sys diff --git a/src/checklog_odoo/cli/__init__.py b/src/checklog_odoo/cli/__init__.py index c484d21..30d028c 100644 --- a/src/checklog_odoo/cli/__init__.py +++ b/src/checklog_odoo/cli/__init__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/src/checklog_odoo/cli/checklog.py b/src/checklog_odoo/cli/checklog.py index d1a4336..49b65ac 100644 --- a/src/checklog_odoo/cli/checklog.py +++ b/src/checklog_odoo/cli/checklog.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/src/checklog_odoo/config.py b/src/checklog_odoo/config.py index adf2988..8cd15dc 100644 --- a/src/checklog_odoo/config.py +++ b/src/checklog_odoo/config.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/tests/__init__.py b/tests/__init__.py index f750b9e..d2d41bd 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont +# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/tests/test_checklog.py b/tests/test_checklog.py index 1d98fa7..adc0286 100644 --- a/tests/test_checklog.py +++ b/tests/test_checklog.py @@ -1,4 +1,3 @@ -# SPDX-FileCopyrightText: 2023-present Benoit Aimont # SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT From cf444c048a72d02123c96d7ce059c2716f4f97ac Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 11 Oct 2023 16:53:21 +0200 Subject: [PATCH 09/20] [FIX] checklog-odoo test --- .coveragerc | 2 +- .gitignore | 1 - tests/data/empty.log | 0 tests/data/test1.log | 13 +++++++++++++ tox.ini | 4 ++-- 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/data/empty.log create mode 100644 tests/data/test1.log diff --git a/.coveragerc b/.coveragerc index 8e8f519..9f0feb1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,3 @@ [run] source = - checklog-odoo + checklog_odoo diff --git a/.gitignore b/.gitignore index 68bc17f..10cc536 100644 --- a/.gitignore +++ b/.gitignore @@ -56,7 +56,6 @@ cover/ *.pot # Django stuff: -*.log local_settings.py db.sqlite3 db.sqlite3-journal diff --git a/tests/data/empty.log b/tests/data/empty.log new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/test1.log b/tests/data/test1.log new file mode 100644 index 0000000..10d73d9 --- /dev/null +++ b/tests/data/test1.log @@ -0,0 +1,13 @@ +2017-05-21 14:01:49,686 8038 INFO ? odoo: Odoo version 10.0 +2017-05-21 14:01:49,687 8038 INFO ? odoo: addons paths: [u'/home/nobody/odoo-10.0/addons', u'/home/nobody/odoo/odoo/addons', u'/home/nobody/odoo/src/odoo10-addon-mail-environment/setup/mail_environment/odoo/addons', u'/home/nobody/odoo/src/odoo10-addon-mis-builder/setup/mis_builder/odoo/addons', u'/home/nobody/odoo/src/odoo10-addon-mis-builder-operating-unit/setup/mis_builder_operating_unit/odoo/addons', u'/home/nobody/odoo/src/odoo10-addon-server-environment-ir-config-parameter/setup/server_environment_ir_config_parameter/odoo/addons', u'/home/nobody/.virtualenvs/odoo-bscw/local/lib/python2.7/site-packages/odoo/addons', u'/home/nobody/.virtualenvs/odoo-bscw/lib/python2.7/site-packages/odoo/addons', '/home/nobody/odoo/src/odoo/odoo/addons'] +2017-05-21 14:01:49,687 8038 INFO ? odoo: database: default@default:default +2017-05-21 14:01:50,496 8038 INFO ? odoo.modules.loading: init db +2017-05-21 14:01:50,637 8038 ERROR ? odoo.modules.registry: Failed to load registry +Traceback (most recent call last): + ... +OSError: [Errno 2] No such file or directory: '/home/nobody/odoo-10.0/addons' +2017-05-21 14:01:50,637 8038 CRITICAL ? odoo.service.server: Failed to initialize database `odoo-bscw-testsuite-1`. +Traceback (most recent call last): + ... +2017-05-21 14:01:50,638 8038 INFO ? odoo.service.server: Initiating shutdown +2017-05-21 14:01:50,638 8038 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown. \ No newline at end of file diff --git a/tox.ini b/tox.ini index 8b9e62b..bc0c874 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,6 @@ extras = test metadata commands = - coverage run -m pytest {posargs} - coverage xml + coverage run -m pytest coverage html + coverage xml From 95241521b9627e1f3c4033af13285ecd71b315f4 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Fri, 13 Oct 2023 10:26:42 +0200 Subject: [PATCH 10/20] [ADD] checklog-odoo - update readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index f71f76e..aa23cd2 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,14 @@ Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions. +Replaces acsoo checklog (https://github.com/acsone/acsoo#id5). **Table of Contents** - [Installation](#installation) +- [Features](#features) - [License](#license) ## Installation @@ -22,6 +24,14 @@ Check if an odoo log file contains error, with the possibility to ignore some er pip install checklog-odoo ``` +## Features + +```console +checklog-odoo odoo.log +unbuffer odoo -d mydb -i base --stop-after-init | checklog-odoo +checklog-odoo --ignore "WARNING.*blah" odoo.log +``` + ## License `checklog-odoo` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. From 07aff930c31cac3eba61a0618aed67dfe6e01967 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Fri, 13 Oct 2023 10:29:34 +0200 Subject: [PATCH 11/20] [IMP] checklog-odoo - no need for cli folder --- pyproject.toml | 2 +- src/checklog_odoo/__init__.py | 2 ++ src/checklog_odoo/__main__.py | 2 +- src/checklog_odoo/{cli => }/checklog.py | 0 src/checklog_odoo/cli/__init__.py | 6 ------ tests/test_checklog.py | 2 +- 6 files changed, 5 insertions(+), 9 deletions(-) rename src/checklog_odoo/{cli => }/checklog.py (100%) delete mode 100644 src/checklog_odoo/cli/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 84d971b..6da6092 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ Issues = "https://github.com/unknown/checklog-odoo/issues" Source = "https://github.com/unknown/checklog-odoo" [project.scripts] -checklog-odoo = "checklog_odoo.cli.checklog:checklog_odoo" +checklog-odoo = "checklog_odoo.checklog:checklog_odoo" [tool.hatch.version] source = "vcs" diff --git a/src/checklog_odoo/__init__.py b/src/checklog_odoo/__init__.py index d2d41bd..a8c557b 100644 --- a/src/checklog_odoo/__init__.py +++ b/src/checklog_odoo/__init__.py @@ -1,3 +1,5 @@ # SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT + +from . import checklog diff --git a/src/checklog_odoo/__main__.py b/src/checklog_odoo/__main__.py index 9a92b07..319051f 100644 --- a/src/checklog_odoo/__main__.py +++ b/src/checklog_odoo/__main__.py @@ -4,6 +4,6 @@ import sys if __name__ == "__main__": - from checklog_odoo.cli.checklog import checklog_odoo + from checklog_odoo.checklog import checklog_odoo sys.exit(checklog_odoo()) diff --git a/src/checklog_odoo/cli/checklog.py b/src/checklog_odoo/checklog.py similarity index 100% rename from src/checklog_odoo/cli/checklog.py rename to src/checklog_odoo/checklog.py diff --git a/src/checklog_odoo/cli/__init__.py b/src/checklog_odoo/cli/__init__.py deleted file mode 100644 index 30d028c..0000000 --- a/src/checklog_odoo/cli/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2023-present ACSONE -# -# SPDX-License-Identifier: MIT - -from . import checklog - diff --git a/tests/test_checklog.py b/tests/test_checklog.py index adc0286..d72f99e 100644 --- a/tests/test_checklog.py +++ b/tests/test_checklog.py @@ -6,7 +6,7 @@ from click.testing import CliRunner -from checklog_odoo.cli.checklog import checklog_odoo +from checklog_odoo.checklog import checklog_odoo DATA_DIR = os.path.join(os.path.dirname(__file__), "data") From 1bae1a2d3f27a66768d1022340f6c8a84afd8b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 20 Nov 2023 16:45:31 +0100 Subject: [PATCH 12/20] Use tomllib for python>=3.11 --- pyproject.toml | 2 +- src/checklog_odoo/compat.py | 9 +++++++++ src/checklog_odoo/config.py | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/checklog_odoo/compat.py diff --git a/pyproject.toml b/pyproject.toml index 6da6092..a37b673 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ ] dependencies = [ "click", - "tomli", + "tomli ; python_version < '3.11'", ] [project.urls] diff --git a/src/checklog_odoo/compat.py b/src/checklog_odoo/compat.py new file mode 100644 index 0000000..a983a17 --- /dev/null +++ b/src/checklog_odoo/compat.py @@ -0,0 +1,9 @@ +import sys + +__all__ = ["tomllib"] + + +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib diff --git a/src/checklog_odoo/config.py b/src/checklog_odoo/config.py index 8cd15dc..bf241dc 100644 --- a/src/checklog_odoo/config.py +++ b/src/checklog_odoo/config.py @@ -7,7 +7,8 @@ from pathlib import Path import click -import tomli + +from .compat import tomllib DEFAULT_CONFIG_FILE = "checklog.cfg" SECTION = "checklog" @@ -36,7 +37,7 @@ def __init__(self, filename): pyproject_path = Path("pyproject.toml") self.__pyproject = {} if pyproject_path.is_file(): - self.__pyproject = tomli.loads(pyproject_path.read_text()) + self.__pyproject = tomllib.loads(pyproject_path.read_text()) @staticmethod def add_default_map_reader(reader): From 41490b705164696c1fa4a0580ffdf00bff20ded8 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Fri, 24 Nov 2023 09:27:02 +0100 Subject: [PATCH 13/20] [IMP] a few improvements --- LICENSE.txt | 2 +- README.md | 26 ++++++++++++++++++++++++-- src/checklog_odoo/__init__.py | 1 - tox.ini | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index dc84bbf..ed47cb8 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023-present ACSONE SA/NV +Copyright (c) 2017-present ACSONE SA/NV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index aa23cd2..8621e16 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ Replaces acsoo checklog (https://github.com/acsone/acsoo#id5). ## Installation ```console -pip install checklog-odoo +pipx install checklog-odoo ``` -## Features +## Use examples ```console checklog-odoo odoo.log @@ -32,6 +32,28 @@ unbuffer odoo -d mydb -i base --stop-after-init | checklog-odoo checklog-odoo --ignore "WARNING.*blah" odoo.log ``` +## Options + +* -i, --ignore REGEX: Regular expression of log records to ignore. +* --echo / --no-echo: Echo the input file (default when reading + from stdin). +* --err-if-empty / --no-err-if-empty: + Exit with an error code if no log record is + found (default). +* -c, --config FILE: Configuration file (default: + ./checklog.cfg). + * Example of config file: + ```console + [checklog] + ignore= + WARNING + ERROR:.*registry + ``` + + +* --help: Show the help message and exit. + + ## License `checklog-odoo` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/src/checklog_odoo/__init__.py b/src/checklog_odoo/__init__.py index a8c557b..143dc26 100644 --- a/src/checklog_odoo/__init__.py +++ b/src/checklog_odoo/__init__.py @@ -1,4 +1,3 @@ -# SPDX-FileCopyrightText: 2023-present ACSONE # # SPDX-License-Identifier: MIT diff --git a/tox.ini b/tox.ini index bc0c874..5e93ed1 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ python = [tox] isolated_build = True +use_develop = True envlist = py37 py38 From ae68bab99fd9c706e9f83469b0546164aa0fb526 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 6 Dec 2023 15:06:05 +0100 Subject: [PATCH 14/20] [IMP] remove import from init --- src/checklog_odoo/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/checklog_odoo/__init__.py b/src/checklog_odoo/__init__.py index 143dc26..88b46b8 100644 --- a/src/checklog_odoo/__init__.py +++ b/src/checklog_odoo/__init__.py @@ -1,4 +1,2 @@ # # SPDX-License-Identifier: MIT - -from . import checklog From e73c11d21a5a0559678cb830b9f54dcd347acb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:10:43 +0200 Subject: [PATCH 15/20] Change default config file name --- src/checklog_odoo/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checklog_odoo/config.py b/src/checklog_odoo/config.py index bf241dc..718b363 100644 --- a/src/checklog_odoo/config.py +++ b/src/checklog_odoo/config.py @@ -10,7 +10,7 @@ from .compat import tomllib -DEFAULT_CONFIG_FILE = "checklog.cfg" +DEFAULT_CONFIG_FILE = "checklog-odoo.cfg" SECTION = "checklog" From c09e469e1890e4939be5e6e094d1bd1545c9230a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:28:08 +0200 Subject: [PATCH 16/20] Configure pre-commit and apply ruff recommendations --- .pre-commit-config.yaml | 16 +++++++++ pyproject.toml | 8 ++--- src/checklog_odoo/checklog.py | 67 +++++++++++++++++------------------ src/checklog_odoo/config.py | 12 +++---- tests/data/test1.log | 2 +- tests/data/test_checklog.cfg | 2 +- tests/test_checklog.py | 16 ++++----- 7 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c0bd724 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +default_language_version: + python: python3 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.2 + hooks: + - id: ruff + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index a37b673..3e1f3e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,9 @@ skip-string-normalization = true [tool.ruff] target-version = "py37" line-length = 120 +fix = true + +[tool.ruff.lint] select = [ "A", "ARG", @@ -141,12 +144,9 @@ unfixable = [ [tool.ruff.isort] known-first-party = ["checklog_odoo"] -[tool.ruff.flake8-tidy-imports] -ban-relative-imports = "all" - [tool.ruff.per-file-ignores] # Tests can use magic values, assertions, and relative imports -"tests/**/*" = ["PLR2004", "S101", "TID252"] +"tests/**/*" = ["PLR2004", "S101"] [tool.coverage.run] branch = true diff --git a/src/checklog_odoo/checklog.py b/src/checklog_odoo/checklog.py index 49b65ac..9feb3be 100644 --- a/src/checklog_odoo/checklog.py +++ b/src/checklog_odoo/checklog.py @@ -30,9 +30,7 @@ def _render_errors(error_records, ignored_error_records): if ignored_error_records: msg.append( click.style( - "\nerrors that did not cause failure ({}):\n".format( - len(ignored_error_records) - ), + f"\nerrors that did not cause failure ({len(ignored_error_records)}):\n", bold=True, ) ) @@ -40,7 +38,7 @@ def _render_errors(error_records, ignored_error_records): if error_records: msg.append( click.style( - "\nerrors that caused failure ({}):\n".format(len(error_records)), + f"\nerrors that caused failure ({len(error_records)}):\n", bold=True, ) ) @@ -48,7 +46,7 @@ def _render_errors(error_records, ignored_error_records): return "".join(msg) -def do_checklog(filename, ignore, echo, err_if_empty=True): +def do_checklog(filename, ignore, echo, *, err_if_empty=True): ignore = [i for i in ignore if not i.startswith("#")] _logger.debug("ignored regular expressions:\n%s", "\n".join(ignore)) ignore_regexes = [re.compile(i, re.MULTILINE) for i in ignore] @@ -78,44 +76,44 @@ def _process_cur_rec(): if echo: click.echo(line, nl=False, color=True) sys.stdout.flush() - line = ANSI_CSI_RE.sub("", line) # strip ANSI colors - mo = LOG_START_RE.match(line) + line_nocolor = ANSI_CSI_RE.sub("", line) # strip ANSI colors + mo = LOG_START_RE.match(line_nocolor) if mo: reccount += 1 _process_cur_rec() cur_rec_mo = mo - cur_rec = [line] + cur_rec = [line_nocolor] else: - cur_rec.append(line) + cur_rec.append(line_nocolor) _process_cur_rec() # last record if not reccount and err_if_empty: - raise click.ClickException("No Odoo log record found in input.") + msg = "No Odoo log record found in input." + raise click.ClickException(msg) if error_records or ignored_error_records: msg = _render_errors(error_records, ignored_error_records) click.echo(msg) if error_records: - raise click.ClickException("Errors detected in log.") + msg = "Errors detected in log." + raise click.ClickException(msg) -class ColoredFormatter(logging.Formatter): - COLORS = { - "DEBUG": dict(dim=True), - "INFO": dict(), - "WARNING": dict(fg="yellow"), - "ERROR": dict(fg="red"), - "CRITICAL": dict(fg="white", bg="red"), +class ColoredFormatter(logging.Formatter): + COLORS = { # noqa: RUF012 + "DEBUG": {"dim": True}, + "INFO": {}, + "WARNING": {"fg": "yellow"}, + "ERROR": {"fg": "red"}, + "CRITICAL": {"fg": "white", "bg": "red"}, } def format(self, record): - res = super(ColoredFormatter, self).format(record) + res = super().format(record) return click.style(res, **self.COLORS[record.levelname]) -@click.command( - help="Check an odoo log file for errors. When no filename " - "or - is provided, read from stdin." -) + +@click.command(help="Check an odoo log file for errors. When no filename or - is provided, read from stdin.") @click.option( "--ignore", "-i", @@ -131,7 +129,7 @@ def format(self, record): @click.option( "--err-if-empty/--no-err-if-empty", default=True, - help="Exit with an error code if no log record is found " "(default).", + help="Exit with an error code if no log record is found (default).", ) @click.option("-v", "--verbose", count=True) @click.option( @@ -145,12 +143,12 @@ def format(self, record): def checklog_odoo(ctx, filename, config, ignore, verbose, echo, err_if_empty): config = ChecklogConfig(config) - ctx.obj = dict(config=config) + ctx.obj = {"config": config} ctx.default_map = config.get_default_map() - checklog_config = ctx.default_map.get('checklog') - default_ignore = checklog_config.get('ignore') + checklog_config = ctx.default_map.get("checklog") + default_ignore = checklog_config.get("ignore") if not ignore and default_ignore: ignore = default_ignore @@ -167,15 +165,16 @@ def checklog_odoo(ctx, filename, config, ignore, verbose, echo, err_if_empty): logger.setLevel(level) logger.addHandler(channel) - do_checklog(filename, ignore, echo, err_if_empty) + do_checklog(filename, ignore, echo, err_if_empty=err_if_empty) def _read_defaults(config): section = "checklog" - defaults = dict( - ignore=config.getlist(section, "ignore", []), - echo=config.getboolean(section, "echo", None), - ) - return dict(checklog=defaults) + defaults = { + "ignore": config.getlist(section, "ignore", []), + "echo": config.getboolean(section, "echo", None), + } + return {"checklog": defaults} + -ChecklogConfig.add_default_map_reader(_read_defaults) \ No newline at end of file +ChecklogConfig.add_default_map_reader(_read_defaults) diff --git a/src/checklog_odoo/config.py b/src/checklog_odoo/config.py index 718b363..19d76c5 100644 --- a/src/checklog_odoo/config.py +++ b/src/checklog_odoo/config.py @@ -18,10 +18,9 @@ def _split_multiline(s): return [i.strip() for i in s.splitlines() if i.strip()] -class ChecklogConfig(object): - +class ChecklogConfig: # list of callables returning dictionaries to update default_map - default_map_readers = [] + default_map_readers = [] # noqa: RUF012 def __init__(self, filename): self.__cfg = RawConfigParser() @@ -29,9 +28,8 @@ def __init__(self, filename): filename = DEFAULT_CONFIG_FILE if filename: if not os.path.isfile(filename): - raise click.ClickException( - "Configuration file {} not found.".format(filename) - ) + msg = f"Configuration file {filename} not found." + raise click.ClickException(msg) self.__cfgfile = filename self.__cfg.read(filename) pyproject_path = Path("pyproject.toml") @@ -49,7 +47,7 @@ def get_default_map(self): default_map.update(reader(self)) return default_map - def get(self, section, option, default=None, flatten=False): + def get(self, section, option, default=None, *, flatten=False): try: r = self.__cfg.get(section, option) if flatten: diff --git a/tests/data/test1.log b/tests/data/test1.log index 10d73d9..ec13dd9 100644 --- a/tests/data/test1.log +++ b/tests/data/test1.log @@ -10,4 +10,4 @@ OSError: [Errno 2] No such file or directory: '/home/nobody/odoo-10.0/addons' Traceback (most recent call last): ... 2017-05-21 14:01:50,638 8038 INFO ? odoo.service.server: Initiating shutdown -2017-05-21 14:01:50,638 8038 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown. \ No newline at end of file +2017-05-21 14:01:50,638 8038 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown. diff --git a/tests/data/test_checklog.cfg b/tests/data/test_checklog.cfg index 191ccf7..17481c1 100644 --- a/tests/data/test_checklog.cfg +++ b/tests/data/test_checklog.cfg @@ -1,2 +1,2 @@ [checklog] -ignore=ERROR \ No newline at end of file +ignore=ERROR diff --git a/tests/test_checklog.py b/tests/test_checklog.py index d72f99e..107fe42 100644 --- a/tests/test_checklog.py +++ b/tests/test_checklog.py @@ -18,29 +18,28 @@ def test1(): expected = "errors that caused failure (2):" assert expected in res.output + def test2(): runner = CliRunner() - res = runner.invoke( - checklog_odoo, - ["--ignore", " ERROR ", os.path.join(DATA_DIR, "test1.log")] - ) + res = runner.invoke(checklog_odoo, ["--ignore", " ERROR ", os.path.join(DATA_DIR, "test1.log")]) assert res.exit_code != 0 expected = "errors that caused failure (1):" assert expected in res.output expected = "errors that did not cause failure (1):" assert expected in res.output + def test3(): runner = CliRunner() res = runner.invoke( checklog_odoo, - ["-i", " ERROR ", "-i", " CRITICAL ", - os.path.join(DATA_DIR, "test1.log")], + ["-i", " ERROR ", "-i", " CRITICAL ", os.path.join(DATA_DIR, "test1.log")], ) assert res.exit_code == 0 expected = "errors that did not cause failure (2):" assert expected in res.output + def test4(): runner = CliRunner() res = runner.invoke( @@ -57,13 +56,12 @@ def test4(): expected = "errors that did not cause failure (1):" assert expected in res.output + def test_empty(): runner = CliRunner() res = runner.invoke(checklog_odoo, [os.path.join(DATA_DIR, "empty.log")]) assert res.exit_code != 0 expected = "No Odoo log record found in input." assert expected in res.output - res = runner.invoke( - checklog_odoo, ["--no-err-if-empty", os.path.join(DATA_DIR, "empty.log")] - ) + res = runner.invoke(checklog_odoo, ["--no-err-if-empty", os.path.join(DATA_DIR, "empty.log")]) assert res.exit_code == 0 From bf826e322324e618d40dda0ee7bf6e2b444a24dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:33:08 +0200 Subject: [PATCH 17/20] Tydi up pyproject.toml --- pyproject.toml | 64 ++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3e1f3e6..3e83214 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] @@ -30,68 +31,25 @@ dependencies = [ ] [project.urls] -Documentation = "https://github.com/unknown/checklog-odoo#readme" -Issues = "https://github.com/unknown/checklog-odoo/issues" -Source = "https://github.com/unknown/checklog-odoo" +Documentation = "https://github.com/acsone/checklog-odoo#readme" +Issues = "https://github.com/acsone/checklog-odoo/issues" +Source = "https://github.com/acsone/checklog-odoo" [project.scripts] checklog-odoo = "checklog_odoo.checklog:checklog_odoo" -[tool.hatch.version] -source = "vcs" - -[tool.hatch.envs.default] -dependencies = [] - [project.optional-dependencies] -metadata = [] test = [ "pytest", "coverage[toml]", ] -[tool.hatch.envs.default.scripts] -test = "pytest {args:tests}" -test-cov = "coverage run -m pytest {args:tests}" -cov-report = [ - "- coverage combine", - "coverage report", -] -cov = [ - "test-cov", - "cov-report", -] - -[[tool.hatch.envs.all.matrix]] -python = ["3.7", "3.8", "3.9", "3.10", "3.11"] - -[tool.hatch.envs.lint] -detached = true -dependencies = [ - "black>=23.1.0", - "mypy>=1.0.0", - "ruff>=0.0.243", -] -[tool.hatch.envs.lint.scripts] -typing = "mypy --install-types --non-interactive {args:checklog_odoo tests}" -style = [ - "ruff {args:.}", - "black --check --diff {args:.}", -] -fmt = [ - "black {args:.}", - "ruff --fix {args:.}", - "style", -] -all = [ - "style", - "typing", -] +[tool.hatch.version] +source = "vcs" -[tool.black] -target-version = ["py37"] -line-length = 120 -skip-string-normalization = true +################################################################################### +# ruff +# [tool.ruff] target-version = "py37" @@ -148,6 +106,10 @@ known-first-party = ["checklog_odoo"] # Tests can use magic values, assertions, and relative imports "tests/**/*" = ["PLR2004", "S101"] +################################################################################### +# coverage +# + [tool.coverage.run] branch = true source_pkgs = ["checklog-odoo"] From 796bc19c7f7d3740172f456fd92ecfdf14f700e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:45:15 +0200 Subject: [PATCH 18/20] Change default config section to checklog-odoo --- src/checklog_odoo/checklog.py | 2 +- tests/data/test_checklog.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checklog_odoo/checklog.py b/src/checklog_odoo/checklog.py index 9feb3be..4188bdc 100644 --- a/src/checklog_odoo/checklog.py +++ b/src/checklog_odoo/checklog.py @@ -169,7 +169,7 @@ def checklog_odoo(ctx, filename, config, ignore, verbose, echo, err_if_empty): def _read_defaults(config): - section = "checklog" + section = "checklog-odoo" defaults = { "ignore": config.getlist(section, "ignore", []), "echo": config.getboolean(section, "echo", None), diff --git a/tests/data/test_checklog.cfg b/tests/data/test_checklog.cfg index 17481c1..6f38941 100644 --- a/tests/data/test_checklog.cfg +++ b/tests/data/test_checklog.cfg @@ -1,2 +1,2 @@ -[checklog] +[checklog-odoo] ignore=ERROR From da8e9f5ada3f9e43533f5c7bf4898ab829fce372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:45:43 +0200 Subject: [PATCH 19/20] DRY default config file name --- src/checklog_odoo/checklog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checklog_odoo/checklog.py b/src/checklog_odoo/checklog.py index 4188bdc..240d35e 100644 --- a/src/checklog_odoo/checklog.py +++ b/src/checklog_odoo/checklog.py @@ -8,7 +8,7 @@ import click -from checklog_odoo.config import ChecklogConfig +from checklog_odoo.config import DEFAULT_CONFIG_FILE, ChecklogConfig _logger = logging.getLogger(__name__) @@ -136,7 +136,7 @@ def format(self, record): "-c", "--config", type=click.Path(dir_okay=False, exists=True), - help="Configuration file (default: ./checklog.cfg).", + help=f"Configuration file [default: {DEFAULT_CONFIG_FILE}].", ) @click.argument("filename", type=click.Path(dir_okay=False), default="-") @click.pass_context From 307464f2f7369b3f608a8157bf018d4690ffcc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 26 Apr 2024 17:46:49 +0200 Subject: [PATCH 20/20] Tydi up README --- README.md | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8621e16..5b2028a 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,15 @@ Check if an odoo log file contains error, with the possibility to ignore some errors based on regular expressions. -Replaces acsoo checklog (https://github.com/acsone/acsoo#id5). + +This project replaces the [acsoo](https://pypi.org/project/acsoo)'s checklog command. **Table of Contents** - [Installation](#installation) -- [Features](#features) +- [Usage](#usage) - [License](#license) ## Installation @@ -32,27 +33,36 @@ unbuffer odoo -d mydb -i base --stop-after-init | checklog-odoo checklog-odoo --ignore "WARNING.*blah" odoo.log ``` -## Options +## Usage + +```console +Usage: checklog-odoo [OPTIONS] [FILENAME] + + Check an odoo log file for errors. When no filename or - is provided, read + from stdin. -* -i, --ignore REGEX: Regular expression of log records to ignore. -* --echo / --no-echo: Echo the input file (default when reading +Options: + -i, --ignore REGEX Regular expression of log records to ignore. + --echo / --no-echo Echo the input file (default when reading from stdin). -* --err-if-empty / --no-err-if-empty: + --err-if-empty / --no-err-if-empty Exit with an error code if no log record is found (default). -* -c, --config FILE: Configuration file (default: - ./checklog.cfg). - * Example of config file: - ```console - [checklog] - ignore= - WARNING - ERROR:.*registry - ``` + -v, --verbose + -c, --config FILE Configuration file [default: checklog-odoo.cfg] + --help Show this message and exit. +``` +## Example of config file: -* --help: Show the help message and exit. +The configuration file use the `ini` format: +```ini +[checklog-odoo] +ignore= + WARNING + ERROR:.*registry +``` ## License