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 ++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 41 deletions(-) (limited to 'distutils2/command/install_data.py') 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 -- 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/install_data.py') 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/install_data.py') 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 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/install_data.py') 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/install_data.py') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'distutils2/command/install_data.py') 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 -- cgit v1.2.1 From e8e24f0af1df9fe9e9f32704756dabcc185754eb Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 13 Feb 2011 23:18:44 +0000 Subject: EnvironmentError does not always have a message attribute (python 2.4) --- distutils2/command/install_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'distutils2/command/install_data.py') diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 1440753..3179ebb 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -51,7 +51,7 @@ class install_data(Command): try: (out, _) = self.copy_file(file[0], dir_dest) except Error, e: - self.warn(e.message) + self.warn(e) out = destination self.outfiles.append(out) -- cgit v1.2.1