[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Refactor get_data_files() function in setup.py.



commit b851164254c4b086d90244f5dc263ffedd3c066e
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Tue Oct 15 04:16:42 2013 +0000

    Refactor get_data_files() function in setup.py.
    
    The ``get_data_files()`` function now takes a boolean ``filesonly`` parameter,
    if True, it returns a list suitable for the ``package_data`` parameter of
    ``setuptools.setup()``, otherwise it returns a list which is compatible with
    ``distutils.command.install_data.install_data.data_files``.
    
    We can now remove distutils entirely from setup.py, but I decided to make this
    function compatible with both distutils and setuptools because Python
    packaging has been in turmoil for a while now. (Hopefully, it's done, but I'm
    not holding my breath.)
    
     * FIXES a problem with some .mo files not getting installed (if they didn't
       already have a directory for their LOCALE in build/).
    
     * FIXES a bug where all .po files were being installed, even though they were
       added to the ``exclude_package_data`` parameter of ``setuptools.setup()``.
    
     * FIXES (along with commit ef784165002086cbc5b8131edcde815326a63009) a bug
       where the robots.txt file was not being packaged correctly.
---
 setup.py |   45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/setup.py b/setup.py
index 143db1d..b3cbb70 100644
--- a/setup.py
+++ b/setup.py
@@ -181,16 +181,43 @@ def get_template_files():
 
     return template_files
 
-def get_data_files():
-    """Returns our hard-coded data_files which should be distributed.
-
-    This is necessary for the :class:`installData` class to determine which
-    files we should include in the packaged distribution.
-
-    see http://docs.python.org/2/distutils/setupscript.html#installing-additional-files
+def get_data_files(filesonly=False):
+    """Return any hard-coded data_files which should be distributed.
+
+    This is necessary so that both the distutils-derived :class:`installData`
+    class and the setuptools ``data_files`` parameter include the same files.
+    Call this function with ``filesonly=True`` to get a list of files suitable
+    for giving to the ``package_data`` parameter in ``setuptools.setup()``.
+    Or, call it with ``filesonly=False`` (the default) to get a list which is
+    suitable for using as ``distutils.command.install_data.data_files``.
+
+    :param bool filesonly: If true, only return the locations of the files to
+        install, not the directories to install them into.
+    :rtype: list
+    :returns: If ``filesonly``, returns a list of file paths. Otherwise,
+        returns a list of 2-tuples containing: one, the directory to install
+        to, and two, the files to install to that directory.
     """
-    data_files=[(os.path.join('share', 'doc', 'bridgedb'),
-                 ['README', 'TODO', 'LICENSE', 'requirements.txt'])]
+    data_files = []
+    doc_files = ['README', 'TODO', 'LICENSE', 'requirements.txt']
+    lang_dirs, lang_files = get_supported_langs()
+    template_files = get_template_files()
+
+    if filesonly:
+        data_files.extend(doc_files)
+        for lst in lang_files, template_files:
+            for filename in lst:
+                if filename.startswith(pkgpath):
+                    # The +1 gets rid of the '/' at the beginning:
+                    filename = filename[len(pkgpath) + 1:]
+                    data_files.append(filename)
+    else:
+        data_files.append((install_docs, doc_files))
+        for ldir, lfile in zip(lang_dirs, lang_files):
+            data_files.append((ldir, [lfile,]))
+
+    [sys.stdout.write("Added data_file '%s'\n" % x) for x in data_files]
+
     return data_files
 
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits