libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] branch trunk updated: Update setup.py so it doesn't rely on any functions from libcloud packages.
Date Fri, 29 Nov 2019 22:15:17 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 21a78a1  Update setup.py so it doesn't rely on any functions from libcloud packages.
21a78a1 is described below

commit 21a78a17929f0633817c337208ab2a21dc0639f9
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Fri Nov 29 23:13:26 2019 +0100

    Update setup.py so it doesn't rely on any functions from libcloud
    packages.
    
    This way we avoid having setup.py depend on typing, requests and other
    modules libcloud depends on.
---
 setup.py | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 tox.ini  |  10 ++++-
 2 files changed, 144 insertions(+), 11 deletions(-)

diff --git a/setup.py b/setup.py
index 0d796e5..7eec1f1 100644
--- a/setup.py
+++ b/setup.py
@@ -12,12 +12,14 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 import os
 import sys
+import re
+import fnmatch
 
 from setuptools import setup
 from distutils.core import Command
-from os.path import join as pjoin
 
 try:
     import epydoc  # NOQA
@@ -25,11 +27,127 @@ try:
 except ImportError:
     has_epydoc = False
 
+# NOTE: Those functions are intentionally moved in-line to prevent setup.py dependening on
any
+# Libcloud code which depends on libraries such as typing, enum, requests, etc.
+# START: Taken From Twisted Python which licensed under MIT license
+# https://github.com/powdahound/twisted/blob/master/twisted/python/dist.py
+# https://github.com/powdahound/twisted/blob/master/LICENSE
+
+# Names that are excluded from globbing results:
+EXCLUDE_NAMES = ['{arch}', 'CVS', '.cvsignore', '_darcs',
+                 'RCS', 'SCCS', '.svn']
+EXCLUDE_PATTERNS = ['*.py[cdo]', '*.s[ol]', '.#*', '*~', '*.py']
+
+
+def _filter_names(names):
+    """
+    Given a list of file names, return those names that should be copied.
+    """
+    names = [n for n in names
+             if n not in EXCLUDE_NAMES]
+    # This is needed when building a distro from a working
+    # copy (likely a checkout) rather than a pristine export:
+    for pattern in EXCLUDE_PATTERNS:
+        names = [n for n in names
+                 if not fnmatch.fnmatch(n, pattern) and not n.endswith('.py')]
+    return names
+
+
+def relative_to(base, relativee):
+    """
+    Gets 'relativee' relative to 'basepath'.
+
+    i.e.,
+
+    >>> relative_to('/home/', '/home/radix/')
+    'radix'
+    >>> relative_to('.', '/home/radix/Projects/Twisted')
+    'Projects/Twisted'
+
+    The 'relativee' must be a child of 'basepath'.
+    """
+    basepath = os.path.abspath(base)
+    relativee = os.path.abspath(relativee)
+    if relativee.startswith(basepath):
+        relative = relativee[len(basepath):]
+        if relative.startswith(os.sep):
+            relative = relative[1:]
+        return os.path.join(base, relative)
+    raise ValueError("%s is not a subpath of %s" % (relativee, basepath))
+
+
+def get_packages(dname, pkgname=None, results=None, ignore=None, parent=None):
+    """
+    Get all packages which are under dname. This is necessary for
+    Python 2.2's distutils. Pretty similar arguments to getDataFiles,
+    including 'parent'.
+    """
+    parent = parent or ""
+    prefix = []
+    if parent:
+        prefix = [parent]
+    bname = os.path.basename(dname)
+    ignore = ignore or []
+    if bname in ignore:
+        return []
+    if results is None:
+        results = []
+    if pkgname is None:
+        pkgname = []
+    subfiles = os.listdir(dname)
+    abssubfiles = [os.path.join(dname, x) for x in subfiles]
 
-import libcloud.utils  # NOQA
-from libcloud.utils.dist import get_packages, get_data_files  # NOQA
+    if '__init__.py' in subfiles:
+        results.append(prefix + pkgname + [bname])
+        for subdir in filter(os.path.isdir, abssubfiles):
+            get_packages(subdir, pkgname=pkgname + [bname],
+                         results=results, ignore=ignore,
+                         parent=parent)
+    res = ['.'.join(result) for result in results]
+    return res
+
+
+def get_data_files(dname, ignore=None, parent=None):
+    """
+    Get all the data files that should be included in this distutils Project.
+
+    'dname' should be the path to the package that you're distributing.
+
+    'ignore' is a list of sub-packages to ignore.  This facilitates
+    disparate package hierarchies.  That's a fancy way of saying that
+    the 'twisted' package doesn't want to include the 'twisted.conch'
+    package, so it will pass ['conch'] as the value.
+
+    'parent' is necessary if you're distributing a subpackage like
+    twisted.conch.  'dname' should point to 'twisted/conch' and 'parent'
+    should point to 'twisted'.  This ensures that your data_files are
+    generated correctly, only using relative paths for the first element
+    of the tuple ('twisted/conch/*').
+    The default 'parent' is the current working directory.
+    """
+    parent = parent or "."
+    ignore = ignore or []
+    result = []
+    for directory, subdirectories, filenames in os.walk(dname):
+        resultfiles = []
+        for exname in EXCLUDE_NAMES:
+            if exname in subdirectories:
+                subdirectories.remove(exname)
+        for ig in ignore:
+            if ig in subdirectories:
+                subdirectories.remove(ig)
+        for filename in _filter_names(filenames):
+            resultfiles.append(filename)
+        if resultfiles:
+            for filename in resultfiles:
+                file_path = os.path.join(directory, filename)
+                if parent:
+                    file_path = file_path.replace(parent + os.sep, '')
+                result.append(file_path)
+
+    return result
+# END: Taken from Twisted
 
-libcloud.utils.SHOW_DEPRECATION_WARNING = False
 
 # Different versions of python have different requirements.  We can't use
 # libcloud.utils.py3 here because it relies on backports dependency being
@@ -76,11 +194,20 @@ if PY2_pre_27 or PY3_pre_34:
 
 def read_version_string():
     version = None
-    sys.path.insert(0, pjoin(os.getcwd()))
-    from libcloud import __version__
-    version = __version__
-    sys.path.pop(0)
-    return version
+    cwd = os.path.dirname(os.path.abspath(__file__))
+    version_file = os.path.join(cwd, 'libcloud/__init__.py')
+
+    with open(version_file) as fp:
+        content = fp.read()
+
+    match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
+                      content, re.M)
+
+    if match:
+        version = match.group(1)
+        return version
+
+    raise Exception('Cannot find version in libcloud/__init__.py')
 
 
 def forbid_publish():
diff --git a/tox.ini b/tox.ini
index ced788b..b5db500 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,12 +30,18 @@ whitelist_externals = cp
                       scripts/*.sh
 [testenv:py2.7-dist]
 # Verify library installs without any dependencies
-skipdist=False
+skipdist = True
+# NOTE: We intentionally set empty deps to ensure it works on a clean
+# environment without any dependencies
+deps =
 commands = python setup.py install
 
 [testenv:py3.7-dist]
 # Verify library installs without any dependencies
-skipdist=False
+skipdist = True
+# NOTE: We intentionally set empty deps to ensure it works on a clean
+# environment without any dependencies
+deps =
 commands = python setup.py install
 
 [testenv:docs]


Mime
View raw message