summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author?ric Araujo <merwok@netwok.org>2012-05-16 00:45:26 -0400
committer?ric Araujo <merwok@netwok.org>2012-05-16 00:45:26 -0400
commit25e1a0abddeb237490a50e4d6ed4bb584ccdb91e (patch)
treec5b82dc7ceadcce62ecbafaadc2d63d1a3493dba
parent0901dedfe3e409b488227aad1112f09752e87048 (diff)
downloaddisutils2-25e1a0abddeb237490a50e4d6ed4bb584ccdb91e.tar.gz
Fix minor whitespace, syntax and idiom nits
-rw-r--r--distutils2/database.py9
-rw-r--r--distutils2/install.py11
-rw-r--r--distutils2/metadata.py1
-rw-r--r--distutils2/run.py21
-rw-r--r--distutils2/tests/test_command_build_scripts.py26
-rw-r--r--distutils2/tests/test_command_register.py22
-rw-r--r--distutils2/tests/test_install.py2
-rw-r--r--distutils2/tests/test_metadata.py4
-rw-r--r--distutils2/tests/test_support.py2
-rw-r--r--distutils2/util.py63
10 files changed, 74 insertions, 87 deletions
diff --git a/distutils2/database.py b/distutils2/database.py
index 37d7c7e..42528e8 100644
--- a/distutils2/database.py
+++ b/distutils2/database.py
@@ -302,7 +302,6 @@ class EggInfoDistribution(object):
"""A :class:`distutils2.metadata.Metadata` instance loaded with
the distribution's ``METADATA`` file."""
-
def __init__(self, path):
self.path = path
if _cache_enabled and path in _cache_path_egg:
@@ -311,8 +310,6 @@ class EggInfoDistribution(object):
self.version = self.metadata['Version']
return
-
-
requires = None
if path.endswith('.egg'):
@@ -347,16 +344,12 @@ class EggInfoDistribution(object):
raise ValueError('path must end with .egg-info or .egg, got %r' %
path)
- if requires is not None:
+ if requires:
if self.metadata['Metadata-Version'] == '1.1':
# we can't have 1.1 metadata *and* Setuptools requires
for field in ('Obsoletes', 'Requires', 'Provides'):
if field in self.metadata:
del self.metadata[field]
-
-
-
- if requires is not None and len(requires)>0:
self.metadata['Requires-Dist'] += requires
if _cache_enabled:
diff --git a/distutils2/install.py b/distutils2/install.py
index 24fa568..e99dd0f 100644
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -60,8 +60,10 @@ def _move_files(files, destination):
def _run_distutils_install(path, dest):
# backward compat: using setuptools or plain-distutils
+ # FIXME pass dest argument to the command
cmd = '%s setup.py install --record=%s'
record_file = os.path.join(path, 'RECORD')
+ # FIXME use subprocess
os.system(cmd % (sys.executable, record_file))
if not os.path.exists(record_file):
raise ValueError('failed to install')
@@ -85,7 +87,7 @@ def _run_packaging_install(path, dest):
dist = Distribution()
dist.parse_config_files()
try:
- dist.run_command('install_dist', dict(prefix=(None,dest)))
+ dist.run_command('install_dist', {'prefix': (None, dest)})
name = dist.metadata['Name']
return database.get_distribution(name) is not None
except (IOError, os.error, PackagingError, CCompilerError), msg:
@@ -152,15 +154,14 @@ install_methods = {
'distutils': _run_distutils_install}
-def _run_install_from_dir(source_dir, destination_dir=None):
+def _run_install_from_dir(source_dir, dest_dir=None):
old_dir = os.getcwd()
os.chdir(source_dir)
- install_method = get_install_method(source_dir)
- func = install_methods[install_method]
try:
+ install_method = get_install_method(source_dir)
func = install_methods[install_method]
try:
- func(source_dir, destination_dir)
+ func(source_dir, dest_dir)
return True
except ValueError, err:
# failed to install
diff --git a/distutils2/metadata.py b/distutils2/metadata.py
index 7b66ba6..5ff5867 100644
--- a/distutils2/metadata.py
+++ b/distutils2/metadata.py
@@ -38,7 +38,6 @@ try:
return nodes.system_message(message, level=level, type=self.
levels[level], *children, **kwargs)
-
_HAS_DOCUTILS = True
except ImportError:
# docutils is not installed
diff --git a/distutils2/run.py b/distutils2/run.py
index 1729761..35edd06 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -653,17 +653,16 @@ def main(args=None):
old_level = logger.level
old_handlers = list(logger.handlers)
try:
- try:
- dispatcher = Dispatcher(args)
- if dispatcher.action is None:
- return
- return dispatcher()
- except KeyboardInterrupt:
- logger.info('interrupted')
- return 1
- except (IOError, os.error, PackagingError, CCompilerError), exc:
- logger.exception(exc)
- return 1
+ dispatcher = Dispatcher(args)
+ if dispatcher.action is None:
+ return
+ return dispatcher()
+ except KeyboardInterrupt:
+ logger.info('interrupted')
+ return 1
+ except (IOError, os.error, PackagingError, CCompilerError), exc:
+ logger.exception(exc)
+ return 1
finally:
logger.setLevel(old_level)
logger.handlers[:] = old_handlers
diff --git a/distutils2/tests/test_command_build_scripts.py b/distutils2/tests/test_command_build_scripts.py
index 9747153..90d2b28 100644
--- a/distutils2/tests/test_command_build_scripts.py
+++ b/distutils2/tests/test_command_build_scripts.py
@@ -38,7 +38,8 @@ class BuildScriptsTestCase(support.TempdirManager,
for name in expected:
self.assertIn(name, built)
- def get_build_scripts_cmd(self, target, scripts, executable=sys.executable):
+ def get_build_scripts_cmd(self, target, scripts,
+ executable=sys.executable):
dist = Distribution()
dist.scripts = scripts
dist.command_obj["build"] = support.DummyCommand(
@@ -82,10 +83,8 @@ class BuildScriptsTestCase(support.TempdirManager,
target = self.mkdtemp()
expected = self.write_sample_scripts(source)
-
- cmd = self.get_build_scripts_cmd(target,
- [os.path.join(source, fn)
- for fn in expected])
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, fn) for fn in expected])
cmd.finalize_options()
# http://bugs.python.org/issue4524
@@ -112,18 +111,25 @@ class BuildScriptsTestCase(support.TempdirManager,
built = os.path.join(target, 'taunt')
- cmd = self.get_build_scripts_cmd(target, [os.path.join(source, 'taunt')], 'pythona')
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, 'taunt')], 'pythona')
cmd.finalize_options()
cmd.run()
- self.assertEqual(open(built).readline(), '#!pythona\n')
+ with open(built) as fp:
+ firstline = fp.readline().strip()
+ self.assertEqual(firstline, '#!pythona')
- cmd = self.get_build_scripts_cmd(target, [os.path.join(source, 'taunt')], 'pythonx')
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, 'taunt')], 'pythonx')
cmd.finalize_options()
cmd.run()
- self.assertEqual(open(built).readline(), '#!pythonx\n')
-
+ with open(built) as fp:
+ firstline = fp.readline().strip()
+ self.assertEqual(firstline, '#!pythonx')
+
+
def test_suite():
return unittest.makeSuite(BuildScriptsTestCase)
diff --git a/distutils2/tests/test_command_register.py b/distutils2/tests/test_command_register.py
index 5fc8e99..7cdb6ce 100644
--- a/distutils2/tests/test_command_register.py
+++ b/distutils2/tests/test_command_register.py
@@ -3,14 +3,9 @@
import os
import getpass
import urllib2
-try:
- import docutils
- DOCUTILS_SUPPORT = True
-except ImportError:
- DOCUTILS_SUPPORT = False
from distutils2.tests import unittest, support
-from distutils2.tests.support import (Inputs, requires_docutils)
+from distutils2.tests.support import Inputs, requires_docutils
from distutils2.command import register as register_module
from distutils2.command.register import register
from distutils2.errors import PackagingSetupError
@@ -188,7 +183,7 @@ class RegisterTestCase(support.TempdirManager,
self.assertEqual(headers['Content-length'], '298')
self.assertIn('tarek', req.data)
- @unittest.skipUnless(DOCUTILS_SUPPORT, 'needs docutils')
+ @requires_docutils
def test_strict(self):
# testing the strict option: when on, the register command stops if the
# metadata is incomplete or if description contains bad reST
@@ -255,14 +250,11 @@ class RegisterTestCase(support.TempdirManager,
@requires_docutils
def test_register_invalid_long_description(self):
- # Contains :func: which break the rst format
- data = "Default :func:`prompt` callback shows"
-
+ description = ':funkie:`str`' # mimic Sphinx-specific markup
metadata = {'Home-page': 'xxx', 'Author': 'xxx',
'Author-email': 'xxx',
- 'Name': 'xxx', 'Version': 'xxx'}
-
- metadata['Description'] = data
+ 'Name': 'xxx', 'Version': 'xxx',
+ 'Description': description}
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
cmd.strict = True
@@ -270,8 +262,8 @@ class RegisterTestCase(support.TempdirManager,
register_module.raw_input = inputs
with self.assertRaises(PackagingSetupError) as e:
cmd.run()
- self.assertIsNotNone(e)
- self.assertIn('func', repr(e.exception))
+ self.assertIn('funkie', str(e.exception))
+
def test_suite():
return unittest.makeSuite(RegisterTestCase)
diff --git a/distutils2/tests/test_install.py b/distutils2/tests/test_install.py
index f613b22..59e7d51 100644
--- a/distutils2/tests/test_install.py
+++ b/distutils2/tests/test_install.py
@@ -1,7 +1,6 @@
"""Tests for the distutils2.install module."""
import os
import logging
-import sys
from tempfile import mkstemp
@@ -262,7 +261,6 @@ class TestInstall(LoggingCatcher, TempdirManager, unittest.TestCase):
def test_install_custom_dir(self):
dest = self.mkdtemp()
- src = self.mkdtemp()
project_dir, dist = self.create_dist(
name='Spamlib', version='0.1',
diff --git a/distutils2/tests/test_metadata.py b/distutils2/tests/test_metadata.py
index 8bb9ec2..600d5ea 100644
--- a/distutils2/tests/test_metadata.py
+++ b/distutils2/tests/test_metadata.py
@@ -383,8 +383,8 @@ class MetadataTestCase(LoggingCatcher,
def test_description_invalid_rst(self):
# make sure bad rst is well handled in the description attribute
metadata = Metadata()
- description_with_bad_rst = ':funkie:`str`' # Sphinx-specific markup
- metadata['description'] = description_with_bad_rst
+ description = ':funkie:`str`' # mimic Sphinx-specific markup
+ metadata['description'] = description
missing, warnings = metadata.check(restructuredtext=True)
warning = warnings[0][1]
self.assertIn('funkie', warning)
diff --git a/distutils2/tests/test_support.py b/distutils2/tests/test_support.py
index 5640fcd..15fd75f 100644
--- a/distutils2/tests/test_support.py
+++ b/distutils2/tests/test_support.py
@@ -21,7 +21,7 @@ class TestingSupportTestCase(unittest.TestCase):
def runTest(self):
# empty method required for the backport
pass
-
+
def test_mktempfile(self2):
tmpfile = self2.mktempfile()
files['test_mktempfile'] = tmpfile.name
diff --git a/distutils2/util.py b/distutils2/util.py
index 4281de0..4297e2f 100644
--- a/distutils2/util.py
+++ b/distutils2/util.py
@@ -1173,13 +1173,16 @@ def _write_record_file(record_path, installed_files):
f.close()
return record_path
+
def parse_requires(req_path):
- """Takes the raw content of a requires.txt file and returns a list of requirements"""
+ """Create a list of dependencies from a requires.txt file.
+
+ *req_path* must be the path to a setuptools-produced requires.txt file.
+ """
# reused from Distribute's pkg_resources
def yield_lines(strs):
- """Yield non-empty/non-comment lines of a ``basestring``
- or sequence"""
+ """Yield non-empty/non-comment lines of a string or sequence"""
if isinstance(strs, basestring):
for s in strs.splitlines():
s = s.strip()
@@ -1208,37 +1211,35 @@ def parse_requires(req_path):
return None
for line in yield_lines(requires):
- if line.startswith('['):
- logger.warning('extensions in requires.txt are not supported')
- break
+ if line.startswith('['):
+ logger.warning('extensions in requires.txt are not supported')
+ break
+ else:
+ match = _REQUIREMENT.match(line.strip())
+ if not match:
+ # this happens when we encounter extras; since they
+ # are written at the end of the file we just exit
+ break
+ else:
+ if match.group('extras'):
+ # msg = ('extra requirements are not supported '
+ # '(used by %r %s)', self.name, self.version)
+ msg = 'extra requirements are not supported'
+ logger.warning(msg)
+ name = match.group('name')
+ version = None
+ if match.group('first'):
+ version = match.group('first')
+ if match.group('rest'):
+ version += match.group('rest')
+ version = version.replace(' ', '') # trim spaces
+ if version is None:
+ reqs.append(name)
else:
- match = _REQUIREMENT.match(line.strip())
- if not match:
- # this happens when we encounter extras; since they
- # are written at the end of the file we just exit
- break
- else:
- if match.group('extras'):
- # msg = ('extra requirements are not supported '
- # '(used by %r %s)', self.name, self.version)
- msg = 'extra requirements are not supported'
- logger.warning(msg)
- name = match.group('name')
- version = None
- if match.group('first'):
- version = match.group('first')
- if match.group('rest'):
- version += match.group('rest')
- version = version.replace(' ', '') # trim spaces
- if version is None:
- reqs.append(name)
- else:
- reqs.append('%s (%s)' % (name, version))
+ reqs.append('%s (%s)' % (name, version))
return reqs
-
-
def egginfo_to_distinfo(record_file, installer=_DEFAULT_INSTALLER,
requested=False, remove_egginfo=False):
"""Create files and directories required for PEP 376
@@ -1277,8 +1278,6 @@ def egginfo_to_distinfo(record_file, installer=_DEFAULT_INSTALLER,
metadata['Requires-Dist'] = requires
metadata.write(metadata_path)
-
-
installer_path = distinfo['installer_path']
logger.info('creating %s', installer_path)
f = open(installer_path, 'w')