Skip to content

Commit

Permalink
Saner auto requirements installation
Browse files Browse the repository at this point in the history
- Shortcut for installation that reduces the logic size.
- Cannot install from repositories before aggregation.
- Auto dependencies should come in before manual ones.
- Drop support of deprecated /opt/custom/src/requirements.txt file.
  • Loading branch information
yajo committed Aug 11, 2017
1 parent 8240246 commit 4430752
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 53 deletions.
51 changes: 0 additions & 51 deletions build.d/100-dependencies

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions build.d/200-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python
# Copyright 2017 LasLabs Inc.

from os.path import join

from odoobaselib import (
addons_config,
AUTO_REQUIREMENTS,
CUSTOM_DIR,
FILE_APT_BUILD,
SRC_DIR,
)
from odoobaselib.installer import install, INSTALLERS


# Build dependencies installed before any others
install("apt", FILE_APT_BUILD)

for name in INSTALLERS:
req_files = []
# pip `requirements.txt` files found in repositories
if name == "pip" and AUTO_REQUIREMENTS:
for repo in addons_config():
req_files.append(join(SRC_DIR, repo, 'requirements.txt'))
# Normal dependency installation
req_files.append(join(CUSTOM_DIR, 'dependencies', '%s.txt' % name))
for req_file in req_files:
install(name, req_file)
11 changes: 9 additions & 2 deletions lib/odoobaselib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def cleanup(self):
def install(self):
"""Install the requirements from the given file."""
if self._requirements:
self._run_command(self._install_command + self._requirements)
return not self._run_command(
self._install_command + self._requirements)
else:
logging.info("No installable requirements found in %s",
self.file_path)
return False

def remove(self):
"""Uninstall the requirements from the given file."""
Expand Down Expand Up @@ -102,7 +104,7 @@ class PipInstaller(Installer):

def requirements(self):
"""Pip will use its ``--requirements`` feature."""
return [self.file_path]
return [self.file_path] if exists(self.file_path) else []


INSTALLERS = {
Expand All @@ -111,3 +113,8 @@ def requirements(self):
"npm": NpmInstaller,
"pip": PipInstaller,
}


def install(installer, file_path):
"""Perform a given type of installation from a given file."""
return INSTALLERS[installer](file_path).install()

0 comments on commit 4430752

Please sign in to comment.