Skip to content

Commit

Permalink
Merge pull request #48 from acsone/py36
Browse files Browse the repository at this point in the history
requires python >= 3.6
  • Loading branch information
sbidoul committed Sep 21, 2022
2 parents 39c9bf9 + e827538 commit 15f08e9
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 273 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: "2.7"
toxenv: "py27-8.0"
- python-version: "2.7"
toxenv: "py27-9.0"
- python-version: "2.7"
toxenv: "py27-10.0"
- python-version: "3.5"
toxenv: "py35-11.0"
- python-version: "3.6"
toxenv: "py36-11.0"
- python-version: "3.6"
toxenv: "py36-12.0"
- python-version: "3.6"
toxenv: "py36-13.0"
- python-version: "3.6"
toxenv: "py36-14.0"
- python-version: "3.6"
toxenv: "py36-15.0"
- python-version: "3.8"
toxenv: "py38-15.0"
# - python-version: "3.8"
Expand Down Expand Up @@ -71,6 +63,7 @@ jobs:
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Install system dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qq --no-install-recommends \
libxml2-dev libxslt1-dev \
libldap2-dev libsasl2-dev \
Expand Down
9 changes: 1 addition & 8 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
[settings]
; see https://github.com/ambv/black
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
use_parentheses=True
line_length=88
known_third_party = click,psycopg2,pytest,setuptools
profile = black
19 changes: 6 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://github.com/pycqa/flake8
rev: 3.8.3
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
rev: v2.32.1
hooks:
- id: pyupgrade
language_version: python3
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
language_version: python3
args: ["--py36-plus"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.5.4
rev: v5.10.1
hooks:
- id: isort
language_version: python3
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exclude .gitignore
exclude .travis.yml
exclude .pre-commit-config.yaml
exclude .github
18 changes: 6 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Useful community-managed scripts can be found in click-odoo-contrib_.
Quick start
~~~~~~~~~~~

Check Odoo is correctly installed: ``python -c "import odoo"`` (for Odoo 10
and later) or ``python -c "import openerp"`` (for Odoo 8 and 9) must
Check Odoo is correctly installed: ``python -c "import odoo"`` must
work when run from another directory than the Odoo root directory.

Install ``click-odoo``::
Expand Down Expand Up @@ -115,17 +114,16 @@ as a global variable.
Supported Odoo versions
~~~~~~~~~~~~~~~~~~~~~~~

Odoo version 8, 9, 10, 11, 12, 13 and 14 are supported.
Odoo version 12, 13, 14 and 15 are supported.

An important design goal is to provide a consistent behaviour
across Odoo versions.

.. note::

``click-odoo`` does not mandate any particular method of installing odoo.
The only prerequisiste is that ``import odoo`` (>= 10) or ``import openerp``
(< 10) must work when run from another directory than the Odoo root
directory.
``click-odoo`` does not mandate any particular method of installing odoo. The only
prerequisiste is that ``import odoo`` must work when run from another directory than
the Odoo root directory.

You may also rely on the fact that python adds the current directory to
``sys.path``, so ``import odoo`` works from the Odoo root directory.
Expand All @@ -148,9 +146,6 @@ commit changes made before or during an interactive session, use ``env.cr.commit
Logging
~~~~~~~

In version 8, Odoo logs to stdout by default. On other versions
it is stderr. ``click-odoo`` attempts to use stderr for Odoo 8 too.

Logging is controlled by the usual Odoo logging options (``--log-level``,
``--logfile``) or the Odoo configuration file.

Expand Down Expand Up @@ -290,8 +285,7 @@ click_odoo.odoo namespace
-------------------------

As a convenience ``click_odoo`` exports the ``odoo`` namespace, so
``from click_odoo import odoo`` is an alias for ``import odoo`` (>= 10)
or ``import openerp as odoo`` (< 10).
``from click_odoo import odoo`` is an alias for ``import odoo``.

OdooEnvironment context manager (experimental)
----------------------------------------------
Expand Down
29 changes: 4 additions & 25 deletions click_odoo/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,11 @@
"odoo_version_info",
]

try:
import odoo
from odoo.api import Environment
except ImportError as e:
if hasattr(e, "name") and e.name != "odoo":
raise
# Odoo < 10
try:
import openerp as odoo
from openerp.api import Environment
except ImportError:
if hasattr(e, "name") and e.name != "openerp":
raise
raise ImportError("No module named odoo nor openerp")
import odoo
from odoo.api import Environment
from odoo.release import version_info as odoo_version_info


try:
from odoo.release import version_info as odoo_version_info
except ImportError:
from openerp.release import version_info as odoo_version_info


if odoo_version_info < (10, 0):
odoo_bin = "openerp-server"
else:
odoo_bin = "odoo"
odoo_bin = "odoo"


