From 4ba3ca4e82fda0e9a7f6d6eb0e66849392d4bbb4 Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Fri, 28 Jan 2011 17:10:57 +0100 Subject: 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. --- distutils2/command/install_data.py | 69 ++++++++++++++-------------------- distutils2/command/install_dist.py | 4 ++ distutils2/command/install_distinfo.py | 21 ++++++++++- 3 files changed, 52 insertions(+), 42 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index e77b11c..6fe3805 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -9,6 +9,7 @@ platform-independent data files.""" 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 @@ class install_data(Command): 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 @@ class install_data(Command): 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) - - 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) + 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) + + 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 @@ class install_data(Command): 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 index 146c905..23f3c5f 100644 --- a/distutils2/command/install_dist.py +++ b/distutils2/command/install_dist.py @@ -87,6 +87,8 @@ class install_dist(Command): ('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 @@ class install_dist(Command): #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 index 6e76546..3df90cd 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -39,9 +39,11 @@ class install_distinfo(Command): "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 @@ class install_distinfo(Command): 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 @@ class install_distinfo(Command): 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 -- cgit v1.2.1 From de90c183d8269238e9d9b1dacc2feb435dceda7b Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sat, 29 Jan 2011 15:39:34 +0100 Subject: Use public method from sysconfig instead of private one to expand paths. Correct a type in config module. --- distutils2/command/install_data.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 6fe3805..59d020a 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -9,7 +9,7 @@ platform-independent data files.""" 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 +from distutils2._backport.sysconfig import get_paths class install_data(Command): @@ -55,8 +55,8 @@ class install_data(Command): 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) + expanded_path = get_paths(path_with_categories, local_vars) + expanded_path = get_paths(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) @@ -66,7 +66,7 @@ class install_data(Command): sources = [] for file in self.data_files: destination = convert_path(self.expand_categories(file[1])) - if os.path.file(destination): + if os.path.isfile(destination): sources.append(destination) return sources -- cgit v1.2.1 From c19d455ade483a0487ecf97264f078c0d147f95a Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sat, 29 Jan 2011 16:47:23 +0100 Subject: Correct typo error in RESOURCE paths mapping file in pkgutil. Add a format_value function in sysconfig. Correct bug in get_source_files in install_data. --- distutils2/command/install_data.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 59d020a..59cf90e 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -9,7 +9,7 @@ platform-independent data files.""" import os from distutils2.command.cmd import Command from distutils2.util import change_root, convert_path -from distutils2._backport.sysconfig import get_paths +from distutils2._backport.sysconfig import get_paths, format_value class install_data(Command): @@ -55,20 +55,15 @@ class install_data(Command): def expand_categories(self, path_with_categories): local_vars = get_paths() local_vars['distribution.name'] = self.distribution.metadata['Name'] - expanded_path = get_paths(path_with_categories, local_vars) - expanded_path = get_paths(expanded_path, local_vars) + expanded_path = format_value(path_with_categories, local_vars) + expanded_path = format_value(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 file in self.data_files: - destination = convert_path(self.expand_categories(file[1])) - if os.path.isfile(destination): - sources.append(destination) - return sources + return self.data_files.keys() def get_inputs(self): return self.data_files or [] -- cgit v1.2.1 From 35c4545ca4ca5b4d46d11cfe9968f1644148b308 Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sat, 29 Jan 2011 17:32:29 +0100 Subject: Correct bug : DATAFILES not added in RECORD file. --- distutils2/command/install_distinfo.py | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index 3df90cd..61c27ad 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -69,6 +69,9 @@ class install_distinfo(Command): self.requested = True if self.no_record is None: self.no_record = False + if self.no_datafiles is None: + self.no_datafiles = False + metadata = self.distribution.metadata @@ -116,6 +119,24 @@ class install_distinfo(Command): f.close() self.outputs.append(requested_path) + + 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) + + self.outputs.append(datafiles_path) + finally: + f.close() + if not self.no_record: record_path = os.path.join(self.distinfo_dir, 'RECORD') logger.info('creating %s', record_path) @@ -145,21 +166,6 @@ class install_distinfo(Command): 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 -- cgit v1.2.1 From 0ef975312695252417f90ad367614b2fdb8d1cd6 Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sat, 29 Jan 2011 17:42:22 +0100 Subject: Only create DATAFILES if distribution include data files. --- distutils2/command/install_distinfo.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index 61c27ad..4357dd9 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -121,21 +121,21 @@ class install_distinfo(Command): 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() != '': + install_data = self.get_finalized_command('install_data') + if install_data.get_datafiles_out() != []: + 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='"') for tuple in install_data.get_datafiles_out(): writer.writerow(tuple) - self.outputs.append(datafiles_path) - finally: - f.close() + self.outputs.append(datafiles_path) + finally: + f.close() if not self.no_record: record_path = os.path.join(self.distinfo_dir, 'RECORD') -- cgit v1.2.1 From 0cbe175fc060a25898bab4c7d54264f245f0db0d Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sun, 30 Jan 2011 11:56:46 +0100 Subject: No file that does not exists can be present in distribution.data_files. Correct bugs in get_inputs in install_data. --- distutils2/command/install_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 59cf90e..8ef089d 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -66,7 +66,7 @@ class install_data(Command): return self.data_files.keys() def get_inputs(self): - return self.data_files or [] + return self.data_files.keys() def get_outputs(self): return self.outfiles -- cgit v1.2.1 From 57b7580dada83b93bcea4f77b3c50069399fc488 Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Sun, 30 Jan 2011 14:42:59 +0100 Subject: Fix last bug, check that data file not exists at the same path and has the same content. --- distutils2/command/install_data.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 8ef089d..b7a9498 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -10,6 +10,7 @@ import os from distutils2.command.cmd import Command from distutils2.util import change_root, convert_path from distutils2._backport.sysconfig import get_paths, format_value +from distutils2._backport.shutil import Error class install_data(Command): @@ -47,7 +48,11 @@ class install_data(Command): dir_dest = os.path.abspath(os.path.dirname(destination)) self.mkpath(dir_dest) - (out, _) = self.copy_file(file[0], dir_dest) + try: + (out, _) = self.copy_file(file[0], dir_dest) + except Error, e: + self.warn(e.message) + out = destination self.outfiles.append(out) self.data_files_out.append((file[0], destination)) -- cgit v1.2.1 From 6e1e6463fa755554444f76ce1c447172622f0392 Mon Sep 17 00:00:00 2001 From: Pierre-Yves David Date: Wed, 2 Feb 2011 11:38:07 +0100 Subject: renames datafiles in ressources for consistency with setup.cfg section --- distutils2/command/install_data.py | 2 +- distutils2/command/install_dist.py | 6 +++--- distutils2/command/install_distinfo.py | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index b7a9498..d4f8143 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -76,5 +76,5 @@ class install_data(Command): def get_outputs(self): return self.outfiles - def get_datafiles_out(self): + def get_resources_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 index 23f3c5f..fb3fd2a 100644 --- a/distutils2/command/install_dist.py +++ b/distutils2/command/install_dist.py @@ -87,7 +87,7 @@ class install_dist(Command): ('record=', None, "filename in which to record a list of installed files " "(not PEP 376-compliant)"), - ('datafiles=', None, + ('resources=', None, "data files mapping"), # .dist-info related arguments, read by install_dist_info @@ -186,14 +186,14 @@ class install_dist(Command): #self.install_info = None self.record = None - self.datafiles = None + self.resources = None # .dist-info related options self.no_distinfo = None self.installer = None self.requested = None self.no_record = None - self.no_datafiles = None + self.no_resources = 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 index 4357dd9..9478d56 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -39,11 +39,11 @@ class install_distinfo(Command): "do not generate a REQUESTED file"), ('no-record', None, "do not generate a RECORD file"), - ('no-datafiles', None, + ('no-resources', None, "do not generate a DATAFILES list installed file") ] - boolean_options = ['requested', 'no-record', 'no-datafiles'] + boolean_options = ['requested', 'no-record', 'no-resources'] negative_opt = {'no-requested': 'requested'} @@ -52,7 +52,7 @@ class install_distinfo(Command): self.installer = None self.requested = None self.no_record = None - self.no_datafiles = None + self.no_resources = None def finalize_options(self): self.set_undefined_options('install_dist', @@ -69,8 +69,8 @@ class install_distinfo(Command): self.requested = True if self.no_record is None: self.no_record = False - if self.no_datafiles is None: - self.no_datafiles = False + if self.no_resources is None: + self.no_resources = False metadata = self.distribution.metadata @@ -120,20 +120,20 @@ class install_distinfo(Command): self.outputs.append(requested_path) - if not self.no_datafiles: + if not self.no_resources: install_data = self.get_finalized_command('install_data') - if install_data.get_datafiles_out() != []: - datafiles_path = os.path.join(self.distinfo_dir, 'DATAFILES') - logger.info('creating %s', datafiles_path) - f = open(datafiles_path, 'wb') + if install_data.get_resources_out() != []: + resources_path = os.path.join(self.distinfo_dir, 'DATAFILES') + logger.info('creating %s', resources_path) + f = open(resources_path, 'wb') try: writer = csv.writer(f, delimiter=',', lineterminator=os.linesep, quotechar='"') - for tuple in install_data.get_datafiles_out(): + for tuple in install_data.get_resources_out(): writer.writerow(tuple) - self.outputs.append(datafiles_path) + self.outputs.append(resources_path) finally: f.close() -- cgit v1.2.1 From d8b072dd0e7a4de3db062515f08d7c171092976b Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Fri, 4 Feb 2011 18:47:37 +0100 Subject: Finish the renaming of datafiles to resources. Change test_ressources.test_resources_open to avoid to install a complete distribution, create a fake one manually. --- distutils2/command/install_distinfo.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'distutils2/command') diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index 9478d56..b8cfcc0 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -12,12 +12,12 @@ automatically by the ``install_dist`` command. # This file was created from the code for the former command install_egg_info -import os import csv -import re -from distutils2.command.cmd import Command from distutils2 import logger from distutils2._backport.shutil import rmtree +from distutils2.command.cmd import Command +import os +import re try: import hashlib except ImportError: @@ -40,7 +40,7 @@ class install_distinfo(Command): ('no-record', None, "do not generate a RECORD file"), ('no-resources', None, - "do not generate a DATAFILES list installed file") + "do not generate a RESSOURCES list installed file") ] boolean_options = ['requested', 'no-record', 'no-resources'] @@ -76,9 +76,9 @@ class install_distinfo(Command): metadata = self.distribution.metadata basename = "%s-%s.dist-info" % ( - to_filename(safe_name(metadata['Name'])), - to_filename(safe_version(metadata['Version'])), - ) + to_filename(safe_name(metadata['Name'])), + to_filename(safe_version(metadata['Version'])), + ) self.distinfo_dir = os.path.join(self.distinfo_dir, basename) self.outputs = [] @@ -123,7 +123,8 @@ class install_distinfo(Command): if not self.no_resources: install_data = self.get_finalized_command('install_data') if install_data.get_resources_out() != []: - resources_path = os.path.join(self.distinfo_dir, 'DATAFILES') + resources_path = os.path.join(self.distinfo_dir, + 'RESOURCES') logger.info('creating %s', resources_path) f = open(resources_path, 'wb') try: -- cgit v1.2.1