From c52c59e82fccc06e053897c0787a05d9de17329d Mon Sep 17 00:00:00 2001 From: ischnell Date: Mon, 13 Jul 2009 00:59:18 +0000 Subject: [PATCH] adding doc strings, making code more understandable git-svn-id: https://svn.enthought.com/svn/enthought/Enstaller/trunk@24107 651a555e-23ca-0310-84fe-ca9f7c59d2ea --- setuptools/command/bdist_egg.py | 64 +++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index c76d4e5..e7772c4 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -46,43 +46,61 @@ def convert_requires_txt_line(line): res = m.group(1) if m.lastindex == 2: version, build = split_old_version(m.group(2)) - res += ' %s' % version + res += ' %s' % version.replace('-', '_') if build is not None: res += '-%i' % build return res -def write_spec_depend(egg_info): +def read_requires_txt(egg_info): """ - egg_info is the path to the EGG-INFO directory + Reads requires.txt and returns a list of requirement strings, to be used + as the packages variable in spec/depend. """ - pkg_info = open(os.path.join(egg_info, 'PKG-INFO')).read() + requires_txt = os.path.join(egg_info, 'requires.txt') + if not os.path.isfile(requires_txt): + return [] + + res = [] + names = set() + for line in open(requires_txt): + req_string = convert_requires_txt_line(line) + if req_string is None: + continue + name = req_string.split()[0] + if name not in names: + res.append(req_string) + names.add(name) + return res - spec = { - 'build': 1, - 'arch': None, - 'platform': sys.platform, - 'osdist': None, - 'python': '%i.%i' % sys.version_info[:2], - 'packages': [] - } - for var in ['name', 'version']: - pat = re.compile(r'^%s:\s*(\S+)' % var, re.M | re.I) - spec[var] = pat.search(pkg_info).group(1) - requires_txt = os.path.join(egg_info, 'requires.txt') - if os.path.isfile(requires_txt): - for line in open(requires_txt): - r = convert_requires_txt_line(line) - if r and r not in spec['packages']: - spec['packages'].append(r) +def write_spec_depend(egg_info): + """ + Writes spec/depend. The information used is gathered from PKG-INFO and + requires.txt. If the version (in PKG-INFO) contains '-', which for + example happens with development versions, everything before '-' is used. + egg_info is the path to the EGG-INFO directory + """ + pkg_info = open(os.path.join(egg_info, 'PKG-INFO')).read() + name_pat = re.compile(r'^Name:\s*(\S+)', re.M) + version_pat = re.compile(r'^Version:\s*([^-\s]+)', re.M) + spec = dict( + name = name_pat.search(pkg_info).group(1), + version = version_pat.search(pkg_info).group(1), + build = 1, + arch = None, + platform = sys.platform, + osdist = None, + python = '%i.%i' % sys.version_info[:2], + packages = read_requires_txt(egg_info), + ) spec_dir = os.path.join(egg_info, 'spec') if not os.path.isdir(spec_dir): - log.info("creating dir %r" % spec_dir) + log.info("creating directory: %r" % spec_dir) os.mkdir(spec_dir) path = os.path.join(spec_dir, 'depend') - log.info("writing %r" % path) + log.info("writing: %r" % path) fo = open(path, 'w') fo.write(data_from_spec(spec)) fo.close()