Rework package_builder
A bunch of updates to package_builder: - remove source from the package - better support Gerrit dependencies - pass system dependencies into Package
This commit is contained in:
parent
83891b64bd
commit
c9137f7f39
|
@ -17,6 +17,7 @@
|
|||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from giftwrap.gerrit import GerritReview
|
||||
from giftwrap.openstack_git_repo import OpenstackGitRepo
|
||||
|
@ -38,43 +39,67 @@ class PackageBuilder(Builder):
|
|||
def _validate_settings(self):
|
||||
pass
|
||||
|
||||
def _build(self):
|
||||
spec = self._spec
|
||||
|
||||
for project in spec.projects:
|
||||
LOG.info("Beginning to build '%s'", project.name)
|
||||
|
||||
# if anything is in our way, see if we can get rid of it
|
||||
if (os.path.exists(project.install_path) and
|
||||
spec.settings.force_overwrite):
|
||||
LOG.info("force_overwrite is set, so removing "
|
||||
"existing path '%s'" % project.install_path)
|
||||
shutil.rmtree(project.install_path)
|
||||
else:
|
||||
raise Exception("Install path '%s' already exists" %
|
||||
project.install_path)
|
||||
os.makedirs(project.install_path)
|
||||
|
||||
LOG.info("Fetching source code for '%s'", project.name)
|
||||
repo = OpenstackGitRepo(project.giturl, project.gitref)
|
||||
repo.clone(project.install_path)
|
||||
review = GerritReview(repo.change_id, project.git_path)
|
||||
|
||||
LOG.info("Creating the virtualenv for '%s'", project.name)
|
||||
execute(project.venv_command, project.install_path)
|
||||
|
||||
def _install_gerrit_dependencies(self, repo, project):
|
||||
try:
|
||||
review = GerritReview(repo.head.change_id, project.git_path)
|
||||
LOG.info("Installing '%s' pip dependencies to the virtualenv",
|
||||
project.name)
|
||||
execute(project.install_command %
|
||||
review.build_pip_dependencies(string=True),
|
||||
project.install_path)
|
||||
except Exception as e:
|
||||
LOG.warning("Could not install gerrit dependencies!!! "
|
||||
"Error was: %s", e)
|
||||
|
||||
def _build(self):
|
||||
spec = self._spec
|
||||
|
||||
tempdir = tempfile.mkdtemp(prefix='giftwrap')
|
||||
src_dir = os.path.join(tempdir, 'src')
|
||||
LOG.debug("Temporary working directory: %s", tempdir)
|
||||
|
||||
for project in spec.projects:
|
||||
LOG.info("Beginning to build '%s'", project.name)
|
||||
|
||||
# if anything is in our way, see if we can get rid of it
|
||||
if os.path.exists(project.install_path):
|
||||
if spec.settings.force_overwrite:
|
||||
LOG.info("force_overwrite is set, so removing "
|
||||
"existing path '%s'" % project.install_path)
|
||||
shutil.rmtree(project.install_path)
|
||||
else:
|
||||
raise Exception("Install path '%s' already exists" %
|
||||
project.install_path)
|
||||
os.makedirs(project.install_path)
|
||||
|
||||
# clone the project's source to a temporary directory
|
||||
project_src_path = os.path.join(src_dir, project.name)
|
||||
os.makedirs(project_src_path)
|
||||
|
||||
LOG.info("Fetching source code for '%s'", project.name)
|
||||
repo = OpenstackGitRepo(project.giturl, project.gitref)
|
||||
repo.clone(project_src_path)
|
||||
|
||||
# start building the virtualenv for the project
|
||||
LOG.info("Creating the virtualenv for '%s'", project.name)
|
||||
execute(project.venv_command, project.install_path)
|
||||
|
||||
# install into the virtualenv
|
||||
LOG.info("Installing '%s' to the virtualenv", project.name)
|
||||
execute(".venv/bin/python setup.py install",
|
||||
project.install_path)
|
||||
venv_python_path = os.path.join(project.install_path, 'bin/python')
|
||||
venv_pip_path = os.path.join(project.install_path, 'bin/pip')
|
||||
|
||||
if not spec.settings.all_in_one:
|
||||
pkg = Package(project.package_name, project.version,
|
||||
project.install_path, True,
|
||||
spec.settings.force_overwrite)
|
||||
pkg.build()
|
||||
deps = " ".join(project.pip_dependencies)
|
||||
execute("%s install %s" % (venv_pip_path, deps))
|
||||
|
||||
if spec.settings.gerrit_dependencies:
|
||||
self._install_gerrit_dependencies(repo, project)
|
||||
|
||||
execute("%s setup.py install" % venv_python_path, project_src_path)
|
||||
execute("%s install pbr" % venv_pip_path)
|
||||
|
||||
# now build the package
|
||||
pkg = Package(project.package_name, project.version,
|
||||
project.install_path, spec.settings.force_overwrite,
|
||||
project.system_dependencies)
|
||||
pkg.build()
|
||||
|
|
|
@ -24,8 +24,8 @@ DEFAULT_GITURL = {
|
|||
'openstack': 'https://git.openstack.org/openstack/',
|
||||
'stackforge': 'https://github.com/stackforge/'
|
||||
}
|
||||
DEFAULT_VENV_COMMAND = "virtualenv .venv"
|
||||
DEFAULT_INSTALL_COMMAND = ".venv/bin/pip install --extra-index http://pypi.openstack.org/openstack/ %s" # noqa
|
||||
DEFAULT_VENV_COMMAND = "virtualenv ."
|
||||
DEFAULT_INSTALL_COMMAND = "./bin/pip install %s" # noqa
|
||||
|
||||
TEMPLATE_VARS = ('name', 'version', 'gitref', 'stackforge')
|
||||
|
||||
|
@ -120,5 +120,5 @@ class OpenstackProject(object):
|
|||
return t.render(self._template_vars())
|
||||
|
||||
@staticmethod
|
||||
def factory(settings, project_dict):
|
||||
return OpenstackProject(settings, **project_dict)
|
||||
def factory(settings, project_dict, version):
|
||||
return OpenstackProject(settings, version=version, **project_dict)
|
||||
|
|
Loading…
Reference in New Issue