Introduce upper constraints
This is a global setting that will apply across every project, a constraint on the versions of things that can be installed via pip. This is a first pass, adding basic functionality, by allowing a single constraint URL to be provided. Future iterations of this feature may be tied to a "superrepo" that contains all the projects _and_ the constraints for those projects all in one place. Change-Id: Ib5c2dd441b9294b775e755e595486a671d8de57f
This commit is contained in:
parent
6b40cee8bf
commit
bdd3f84652
|
@ -16,6 +16,7 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
import requests
|
||||
import threading
|
||||
|
||||
from giftwrap.gerrit import GerritReview
|
||||
|
@ -36,6 +37,7 @@ class Builder(object):
|
|||
self._temp_src_dir = None
|
||||
self._spec = spec
|
||||
self._thread_exit = []
|
||||
self._constraints = None
|
||||
|
||||
@staticmethod
|
||||
def builder_names(ext_mgr=None):
|
||||
|
@ -55,6 +57,27 @@ class Builder(object):
|
|||
"Error was: %s", e)
|
||||
return []
|
||||
|
||||
def _get_upper_constraints(self):
|
||||
try:
|
||||
curl = self._spec.settings.upper_constraints
|
||||
response = requests.get(curl)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise Exception("Unable to get constraints at %s. Error: %d" %
|
||||
(curl, response.status_code))
|
||||
|
||||
constraints = response.text.encode('utf-8')
|
||||
|
||||
cfile = os.path.join(self._temp_src_dir, 'constraints.txt')
|
||||
|
||||
with open(cfile, 'w') as f:
|
||||
f.write(constraints)
|
||||
|
||||
return cfile
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("Unable to construct constraints. Error: %s" % e)
|
||||
|
||||
def _build_project(self, project):
|
||||
try:
|
||||
self._prepare_project_build(project)
|
||||
|
@ -81,6 +104,9 @@ class Builder(object):
|
|||
if self._spec.settings.include_config:
|
||||
self._copy_sample_config(src_clone_dir, project)
|
||||
|
||||
if self._spec.settings.upper_constraints:
|
||||
self._constraints = self._get_upper_constraints()
|
||||
|
||||
self._install_project(project.install_path, src_clone_dir)
|
||||
|
||||
if project.postinstall_dependencies:
|
||||
|
|
|
@ -84,8 +84,11 @@ class DockerBuilder(Builder):
|
|||
|
||||
def _install_pip_dependencies(self, venv_path, dependencies):
|
||||
pip_path = self._get_venv_pip_path(venv_path)
|
||||
install = "install"
|
||||
if self._constraints:
|
||||
install += " -c %s" % self._constraints
|
||||
for dependency in dependencies:
|
||||
self._execute("%s install %s" % (pip_path, dependency))
|
||||
self._execute("%s %s %s" % (pip_path, install, dependency))
|
||||
|
||||
def _copy_sample_config(self, src_clone_dir, project):
|
||||
src_config = os.path.join(src_clone_dir, 'etc')
|
||||
|
@ -96,7 +99,10 @@ class DockerBuilder(Builder):
|
|||
|
||||
def _install_project(self, venv_path, src_clone_dir):
|
||||
pip_path = self._get_venv_pip_path(venv_path)
|
||||
self._execute("%s install %s" % (pip_path, src_clone_dir))
|
||||
install = "install"
|
||||
if self._constraints:
|
||||
install += " -c %s" % self._constraints
|
||||
self._execute("%s %s %s" % (pip_path, install, src_clone_dir))
|
||||
|
||||
def _finalize_project_build(self, project):
|
||||
self._commands.append("rm -rf %s" % self._temp_dir)
|
||||
|
|
|
@ -70,8 +70,11 @@ class PackageBuilder(Builder):
|
|||
|
||||
def _install_pip_dependencies(self, venv_path, dependencies):
|
||||
pip_path = self._get_venv_pip_path(venv_path)
|
||||
install = "install"
|
||||
if self._constraints:
|
||||
install += " -c %s" % self._constraints
|
||||
for dependency in dependencies:
|
||||
self._execute("%s install %s" % (pip_path, dependency))
|
||||
self._execute("%s %s %s" % (pip_path, install, dependency))
|
||||
|
||||
def _copy_sample_config(self, src_clone_dir, project):
|
||||
src_config = os.path.join(src_clone_dir, 'etc')
|
||||
|
@ -87,7 +90,10 @@ class PackageBuilder(Builder):
|
|||
|
||||
def _install_project(self, venv_path, src_clone_dir):
|
||||
pip_path = self._get_venv_pip_path(venv_path)
|
||||
self._execute("%s install %s" % (pip_path, src_clone_dir))
|
||||
install = "install"
|
||||
if self._constraints:
|
||||
install += " -c %s" % self._constraints
|
||||
self._execute("%s %s %s" % (pip_path, install, src_clone_dir))
|
||||
|
||||
def _finalize_project_build(self, project):
|
||||
# build the package
|
||||
|
|
|
@ -31,7 +31,7 @@ class Settings(object):
|
|||
package_name_format=None, version=None,
|
||||
base_path=None, install_path=None, gerrit_dependencies=True,
|
||||
force_overwrite=False, output_dir=None, include_config=True,
|
||||
parallel_build=True):
|
||||
parallel_build=True, upper_constraints=None):
|
||||
if not version:
|
||||
raise Exception("'version' is a required settings")
|
||||
self.build_type = build_type
|
||||
|
@ -44,6 +44,7 @@ class Settings(object):
|
|||
self._output_dir = output_dir
|
||||
self.include_config = include_config
|
||||
self.parallel_build = parallel_build
|
||||
self.upper_constraints = upper_constraints
|
||||
|
||||
@property
|
||||
def package_name_format(self):
|
||||
|
|
Loading…
Reference in New Issue