new style: update setup.py and __pkginfo__ stable
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Fri, 01 Sep 2017 15:44:24 +0200
branchstable
changeset 179 6eced128fb82
parent 178 336aa0819b5c
child 180 bc2580032bc3
new style: update setup.py and __pkginfo__
README
cubicweb_keyword/__pkginfo__.py
setup.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Fri Sep 01 15:44:24 2017 +0200
@@ -0,0 +1,27 @@
+Summary
+-------
+The `keyword` cube provides classification by using hierarchies of keywords to
+classify content.
+
+Each classification is represented using a `Classification` entity, which will
+hold a keywords tree.
+
+There is two types of keywords:
+
+- `Keyword` which contains a description,
+
+- `CodeKeyword` which contains the keyword description and the associated code.
+
+In order to link an entity to a keyword, you have to add a relation
+ `applied_to` in the schema.
+
+Each keyword has the `subkeyword_of` relation definition. This allows to
+navigate in the classification without a Modified Preorder Tree Traversal
+representation of the data.
+
+Some methods are defined in order to get parents and children or get the status
+of a keyword (leaf or root).
+
+See also `cubicweb-tag`_ as another (simpler) way to classify content.
+
+.. _`cubicweb-tag`: http://www.cubicweb.org/project/cubicweb-tag
\ No newline at end of file
--- a/cubicweb_keyword/__pkginfo__.py	Fri Sep 01 15:43:21 2017 +0200
+++ b/cubicweb_keyword/__pkginfo__.py	Fri Sep 01 15:44:24 2017 +0200
@@ -15,35 +15,7 @@
 author_email = "contact@logilab.fr"
 web = 'http://www.cubicweb.org/project/%s' % distname
 
-short_desc = "classification schemes system for the Cubicweb framework"
-long_desc = """Summary
--------
-The `keyword` cube provides classification by using hierarchies of keywords to
-classify content.
-
-Each classification is represented using a `Classification` entity, which will
-hold a keywords tree.
-
-There is two types of keywords:
-
-- `Keyword` which contains a description,
-
-- `CodeKeyword` which contains the keyword description and the associated code.
-
-In order to link an entity to a keyword, you have to add a relation `applied_to`
-in the schema.
-
-Each keyword has the `subkeyword_of` relation definition. This allows to
-navigate in the classification without a Modified Preorder Tree Traversal
-representation of the data.
-
-Some methods are defined in order to get parents and children or get the status
-of a keyword (leaf or root).
-
-See also `cubicweb-tag`_ as another (simpler) way to classify content.
-
-.. _`cubicweb-tag`: http://www.cubicweb.org/project/cubicweb-tag
-"""
+description = "classification schemes system for the Cubicweb framework"
 
 classifiers = [
     'Environment :: Web Environment',
@@ -53,36 +25,4 @@
     ]
 
 __depends_cubes__ = {}
-__depends__ = {'cubicweb': '>= 3.16.0'}
-__use__ = tuple(__depends_cubes__)
-
-from os import listdir as _listdir
-from os.path import join, isdir
-from glob import glob
-
-THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
-
-def listdir(dirpath):
-    return [join(dirpath, fname) for fname in _listdir(dirpath)
-            if fname[0] != '.' and not fname.endswith('.pyc')
-            and not fname.endswith('~')
-            and not isdir(join(dirpath, fname))]
-try:
-    data_files = [
-        # common files
-        [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
-        [join(THIS_CUBE_DIR, 'test'), [fname for fname in glob('test/*.py')]],
-
-    ]
-    for dname in ('data', 'i18n', 'migration', ):
-        if isdir(dname):
-            data_files.append([join(THIS_CUBE_DIR, dname), listdir(dname)])
-
-    # Note: here, you'll need to add subdirectories if you want
-    # them to be included in the debian package
-    for dname in ('data', ):
-        data_files.append([join(THIS_CUBE_DIR, 'test', dname), listdir(join('test', dname))])
-
-except OSError:
-    # we are in an installed directory
-    pass
+__depends__ = {'cubicweb': '>= 3.24.0'}
--- a/setup.py	Fri Sep 01 15:43:21 2017 +0200
+++ b/setup.py	Fri Sep 01 15:44:24 2017 +0200
@@ -1,82 +1,82 @@
 #!/usr/bin/env python
-# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152
-# Copyright (c) 2003-2009 LOGILAB S.A. (Paris, FRANCE).
-# http://www.logilab.fr/ -- mailto:contact@logilab.fr
+# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
+#
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of a cubicweb-keyword.
 #
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
 #
-# This program is distributed in the hope that it will be useful, but WITHOUT
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-""" Generic Setup script, takes package info from __pkginfo__.py file """
+# You should have received a copy of the GNU Lesser General Public License
+# along with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb_keyword setup module using data from
+cubicweb_keyword/__pkginfo__.py file
+"""
 
-import os
-import sys
-import shutil
-from distutils.core import setup
-from distutils import command
-from distutils.command import install_lib
-from os.path import isdir, exists, join, walk
+from os.path import join, dirname
 
-# import required features
-from __pkginfo__ import distname, version, license, short_desc, long_desc, \
-     web, author, author_email
-# import optional features
-try:
-    from __pkginfo__ import distname
-except ImportError:
-    distname = distname
-try:
-    from __pkginfo__ import scripts
-except ImportError:
-    scripts = []
-try:
-    from __pkginfo__ import data_files
-except ImportError:
-    data_files = None
-try:
-    from __pkginfo__ import include_dirs
-except ImportError:
-    include_dirs = []
-
-BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
-IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
+from setuptools import find_packages, setup
 
 
-def ensure_scripts(linux_scripts):
-    """creates the proper script names required for each platform
-    (taken from 4Suite)
-    """
-    from distutils import util
-    if util.get_platform()[:3] == 'win':
-        scripts_ = [script + '.bat' for script in linux_scripts]
-    else:
-        scripts_ = linux_scripts
-    return scripts_
+here = 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 = join(here, 'cubicweb_keyword', '__pkginfo__.py')
+__pkginfo__ = {}
+with open(pkginfo) as f:
+    exec(f.read(), __pkginfo__)
 
+# get required metadatas
+distname = __pkginfo__['distname']
+version = __pkginfo__['version']
+license = __pkginfo__['license']
+description = __pkginfo__['description']
+web = __pkginfo__['web']
+author = __pkginfo__['author']
+author_email = __pkginfo__['author_email']
+classifiers = __pkginfo__['classifiers']
+
+with open(join(here, 'README')) as f:
+    long_description = f.read()
+
+# get optional metadatas
+data_files = __pkginfo__.get('data_files', None)
+dependency_links = __pkginfo__.get('dependency_links', ())
+
+requires = {}
+for entry in ("__depends__",):  # "__recommends__"):
+    requires.update(__pkginfo__.get(entry, {}))
+install_requires = ["{0} {1}".format(d, v and v or "").strip()
+                    for d, v in requires.items()]
 
 
-def install(**kwargs):
-    """setup entry point"""
-    #kwargs['distname'] = modname
-    return setup(name=distname,
-                 version=version,
-                 license =license,
-                 description=short_desc,
-                 long_description=long_desc,
-                 author=author,
-                 author_email=author_email,
-                 url=web,
-                 scripts=ensure_scripts(scripts),
-                 data_files=data_files,
-                 **kwargs)
-
-if __name__ == '__main__' :
-    install()
+setup(
+    name=distname,
+    version=version,
+    license=license,
+    description=description,
+    long_description=long_description,
+    author=author,
+    author_email=author_email,
+    url=web,
+    classifiers=classifiers,
+    packages=find_packages(exclude=['test']),
+    install_requires=install_requires,
+    include_package_data=True,
+    entry_points={
+        'cubicweb.cubes': [
+            'keyword=cubicweb_keyword',
+        ],
+    },
+    zip_safe=False,
+)