Skip to content

Commit

Permalink
Unify api to call pip instead of rolling my own everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
llacroix committed Nov 16, 2022
1 parent 9b12dc8 commit 055d287
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
34 changes: 16 additions & 18 deletions odoo_tools/configuration/odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import requests
from packaging.version import parse as version_parse
from .pip import pip_command

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -129,25 +130,22 @@ def install(self):

_logger.info("Installing odoo")

args = [
sys.executable,
'-m',
'pip',
'install'
]

if hasattr(self.options, 'upgrade') and self.options.upgrade:
args.append('-U')

if hasattr(self.options, 'target') and self.options.target:
args += [
"--target", str(self.options.target),
"--implementation", "cp",
"--python", "3.8",
# "--only-binary", ":all:"
"--no-deps",
]
target = (
self.options.target
if hasattr(self.options, 'target') and self.options.target
else None
)

upgrade = (
self.options.upgrade
if hasattr(self.options, 'upgrade') and self.options.upgrade
else False
)

args = pip_command(target=target, upgrade=upgrade)

# Ensure setuptools less than 58 is installed for odoo
# versions from 11 to 13.
if (
self.parsed_version.major > 10 and
self.parsed_version.major < 14
Expand Down
31 changes: 31 additions & 0 deletions odoo_tools/configuration/pip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys


def pip_command(user=None, target=None, upgrade=False):
base_install_args = [
sys.executable,
'-m',
'pip',
'install',
]

args = []
if user is True:
args.append('--user')

if target is not None:
python_version = (
f"{sys.version_info.major}.{sys.version_info.minor}"
)
args += [
"--target", str(target),
"--implementation", "cp",
"--python", python_version,
# "--only-binary", ":all:"
"--no-deps",
]

if upgrade:
args.append('-U')

return base_install_args + args
11 changes: 6 additions & 5 deletions odoo_tools/docker/user_entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import tempfile
import time
import os
Expand All @@ -7,6 +8,7 @@

from ..utils import random_string
from ..compat import pipe, Path
from ..configuration.pip import pip_command


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -101,12 +103,11 @@ def install_python_dependencies(env):
_logger.info("Requirements:\n%s", data)
fout.write(data)

retcode = pipe([
"pip",
"install",
"--user",
args = pip_command(user=True) + [
"-r", str(file_path)
])
]

retcode = pipe(args)

if env.context.strict_mode and retcode != 0:
raise Exception("Failed to install pip dependencies")
Expand Down

0 comments on commit 055d287

Please sign in to comment.