[PATCH 4 of 6 cw-celerytask-helpers] [pkg] read __pkginfo__ without importing cw_celerytask_helpers

Philippe Pepiot philippe.pepiot at logilab.fr
Wed Jun 20 17:59:53 CEST 2018


# HG changeset patch
# User Philippe Pepiot <philippe.pepiot at logilab.fr>
# Date 1529502334 -7200
#      Wed Jun 20 15:45:34 2018 +0200
# Node ID 9f5a9b939be34088169f808fb1459ac3161df9d8
# Parent  5a98c73f1b21aad3e54e78a54d183daec231cce6
# Available At https://hg.logilab.org/review/cw-celerytask-helpers
#              hg pull https://hg.logilab.org/review/cw-celerytask-helpers -r 9f5a9b939be3
[pkg] read __pkginfo__ without importing cw_celerytask_helpers

Otherwise setup.py may fail if we import a third party dependency in
__init__.py (we will do it in next changeset).

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,16 +1,23 @@
+import os.path
 from setuptools import setup, find_packages
 
-from cw_celerytask_helpers import __pkginfo__ as pkginfo
+here = os.path.dirname(__file__)
+# 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
+pkginfo = os.path.join(here, 'cw_celerytask_helpers', '__pkginfo__.py')
+__pkginfo__ = {'__file__': pkginfo}
+with open(pkginfo) as f:
+    exec(f.read(), __pkginfo__)
 
 setup(
-    name=pkginfo.distname,
-    version=pkginfo.version,
-    description=pkginfo.description,
-    author=pkginfo.author,
-    author_email=pkginfo.author_email,
-    license=pkginfo.license,
-    classifiers=pkginfo.classifiers,
+    name=__pkginfo__['distname'],
+    version=__pkginfo__['version'],
+    description=__pkginfo__['description'],
+    author=__pkginfo__['author'],
+    author_email=__pkginfo__['author_email'],
+    license=__pkginfo__['license'],
+    classifiers=__pkginfo__['classifiers'],
     packages=find_packages('.'),
     install_requires=["{0} {1}".format(d, v and v or "").strip()
-                      for d, v in pkginfo.__depends__.items()],
+                      for d, v in __pkginfo__['__depends__'].items()],
 )


More information about the cubicweb-devel mailing list