Commit 188827f9 authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: loop forever when upgrading

Solution:
- better detection of need for upgrade
- more protection break by restarting only once
parent 37639717
...@@ -4,6 +4,8 @@ Change History ...@@ -4,6 +4,8 @@ Change History
3.0.0 (unreleased) 3.0.0 (unreleased)
================== ==================
- Fix forever loop when changing ``zc.buildout`` version via ``buildout``.
- Add support for ``Requires-Python`` metadata. - Add support for ``Requires-Python`` metadata.
Fragile monkeypatch that relies on ``pip._internal``. Fragile monkeypatch that relies on ``pip._internal``.
Emits a warning when support is disabled due to changes in ``pip``. Emits a warning when support is disabled due to changes in ``pip``.
......
...@@ -32,6 +32,8 @@ import copy ...@@ -32,6 +32,8 @@ import copy
import datetime import datetime
import distutils.errors import distutils.errors
import glob import glob
import importlib
import inspect
import itertools import itertools
import logging import logging
import os import os
...@@ -1090,6 +1092,9 @@ class Buildout(DictMixin): ...@@ -1090,6 +1092,9 @@ class Buildout(DictMixin):
# If they do, do the upgrade and restart the buildout process. # If they do, do the upgrade and restart the buildout process.
__doing__ = 'Checking for upgrades.' __doing__ = 'Checking for upgrades.'
if self['buildout'].get('restart-after-upgrade', '') == 'true':
return
if not self.newest: if not self.newest:
return return
...@@ -1103,14 +1108,13 @@ class Buildout(DictMixin): ...@@ -1103,14 +1108,13 @@ class Buildout(DictMixin):
) )
upgraded = [] upgraded = []
# The setuptools/zc.buildout locations at the time we started was
# recorded in easy_install.py. We use that here to check if we've been
# upgraded.
start_locations = zc.buildout.easy_install.buildout_and_setuptools_path
for project in 'zc.buildout', 'setuptools', 'pip', 'wheel': for project in 'zc.buildout', 'setuptools', 'pip', 'wheel':
req = pkg_resources.Requirement.parse(project) req = pkg_resources.Requirement.parse(project)
if ws.find(req).location not in start_locations: dist = ws.find(req)
upgraded.append(ws.find(req)) importlib.import_module(project)
if not inspect.getfile(sys.modules[project]).startswith(dist.location):
upgraded.append(dist)
if not upgraded: if not upgraded:
return return
...@@ -1154,6 +1158,7 @@ class Buildout(DictMixin): ...@@ -1154,6 +1158,7 @@ class Buildout(DictMixin):
# Restart # Restart
args = sys.argv[:] args = sys.argv[:]
args.insert(1, '--restart-after-upgrade')
if not __debug__: if not __debug__:
args.insert(0, '-O') args.insert(0, '-O')
args.insert(0, sys.executable) args.insert(0, sys.executable)
...@@ -2142,7 +2147,10 @@ def main(args=None): ...@@ -2142,7 +2147,10 @@ def main(args=None):
_help() _help()
elif orig_op == '--version': elif orig_op == '--version':
_version() _version()
_error("Invalid option", '-'+op[0]) elif orig_op == '--restart-after-upgrade':
options.append(('buildout', 'restart-after-upgrade', "true"))
else:
_error("Invalid option", '-'+op[0])
elif '=' in args[0]: elif '=' in args[0]:
option, value = args.pop(0).split('=', 1) option, value = args.pop(0).split('=', 1)
option = option.split(':') option = option.split(':')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment