diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 96ce4aa..0000000 --- a/.flake8 +++ /dev/null @@ -1,15 +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 -exclude = - ./.git - ./src - ./venv* - .eggs/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d86bd09..b392e2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,11 +60,11 @@ jobs: PGUSER: odoo PGPASSWORD: odoo steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: "${{ matrix.python-version }}" - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ matrix.toxenv }} @@ -78,19 +78,4 @@ jobs: pip install tox virtualenv - name: Run tox run: tox -e ${{ matrix.toxenv }} - - uses: codecov/codecov-action@v1 - deploy: - runs-on: ubuntu-latest - needs: - - tests - if: startsWith(github.ref, 'refs/tags') - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - name: Build a binary wheel and a source tarball - run: pipx run build - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.pypi_token }} + - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e728db7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +on: + release: + types: + - published + +name: release + +jobs: + pypi: + name: upload release to PyPI + runs-on: ubuntu-latest + environment: release + + permissions: + # Used to authenticate to PyPI via OIDC. + id-token: write + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ">= 3.8" + + - name: build + run: pipx run build + + - name: publish + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index f238bf7..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[settings] -profile = black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57caf5a..391bd5a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,26 +1,15 @@ exclude: "^tests/data/.*$" repos: -- repo: https://github.com/psf/black - rev: 23.7.0 - hooks: - - id: black -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: debug-statements -- repo: https://github.com/pycqa/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - additional_dependencies: ["flake8-bugbear==20.1.4"] -- repo: https://github.com/asottile/pyupgrade - rev: v3.10.1 - hooks: - - id: pyupgrade -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: debug-statements + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.1.3 + hooks: + - id: ruff + args: [--exit-non-zero-on-fix] + - id: ruff-format diff --git a/README.rst b/README.rst index 35f1ba3..c4acd85 100644 --- a/README.rst +++ b/README.rst @@ -307,13 +307,13 @@ To run tests, type ``tox``. Tests are made using pytest. To run tests matching a specific keyword for, say, Odoo 12 and python 3.6, use ``tox -e py36-12.0 -- -k keyword``. For running tests you need a postgres server accessible for your user without a password at ``/var/run/postgresql/.s.PGSQL.5432``. -This project uses `black `_ -as code formatting convention, as well as isort and flake8. To make sure local coding convention are respected before you commit, install `pre-commit `_ and run ``pre-commit install`` after cloning the repository. +To release, create a tagged release on GitHub. This will trigger publishing to PyPI. + Credits ~~~~~~~ diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index c3c8ed1..f9d1d67 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -65,11 +65,7 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage): odoo.tools.config["init"] = dict.fromkeys(module_names, 1) odoo.tools.config["without_demo"] = not demo odoo.modules.registry.Registry.new(dbname, force_demo=demo, update_module=True) - _logger.info( - click.style( - "Created new Odoo database {dbname}.".format(**locals()), fg="green" - ) - ) + _logger.info(click.style(f"Created new Odoo database {dbname}.", fg="green")) with odoo.sql_db.db_connect(dbname).cursor() as cr: _save_installed_checksums(cr) odoo.sql_db.close_db(dbname) @@ -151,39 +147,32 @@ def _make_new_template_name(self, hashsum): def _create_db_from_template(self, dbname, template): _logger.info( click.style( - "Creating database {dbname} " - "from template {template}".format(**locals()), + f"Creating database {dbname} from template {template}", fg="green", ) ) self.pgcr.execute( - """ + f""" CREATE DATABASE "{dbname}" ENCODING 'unicode' TEMPLATE "{template}" - """.format( - **locals() - ) + """ ) def _rename_db(self, dbname_from, dbname_to): self.pgcr.execute( - """ + f""" ALTER DATABASE "{dbname_from}" RENAME TO "{dbname_to}" - """.format( - **locals() - ) + """ ) def _drop_db(self, dbname): - _logger.info("Dropping database {dbname}".format(**locals())) + _logger.info(f"Dropping database {dbname}") self.pgcr.execute( - """ + f""" DROP DATABASE "{dbname}" - """.format( - **locals() - ) + """ ) def _find_template(self, hashsum): @@ -194,7 +183,7 @@ def _find_template(self, hashsum): SELECT datname FROM pg_database WHERE datname like %s ORDER BY datname DESC -- MRU first - """, + """, (pattern,), ) r = self.pgcr.fetchone() diff --git a/tests/conftest.py b/tests/conftest.py index d43594f..f314b76 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -55,12 +55,10 @@ def odoocfg(request, tmpdir): odoo_cfg = tmpdir / "odoo.cfg" odoo_cfg.write( textwrap.dedent( - """\ - [options] - addons_path = {} - """.format( - ",".join(addons_path) - ) + f"""\ + [options] + addons_path = {",".join(addons_path)} + """ ) ) yield odoo_cfg diff --git a/tests/test_initdb.py b/tests/test_initdb.py index d4b7038..5206c1d 100644 --- a/tests/test_initdb.py +++ b/tests/test_initdb.py @@ -251,12 +251,10 @@ def test_create_cmd_cache(dbcache, tmpdir): odoo_cfg = tmpdir / "odoo.cfg" odoo_cfg.write( textwrap.dedent( - """\ - [options] - addons_path = {} - """.format( - ADDONS_PATH - ) + f"""\ + [options] + addons_path = {ADDONS_PATH} + """ ) ) cmd = [