[Python-checkins] distutils2: Distutils 2 now install datafiles in the right place (indicated by sysconfig).
tarek.ziade
python-checkins at python.org
Wed Feb 16 22:23:57 CET 2011
tarek.ziade pushed 1bb3a0e4029d to distutils2:
http://hg.python.org/distutils2/rev/1bb3a0e4029d
changeset: 1033:1bb3a0e4029d
user: FELD Boris <lothiraldan at gmail.com>
date: Fri Jan 28 17:10:57 2011 +0100
summary:
Distutils 2 now install datafiles in the right place (indicated by sysconfig).
Data files are read from config file.
Data files are installed to the expanded category file.
Data files list is written in DATAFILES file in .dist-info dir.
files:
distutils2/command/install_data.py
distutils2/command/install_dist.py
distutils2/command/install_distinfo.py
distutils2/config.py
diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py
--- a/distutils2/command/install_data.py
+++ b/distutils2/command/install_data.py
@@ -9,6 +9,7 @@
import os
from distutils2.command.cmd import Command
from distutils2.util import change_root, convert_path
+from distutils2._backport.sysconfig import _expand_vars, _subst_vars, get_paths
class install_data(Command):
@@ -28,6 +29,7 @@
def initialize_options(self):
self.install_dir = None
self.outfiles = []
+ self.data_files_out = []
self.root = None
self.force = 0
self.data_files = self.distribution.data_files
@@ -40,50 +42,32 @@
def run(self):
self.mkpath(self.install_dir)
- for f in self.data_files:
- if isinstance(f, str):
- # it's a simple file, so copy it
- f = convert_path(f)
- if self.warn_dir:
- self.warn("setup script did not provide a directory for "
- "'%s' -- installing right in '%s'" %
- (f, self.install_dir))
- (out, _) = self.copy_file(f, self.install_dir)
- self.outfiles.append(out)
- else:
- # it's a tuple with path to install to and a list of files
- dir = convert_path(f[0])
- if not os.path.isabs(dir):
- dir = os.path.join(self.install_dir, dir)
- elif self.root:
- dir = change_root(self.root, dir)
- self.mkpath(dir)
+ for file in self.data_files.items():
+ destination = convert_path(self.expand_categories(file[1]))
+ dir_dest = os.path.abspath(os.path.dirname(destination))
+
+ self.mkpath(dir_dest)
+ (out, _) = self.copy_file(file[0], dir_dest)
- if f[1] == []:
- # If there are no files listed, the user must be
- # trying to create an empty directory, so add the
- # directory to the list of output files.
- self.outfiles.append(dir)
- else:
- # Copy files, adding them to the list of output files.
- for data in f[1]:
- data = convert_path(data)
- (out, _) = self.copy_file(data, dir)
- self.outfiles.append(out)
+ self.outfiles.append(out)
+ self.data_files_out.append((file[0], destination))
+
+ def expand_categories(self, path_with_categories):
+ local_vars = get_paths()
+ local_vars['distribution.name'] = self.distribution.metadata['Name']
+ expanded_path = _subst_vars(path_with_categories, local_vars)
+ expanded_path = _subst_vars(expanded_path, local_vars)
+ if '{' in expanded_path and '}' in expanded_path:
+ self.warn("Unable to expand %s, some categories may missing." %
+ path_with_categories)
+ return expanded_path
def get_source_files(self):
sources = []
- for item in self.data_files:
- if isinstance(item, str): # plain file
- item = convert_path(item)
- if os.path.isfile(item):
- sources.append(item)
- else: # a (dirname, filenames) tuple
- dirname, filenames = item
- for f in filenames:
- f = convert_path(f)
- if os.path.isfile(f):
- sources.append(f)
+ for file in self.data_files:
+ destination = convert_path(self.expand_categories(file[1]))
+ if os.path.file(destination):
+ sources.append(destination)
return sources
def get_inputs(self):
@@ -91,3 +75,6 @@
def get_outputs(self):
return self.outfiles
+
+ def get_datafiles_out(self):
+ return self.data_files_out
\ No newline at end of file
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -87,6 +87,8 @@
('record=', None,
"filename in which to record a list of installed files "
"(not PEP 376-compliant)"),
+ ('datafiles=', None,
+ "data files mapping"),
# .dist-info related arguments, read by install_dist_info
('no-distinfo', None,
@@ -184,12 +186,14 @@
#self.install_info = None
self.record = None
+ self.datafiles = None
# .dist-info related options
self.no_distinfo = None
self.installer = None
self.requested = None
self.no_record = None
+ self.no_datafiles = None
# -- Option finalizing methods -------------------------------------
# (This is rather more involved than for most commands,
diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py
--- a/distutils2/command/install_distinfo.py
+++ b/distutils2/command/install_distinfo.py
@@ -39,9 +39,11 @@
"do not generate a REQUESTED file"),
('no-record', None,
"do not generate a RECORD file"),
+ ('no-datafiles', None,
+ "do not generate a DATAFILES list installed file")
]
- boolean_options = ['requested', 'no-record']
+ boolean_options = ['requested', 'no-record', 'no-datafiles']
negative_opt = {'no-requested': 'requested'}
@@ -50,6 +52,7 @@
self.installer = None
self.requested = None
self.no_record = None
+ self.no_datafiles = None
def finalize_options(self):
self.set_undefined_options('install_dist',
@@ -142,6 +145,22 @@
finally:
f.close()
+ if not self.no_datafiles:
+ datafiles_path = os.path.join(self.distinfo_dir, 'DATAFILES')
+ logger.info('creating %s', datafiles_path)
+ f = open(datafiles_path, 'wb')
+ try:
+ writer = csv.writer(f, delimiter=',',
+ lineterminator=os.linesep,
+ quotechar='"')
+ install_data = self.get_finalized_command('install_data')
+ if install_data.get_datafiles_out() != '':
+ for tuple in install_data.get_datafiles_out():
+ writer.writerow(tuple)
+ finally:
+ f.close()
+
+
def get_outputs(self):
return self.outputs
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -2,14 +2,17 @@
Know how to read all config files Distutils2 uses.
"""
+import os.path
import os
import sys
+import re
from ConfigParser import RawConfigParser
from distutils2 import logger
from distutils2.util import check_environ, resolve_name
from distutils2.compiler import set_compiler
from distutils2.command import set_command
+from distutils2.datafiles import resources_dests
class Config(object):
"""Reads configuration files and work with the Distribution instance
@@ -82,7 +85,7 @@
if v != '']
return value
- def _read_setup_cfg(self, parser):
+ def _read_setup_cfg(self, parser, filename):
content = {}
for section in parser.sections():
content[section] = dict(parser.items(section))
@@ -164,6 +167,25 @@
# manifest template
self.dist.extra_files = files.get('extra_files', [])
+
+ if 'resources' in content:
+ resources = []
+ regex = re.compile(r'[^\\](?:\\{2})* ')
+ for glob, destination in content['resources'].iteritems():
+ splitted_glob = regex.split(glob, 1)
+ if len(splitted_glob) == 1:
+ prefix = ''
+ suffix = splitted_glob[0]
+ else:
+ prefix = splitted_glob[0]
+ suffix = splitted_glob[1]
+
+ resources.append((prefix, suffix, destination))
+
+ dir = os.path.dirname(os.path.join(os.getcwd(), filename))
+ data_files = resources_dests(dir, resources)
+ self.dist.data_files = data_files
+
def parse_config_files(self, filenames=None):
if filenames is None:
@@ -178,7 +200,7 @@
parser.read(filename)
if os.path.split(filename)[-1] == 'setup.cfg':
- self._read_setup_cfg(parser)
+ self._read_setup_cfg(parser, filename)
for section in parser.sections():
if section == 'global':
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list