[pkg] update setup
authorDavid Douard <david.douard@logilab.fr>
Wed, 13 May 2015 23:16:51 +0200
changeset 1827 604c6af48cd6
parent 1826 239805c9132d
child 1828 4dde56c26e53
[pkg] update setup
__pkginfo__.py
setup.py
--- a/__pkginfo__.py	Fri Jul 24 15:15:14 2015 +0200
+++ b/__pkginfo__.py	Wed May 13 23:16:51 2015 +0200
@@ -58,7 +58,7 @@
 # Note: here, you'll need to add subdirectories if you want
 # them to be included in the debian package
 
-NARVALDIR = join(dirname(__file__), '_narval')
+NARVALDIR = '_narval'
 if isdir(NARVALDIR): # test REQUIRED (to be importable from everywhere)
     data_files.append([join('share', 'narval', 'checkers'),
                        listdir(join(NARVALDIR, 'checkers'))])
--- a/setup.py	Fri Jul 24 15:15:14 2015 +0200
+++ b/setup.py	Wed May 13 23:16:51 2015 +0200
@@ -8,7 +8,7 @@
 import os
 import sys
 import shutil
-from os.path import isdir, exists, join, walk
+from os.path import isdir, exists, join, walk, dirname
 
 try:
     if os.environ.get('NO_SETUPTOOLS'):
@@ -20,38 +20,46 @@
     from distutils.core import setup
     from distutils.command import install_lib
     USE_SETUPTOOLS = 0
-from distutils.command import install_data
+
+# load metadata from the __pkginfo__.py file so there is no risk of conflict
+# see https://packaging.python.org/en/latest/single_source_version.html
+base_dir = dirname(__file__)
 
-sys.modules.pop('__pkginfo__', None)
-# import required features
-from __pkginfo__ import modname, version, license, description, \
-     web, author, author_email
-# import optional features
-import __pkginfo__
-distname = getattr(__pkginfo__, 'distname', modname)
-scripts = getattr(__pkginfo__, 'scripts', [])
-data_files = getattr(__pkginfo__, 'data_files', None)
-include_dirs = getattr(__pkginfo__, 'include_dirs', [])
-ext_modules = getattr(__pkginfo__, 'ext_modules', None)
-dependency_links = getattr(__pkginfo__, 'dependency_links', [])
+pkginfo = {}
+with open(join(base_dir, "__pkginfo__.py")) as f:
+    exec(f.read(), pkginfo)
+# get required metadatas
+modname = pkginfo['modname']
+version = pkginfo['version']
+license = pkginfo['license']
+description = pkginfo['description']
+web = pkginfo['web']
+author = pkginfo['author']
+author_email = pkginfo['author_email']
+classifiers = pkginfo['classifiers']
 
-STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
-
-IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
+with open(join(base_dir, 'README')) as f:
+    long_description = f.read()
 
-if exists('README'):
-    long_description = file('README').read()
-else:
-    long_description = ''
+# get optional metadatas
+distname = pkginfo.get('distname', modname)
+scripts = pkginfo.get('scripts', ())
+include_dirs = pkginfo.get('include_dirs', ())
+data_files = pkginfo.get('data_files', None)
+ext_modules = pkginfo.get('ext_modules', None)
+dependency_links = pkginfo.get('dependency_links', ())
+
 if USE_SETUPTOOLS:
-   requires = {}
-   for entry in ("__depends__", "__recommends__"):
-      requires.update(getattr(__pkginfo__, entry, {}))
-   install_requires = [("%s %s" % (d, v and v or "")).strip()
+    requires = {}
+    for entry in ("__depends__",): # "__recommends__"):
+        requires.update(pkginfo.get(entry, {}))
+    install_requires = [("%s %s" % (d, v and v or "")).strip()
                        for d, v in requires.iteritems()]
 else:
-   install_requires = []
+    install_requires = []
 
+BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build')
+IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
 
 def ensure_scripts(linux_scripts):
     """Creates the proper script names required for each platform
@@ -80,7 +88,7 @@
     return result
 
 def export(from_dir, to_dir,
-           blacklist=STD_BLACKLIST,
+           blacklist=BASE_BLACKLIST,
            ignore_ext=IGNORED_EXTENSIONS,
            verbose=True):
     """make a mirror of from_dir in to_dir, omitting directories and files