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