Commit 085247fa authored by Jason R. Coombs's avatar Jason R. Coombs

Use OrderedDict to retain deterministic ordering of version info in egg_info...

Use OrderedDict to retain deterministic ordering of version info in egg_info command. Remove lexicographic ordering in setopt.edit_config. Ref #553
parent df05ebf3
...@@ -13,6 +13,7 @@ import sys ...@@ -13,6 +13,7 @@ import sys
import io import io
import warnings import warnings
import time import time
import collections
from setuptools.extern import six from setuptools.extern import six
from setuptools.extern.six.moves import map from setuptools.extern.six.moves import map
...@@ -66,14 +67,20 @@ class egg_info(Command): ...@@ -66,14 +67,20 @@ class egg_info(Command):
self.vtags = None self.vtags = None
def save_version_info(self, filename): def save_version_info(self, filename):
values = dict( """
egg_info=dict( Materialize the values of svn_revision and date into the
tag_svn_revision=0, build tag. Install these keys in a deterministic order
tag_date=0, to avoid arbitrary reordering on subsequent builds.
tag_build=self.tags(), """
) # python 2.6 compatibility
) odict = getattr(collections, 'OrderedDict', dict)
edit_config(filename, values) egg_info = odict()
# follow the order these keys would have been added
# when PYTHONHASHSEED=0
egg_info['tag_date'] = 0
egg_info['tag_svn_revision'] = 0
egg_info['tag_build'] = self.tags()
edit_config(filename, dict(egg_info=egg_info))
def finalize_options(self): def finalize_options(self):
self.egg_name = safe_name(self.distribution.get_name()) self.egg_name = safe_name(self.distribution.get_name())
......
...@@ -2,7 +2,6 @@ from distutils.util import convert_path ...@@ -2,7 +2,6 @@ from distutils.util import convert_path
from distutils import log from distutils import log
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
import distutils import distutils
import operator
import os import os
from setuptools.extern.six.moves import configparser from setuptools.extern.six.moves import configparser
...@@ -43,8 +42,7 @@ def edit_config(filename, settings, dry_run=False): ...@@ -43,8 +42,7 @@ def edit_config(filename, settings, dry_run=False):
log.debug("Reading configuration from %s", filename) log.debug("Reading configuration from %s", filename)
opts = configparser.RawConfigParser() opts = configparser.RawConfigParser()
opts.read([filename]) opts.read([filename])
for section, options in sorted(settings.items(), for section, options in settings.items():
key=operator.itemgetter(0)):
if options is None: if options is None:
log.info("Deleting section [%s] from %s", section, filename) log.info("Deleting section [%s] from %s", section, filename)
opts.remove_section(section) opts.remove_section(section)
...@@ -52,8 +50,7 @@ def edit_config(filename, settings, dry_run=False): ...@@ -52,8 +50,7 @@ def edit_config(filename, settings, dry_run=False):
if not opts.has_section(section): if not opts.has_section(section):
log.debug("Adding new section [%s] to %s", section, filename) log.debug("Adding new section [%s] to %s", section, filename)
opts.add_section(section) opts.add_section(section)
for option, value in sorted(options.items(), for option, value in options.items():
key=operator.itemgetter(0)):
if value is None: if value is None:
log.debug( log.debug(
"Deleting %s.%s from %s", "Deleting %s.%s from %s",
......
...@@ -89,7 +89,7 @@ class TestEggInfo(object): ...@@ -89,7 +89,7 @@ class TestEggInfo(object):
assert 'tag_svn_revision = 0' in content assert 'tag_svn_revision = 0' in content
if sys.version_info[0:2] >= (2, 7): if sys.version_info[0:2] >= (2, 7):
assert re.search('tag_build.*tag_date.*tag_svn_revision', assert re.search('tag_date.*tag_svn_revision.*tag_build',
content, content,
re.MULTILINE | re.DOTALL) is not None re.MULTILINE | re.DOTALL) is not None
......
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