if odoo_version_info < (15, 0):
Expand Down
2 changes: 1 addition & 1 deletion click_odoo/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_logger = logging.getLogger(__name__)


class Shell(object):
class Shell:

shells = ["ipython", "ptpython", "bpython", "python"]

Expand Down
7 changes: 2 additions & 5 deletions click_odoo/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from contextlib import contextmanager

from .compat import Environment, environment_manage, odoo, odoo_version_info
from .compat import Environment, environment_manage, odoo

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,8 +36,5 @@ def OdooEnvironment(database, rollback=False, **kwargs):
else:
cr.commit()
finally:
if odoo_version_info < (10, 0):
odoo.modules.registry.RegistryManager.delete(database)
else:
odoo.modules.registry.Registry.delete(database)
odoo.modules.registry.Registry.delete(database)
odoo.sql_db.close_db(database)
20 changes: 2 additions & 18 deletions click_odoo/env_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

import logging
import sys
from contextlib import closing

import click
from click.decorators import _param_memo # XXX undocumented click internal

from .compat import environment_manage, odoo_version_info
from .compat import environment_manage
from .env import OdooEnvironment, odoo

_logger = logging.getLogger(__name__)


class env_options(object):
class env_options:
def __init__(
self,
default_log_level="info",
Expand Down Expand Up @@ -112,19 +111,6 @@ def _register(self, ctx, param, value):
ctx.command.invoke = self._invoke
return value

def _fix_odoo_logging(self):
if odoo_version_info < (9, 0):
handlers = logging.getLogger().handlers
if handlers and len(handlers) == 1:
handler = handlers[0]
if isinstance(handler, logging.StreamHandler):
if handler.stream is sys.stdout:
handler.stream = sys.stderr

def _fix_disable_wsgi_module_handlers(self):
if odoo_version_info < (9, 0):
odoo.service.wsgi_server.module_handlers[:] = []

def get_odoo_args(self, ctx):
"""Return a list of Odoo command line arguments from the Click context."""
config = ctx.params.get("config")
Expand Down Expand Up @@ -157,8 +143,6 @@ def _configure_odoo(self, ctx):
# see https://github.com/odoo/odoo/commit/b122217f74
odoo.tools.config["load_language"] = None
odoo.tools.config.parse_config(odoo_args)
self._fix_odoo_logging()
self._fix_disable_wsgi_module_handlers()
odoo.cli.server.report_configuration()

def _db_exists(self, dbname):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/48.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for python < 3.6 and Odoo 8, 9, 10.
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
include_package_data=True,
setup_requires=["setuptools_scm"],
install_requires=["click>=7"],
python_requires=">=3.6",
license="LGPLv3+",
author="ACSONE SA/NV",
author_email="info@acsone.eu",
Expand All @@ -32,8 +33,6 @@
"Intended Audience :: Developers",
"License :: OSI Approved :: "
"GNU Lesser General Public License v3 or later (LGPLv3+)",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand Down
20 changes: 4 additions & 16 deletions tests/scripts/install_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@
def odoo_installed():
try:
import odoo # noqa

return True
except ImportError:
# odoo < 10
try:
import openerp # noqa

return True
except ImportError:
# odoo not installed
return False
return False
else:
return True


def odoo_cloned():
Expand All @@ -39,15 +32,10 @@ def clone_odoo():
odoo_dir,
]
)
if "PGHOST" in os.environ and odoo_branch == "8.0":
# Patch postgres connection mechanism to support connection with PGHOST
# environment variable. This patch is a backport from 9.0.
patch_path = os.path.join(os.path.dirname(__file__), "sql_db-8.patch")
subprocess.check_call(["patch", "-p1", "-i", patch_path], cwd=odoo_dir)


def install_odoo():
if odoo_branch in ["8.0", "9.0", "10.0", "11.0", "12.0", "13.0"]:
if odoo_branch in ["11.0", "12.0", "13.0"]:
# setuptools 58 dropped support for 2to3, which is required
# for dependencies of older Odoo versions
subprocess.check_call(
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/script1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env click-odoo
from __future__ import print_function

env = env # noqa

Expand Down
1 change: 0 additions & 1 deletion tests/scripts/script2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env click-odoo
from __future__ import print_function

import sys

Expand Down
12 changes: 2 additions & 10 deletions tests/scripts/script5.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
# noqa
try:
import odoo.release as release
except (AttributeError, ImportError):
import openerp.release as release

if release.version_info < (10, 0):
import openerp.addons.addon1 # noqa
else:
import odoo.addons.addon1 # noqa
import odoo.addons.addon1 # noqa
import odoo.release as release # noqa
Loading

0 comments on commit 15f08e9

Please sign in to comment.