summaryrefslogtreecommitdiff
path: root/distutils2
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2011-01-29 12:59:03 +0100
committerTarek Ziade <tarek@ziade.org>2011-01-29 12:59:03 +0100
commit4aa91e6aeb12e093c297f5cc439407ffa59ea156 (patch)
tree7d426becd92b78d9f6a97222117e1f8e57d308d4 /distutils2
parentdeb4f4480f20f5c9f1321ec35599ee401bc96b2f (diff)
downloaddisutils2-4aa91e6aeb12e093c297f5cc439407ffa59ea156.tar.gz
simplified the package_dir option - just one root dir allowed
Diffstat (limited to 'distutils2')
-rw-r--r--distutils2/command/build_py.py46
-rw-r--r--distutils2/config.py6
-rw-r--r--distutils2/install.py7
-rw-r--r--distutils2/run.py1
-rw-r--r--distutils2/tests/test_command_build_ext.py6
-rw-r--r--distutils2/tests/test_command_build_py.py24
-rw-r--r--distutils2/tests/test_config.py23
7 files changed, 51 insertions, 62 deletions
diff --git a/distutils2/command/build_py.py b/distutils2/command/build_py.py
index c3e4878..0956fa8 100644
--- a/distutils2/command/build_py.py
+++ b/distutils2/command/build_py.py
@@ -66,10 +66,9 @@ class build_py(Command, Mixin2to3):
self.packages = self.distribution.packages
self.py_modules = self.distribution.py_modules
self.package_data = self.distribution.package_data
- self.package_dir = {}
- if self.distribution.package_dir:
- for name, path in self.distribution.package_dir.iteritems():
- self.package_dir[name] = convert_path(path)
+ self.package_dir = None
+ if self.distribution.package_dir is not None:
+ self.package_dir = convert_path(self.distribution.package_dir)
self.data_files = self.get_data_files()
# Ick, copied straight from install_lib.py (fancy_getopt needs a
@@ -179,41 +178,14 @@ class build_py(Command, Mixin2to3):
"""Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any)."""
-
path = package.split('.')
+ if self.package_dir is not None:
+ path.insert(0, self.package_dir)
- if not self.package_dir:
- if path:
- return os.path.join(*path)
- else:
- return ''
- else:
- tail = []
- while path:
- try:
- pdir = self.package_dir['.'.join(path)]
- except KeyError:
- tail.insert(0, path[-1])
- del path[-1]
- else:
- tail.insert(0, pdir)
- return os.path.join(*tail)
- else:
- # Oops, got all the way through 'path' without finding a
- # match in package_dir. If package_dir defines a directory
- # for the root (nameless) package, then fallback on it;
- # otherwise, we might as well have not consulted
- # package_dir at all, as we just use the directory implied
- # by 'tail' (which should be the same as the original value
- # of 'path' at this point).
- pdir = self.package_dir.get('')
- if pdir is not None:
- tail.insert(0, pdir)
-
- if tail:
- return os.path.join(*tail)
- else:
- return ''
+ if len(path) > 0:
+ return os.path.join(*path)
+
+ return ''
def check_package(self, package, package_dir):
"""Helper function for `find_package_modules()` and `find_modules()'.
diff --git a/distutils2/config.py b/distutils2/config.py
index a1b03d1..f6f78f6 100644
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -138,16 +138,12 @@ class Config(object):
files = dict([(key, self._multiline(value))
for key, value in content['files'].iteritems()])
self.dist.packages = []
- self.dist.package_dir = {}
-
+ self.dist.package_dir = pkg_dir = files.get('packages_root')
packages = files.get('packages', [])
if isinstance(packages, str):
packages = [packages]
for package in packages:
- if ':' in package:
- dir_, package = package.split(':')
- self.dist.package_dir[package] = dir_
self.dist.packages.append(package)
self.dist.py_modules = files.get('modules', [])
diff --git a/distutils2/install.py b/distutils2/install.py
index 8daf0e0..6cee781 100644
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -208,6 +208,13 @@ def _update_infos(infos, new_infos):
infos[key].extend(new_infos[key])
+def remove(project_name):
+ """Removes a single project from the installation"""
+ pass
+
+
+
+
def main(**attrs):
if 'script_args' not in attrs:
import sys
diff --git a/distutils2/run.py b/distutils2/run.py
index 429ce3d..e5c628b 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -109,6 +109,7 @@ def commands_main(**attrs):
except (DistutilsError,
CCompilerError), msg:
+ raise
raise SystemExit, "error: " + str(msg)
return dist
diff --git a/distutils2/tests/test_command_build_ext.py b/distutils2/tests/test_command_build_ext.py
index 8b707d1..2434e33 100644
--- a/distutils2/tests/test_command_build_ext.py
+++ b/distutils2/tests/test_command_build_ext.py
@@ -289,7 +289,7 @@ class BuildExtTestCase(support.TempdirManager,
# inplace = 0, cmd.package = 'bar'
build_py = cmd.get_finalized_command('build_py')
- build_py.package_dir = {'': 'bar'}
+ build_py.package_dir = 'bar'
path = cmd.get_ext_fullpath('foo')
# checking that the last directory is the build_dir
path = os.path.split(path)[0]
@@ -318,7 +318,7 @@ class BuildExtTestCase(support.TempdirManager,
dist = Distribution()
cmd = build_ext(dist)
cmd.inplace = 1
- cmd.distribution.package_dir = {'': 'src'}
+ cmd.distribution.package_dir = 'src'
cmd.distribution.packages = ['lxml', 'lxml.html']
curdir = os.getcwd()
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
@@ -334,7 +334,7 @@ class BuildExtTestCase(support.TempdirManager,
# building twisted.runner.portmap not inplace
build_py = cmd.get_finalized_command('build_py')
- build_py.package_dir = {}
+ build_py.package_dir = None
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
path = cmd.get_ext_fullpath('twisted.runner.portmap')
wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
diff --git a/distutils2/tests/test_command_build_py.py b/distutils2/tests/test_command_build_py.py
index eefdc69..38ff7a6 100644
--- a/distutils2/tests/test_command_build_py.py
+++ b/distutils2/tests/test_command_build_py.py
@@ -17,12 +17,14 @@ class BuildPyTestCase(support.TempdirManager,
def test_package_data(self):
sources = self.mkdtemp()
- f = open(os.path.join(sources, "__init__.py"), "w")
+ pkg_dir = os.path.join(sources, 'pkg')
+ os.mkdir(pkg_dir)
+ f = open(os.path.join(pkg_dir, "__init__.py"), "w")
try:
f.write("# Pretend this is a package.")
finally:
f.close()
- f = open(os.path.join(sources, "README.txt"), "w")
+ f = open(os.path.join(pkg_dir, "README.txt"), "w")
try:
f.write("Info about this package")
finally:
@@ -31,8 +33,9 @@ class BuildPyTestCase(support.TempdirManager,
destination = self.mkdtemp()
dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": sources}})
+ "package_dir": sources})
# script_name need not exist, it just need to be initialized
+
dist.script_name = os.path.join(sources, "setup.py")
dist.command_obj["build"] = support.DummyCommand(
force=0,
@@ -42,7 +45,7 @@ class BuildPyTestCase(support.TempdirManager,
use_2to3=False)
dist.packages = ["pkg"]
dist.package_data = {"pkg": ["README.txt"]}
- dist.package_dir = {"pkg": sources}
+ dist.package_dir = sources
cmd = build_py(dist)
cmd.compile = 1
@@ -68,19 +71,20 @@ class BuildPyTestCase(support.TempdirManager,
# create the distribution files.
sources = self.mkdtemp()
- open(os.path.join(sources, "__init__.py"), "w").close()
-
- testdir = os.path.join(sources, "doc")
+ pkg = os.path.join(sources, 'pkg')
+ os.mkdir(pkg)
+ open(os.path.join(pkg, "__init__.py"), "w").close()
+ testdir = os.path.join(pkg, "doc")
os.mkdir(testdir)
open(os.path.join(testdir, "testfile"), "w").close()
os.chdir(sources)
old_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
+ #sys.stdout = StringIO.StringIO()
try:
dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": ""},
+ "package_dir": sources,
"package_data": {"pkg": ["doc/*"]}})
# script_name need not exist, it just need to be initialized
dist.script_name = os.path.join(sources, "setup.py")
@@ -89,7 +93,7 @@ class BuildPyTestCase(support.TempdirManager,
try:
dist.run_commands()
- except DistutilsFileError:
+ except DistutilsFileError, e:
self.fail("failed package_data test when package_dir is ''")
finally:
# Restore state.
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
index bdd4739..5fdb04c 100644
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -49,9 +49,11 @@ project_url =
Fork in progress, http://bitbucket.org/Merwok/sample-distutils2-project
[files]
+packages_root = src
+
packages = one
- src:two
- src2:three
+ two
+ three
modules = haven
@@ -140,6 +142,7 @@ class ConfigTestCase(support.TempdirManager,
opts.update(kwargs)
self.write_file('setup.cfg', SETUP_CFG % opts)
+
def run_setup(self, *args):
# run setup with args
sys.stdout = StringIO()
@@ -198,7 +201,6 @@ class ConfigTestCase(support.TempdirManager,
'http://bitbucket.org/Merwok/sample-distutils2-project')]
self.assertEqual(dist.metadata['Project-Url'], urls)
-
self.assertEqual(dist.packages, ['one', 'two', 'three'])
self.assertEqual(dist.py_modules, ['haven'])
self.assertEqual(dist.package_data, {'cheese': 'data/templates/*'})
@@ -206,7 +208,8 @@ class ConfigTestCase(support.TempdirManager,
[('bitmaps ', ['bm/b1.gif', 'bm/b2.gif']),
('config ', ['cfg/data.cfg']),
('/etc/init.d ', ['init-script'])])
- self.assertEqual(dist.package_dir['two'], 'src')
+
+ self.assertEqual(dist.package_dir, 'src')
# Make sure we get the foo command loaded. We use a string comparison
# instead of assertIsInstance because the class is not the same when
@@ -262,7 +265,9 @@ class ConfigTestCase(support.TempdirManager,
os.mkdir('bin')
self.write_file(os.path.join('bin', 'taunt'), '#')
- for pkg in ('one', 'src', 'src2'):
+ os.mkdir('src')
+ for pkg in ('one', 'two', 'three'):
+ pkg = os.path.join('src', pkg)
os.mkdir(pkg)
self.write_file(os.path.join(pkg, '__init__.py'), '#')
@@ -285,7 +290,9 @@ class ConfigTestCase(support.TempdirManager,
os.mkdir('bin')
self.write_file(os.path.join('bin', 'taunt'), '#')
- for pkg in ('one', 'src', 'src2'):
+ os.mkdir('src')
+ for pkg in ('one', 'two', 'three'):
+ pkg = os.path.join('src', pkg)
os.mkdir(pkg)
self.write_file(os.path.join(pkg, '__init__.py'), '#')
@@ -310,8 +317,10 @@ class ConfigTestCase(support.TempdirManager,
self.write_file(os.path.join('scripts', 'find-coconuts'), '#')
os.mkdir('bin')
self.write_file(os.path.join('bin', 'taunt'), '#')
+ os.mkdir('src')
- for pkg in ('one', 'src', 'src2'):
+ for pkg in ('one', 'two', 'three'):
+ pkg = os.path.join('src', pkg)
os.mkdir(pkg)
self.write_file(os.path.join(pkg, '__init__.py'), '#')