You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/12/08 13:00:58 UTC

[libcloud] 02/06: Reformat Python files in the repo root with black.

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

commit 97573abf0667e0e1eeed099396f3c163310e8e64
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:52:09 2021 +0100

    Reformat Python files in the repo root with black.
---
 example_compute.py      |   8 +-
 example_container.py    |   4 +-
 example_dns.py          |   2 +-
 example_loadbalancer.py |  24 +++---
 example_storage.py      |   2 +-
 setup.py                | 199 ++++++++++++++++++++++++++----------------------
 6 files changed, 131 insertions(+), 108 deletions(-)

diff --git a/example_compute.py b/example_compute.py
index f93c26a..4a0d067 100644
--- a/example_compute.py
+++ b/example_compute.py
@@ -24,8 +24,10 @@ from typing import Type, cast
 EC2 = get_driver(Provider.EC2)
 Rackspace = get_driver(Provider.RACKSPACE)
 
-drivers = [EC2('access key id', 'secret key', region='us-east-1'),
-           Rackspace('username', 'api key', region='iad')]
+drivers = [
+    EC2("access key id", "secret key", region="us-east-1"),
+    Rackspace("username", "api key", region="iad"),
+]
 
 nodes = []
 for driver in drivers:
@@ -36,7 +38,7 @@ print(nodes)
 # <Node: provider=Rackspace, status=REBOOT, name=korine, ip=6.7.8.9.10>, ... ]
 
 # grab the node named "test"
-node = [n for n in nodes if n.name == 'test'][0]
+node = [n for n in nodes if n.name == "test"][0]
 
 # reboot "test"
 node.reboot()
diff --git a/example_container.py b/example_container.py
index da1cfde..6b1476a 100644
--- a/example_container.py
+++ b/example_container.py
@@ -19,9 +19,7 @@ from libcloud.container.providers import get_driver
 cls = get_driver(Provider.KUBERNETES)
 
 # You can retrieve cluster ip by running "minikube ip" command
-conn = cls(key='my_token',
-           host='126.32.21.4',
-           ex_token_bearer_auth=True)
+conn = cls(key="my_token", host="126.32.21.4", ex_token_bearer_auth=True)
 
 for cluster in conn.list_clusters():
     print(cluster.name)
diff --git a/example_dns.py b/example_dns.py
index b99756b..918b14d 100644
--- a/example_dns.py
+++ b/example_dns.py
@@ -20,7 +20,7 @@ from libcloud.dns.providers import get_driver
 
 Zerigo = get_driver(Provider.ZERIGO)
 
-driver = Zerigo('email', 'key')
+driver = Zerigo("email", "key")
 
 zones = driver.list_zones()
 pprint(zones)
diff --git a/example_loadbalancer.py b/example_loadbalancer.py
index d47a0fe..4ceff41 100644
--- a/example_loadbalancer.py
+++ b/example_loadbalancer.py
@@ -25,7 +25,7 @@ from libcloud.loadbalancer.providers import get_driver
 
 def main():
     cls = get_driver(Provider.RACKSPACE)
-    driver = cls('username', 'api key', region='ord')
+    driver = cls("username", "api key", region="ord")
 
     balancers = driver.list_balancers()
 
@@ -34,14 +34,15 @@ def main():
     # creating a balancer which balances traffic across two
     # nodes: 192.168.86.1:80 and 192.168.86.2:8080. Balancer
     # itself listens on port 80/tcp
-    new_balancer_name = 'testlb' + os.urandom(4).encode('hex')
-    members = (Member(None, '192.168.86.1', 80),
-               Member(None, '192.168.86.2', 8080))
-    new_balancer = driver.create_balancer(name=new_balancer_name,
-                                          algorithm=Algorithm.ROUND_ROBIN,
-                                          port=80,
-                                          protocol='http',
-                                          members=members)
+    new_balancer_name = "testlb" + os.urandom(4).encode("hex")
+    members = (Member(None, "192.168.86.1", 80), Member(None, "192.168.86.2", 8080))
+    new_balancer = driver.create_balancer(
+        name=new_balancer_name,
+        algorithm=Algorithm.ROUND_ROBIN,
+        port=80,
+        protocol="http",
+        members=members,
+    )
 
     print(new_balancer)
 
@@ -54,7 +55,7 @@ def main():
         if balancer.state == State.RUNNING:
             break
 
-        print('sleeping for 30 seconds for balancers to become ready')
+        print("sleeping for 30 seconds for balancers to become ready")
         time.sleep(30)
 
     # fetch list of members
@@ -67,5 +68,6 @@ def main():
     # remove the balancer
     driver.destroy_balancer(new_balancer)
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     main()
diff --git a/example_storage.py b/example_storage.py
index be3058c..05e9cca 100644
--- a/example_storage.py
+++ b/example_storage.py
@@ -20,7 +20,7 @@ from libcloud.storage.providers import get_driver
 
 CloudFiles = get_driver(Provider.CLOUDFILES)
 
-driver = CloudFiles('access key id', 'secret key', region='ord')
+driver = CloudFiles("access key id", "secret key", region="ord")
 
 containers = driver.list_containers()
 container_objects = driver.list_container_objects(containers[0])
diff --git a/setup.py b/setup.py
index 05dc38b..d96ae99 100644
--- a/setup.py
+++ b/setup.py
@@ -24,6 +24,7 @@ from distutils.core import Command
 
 try:
     import epydoc  # NOQA
+
     has_epydoc = True
 except ImportError:
     has_epydoc = False
@@ -35,22 +36,23 @@ except ImportError:
 # 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']
+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]
+    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')]
+        names = [
+            n
+            for n in names
+            if not fnmatch.fnmatch(n, pattern) and not n.endswith(".py")
+        ]
     return names
 
 
@@ -70,7 +72,7 @@ def relative_to(base, relativee):
     basepath = os.path.abspath(base)
     relativee = os.path.abspath(relativee)
     if relativee.startswith(basepath):
-        relative = relativee[len(basepath):]
+        relative = relativee[len(basepath) :]
         if relative.startswith(os.sep):
             relative = relative[1:]
         return os.path.join(base, relative)
@@ -98,13 +100,17 @@ def get_packages(dname, pkgname=None, results=None, ignore=None, parent=None):
     subfiles = os.listdir(dname)
     abssubfiles = [os.path.join(dname, x) for x in subfiles]
 
-    if '__init__.py' in subfiles:
+    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]
+            get_packages(
+                subdir,
+                pkgname=pkgname + [bname],
+                results=results,
+                ignore=ignore,
+                parent=parent,
+            )
+    res = [".".join(result) for result in results]
     return res
 
 
@@ -143,10 +149,12 @@ def get_data_files(dname, ignore=None, parent=None):
             for filename in resultfiles:
                 file_path = os.path.join(directory, filename)
                 if parent:
-                    file_path = file_path.replace(parent + os.sep, '')
+                    file_path = file_path.replace(parent + os.sep, "")
                 result.append(file_path)
 
     return result
+
+
 # END: Taken from Twisted
 
 
@@ -155,19 +163,27 @@ def get_data_files(dname, ignore=None, parent=None):
 # installed / available
 PY_pre_36 = sys.version_info < (3, 6, 0)
 
-HTML_VIEWSOURCE_BASE = 'https://svn.apache.org/viewvc/libcloud/trunk'
-PROJECT_BASE_DIR = 'https://libcloud.apache.org'
-TEST_PATHS = ['libcloud/test', 'libcloud/test/common', 'libcloud/test/compute',
-              'libcloud/test/storage', 'libcloud/test/loadbalancer',
-              'libcloud/test/dns', 'libcloud/test/container',
-              'libcloud/test/backup']
-DOC_TEST_MODULES = ['libcloud.compute.drivers.dummy',
-                    'libcloud.storage.drivers.dummy',
-                    'libcloud.dns.drivers.dummy',
-                    'libcloud.container.drivers.dummy',
-                    'libcloud.backup.drivers.dummy']
-
-SUPPORTED_VERSIONS = ['PyPy 3.6+', 'Python 3.6+']
+HTML_VIEWSOURCE_BASE = "https://svn.apache.org/viewvc/libcloud/trunk"
+PROJECT_BASE_DIR = "https://libcloud.apache.org"
+TEST_PATHS = [
+    "libcloud/test",
+    "libcloud/test/common",
+    "libcloud/test/compute",
+    "libcloud/test/storage",
+    "libcloud/test/loadbalancer",
+    "libcloud/test/dns",
+    "libcloud/test/container",
+    "libcloud/test/backup",
+]
+DOC_TEST_MODULES = [
+    "libcloud.compute.drivers.dummy",
+    "libcloud.storage.drivers.dummy",
+    "libcloud.dns.drivers.dummy",
+    "libcloud.container.drivers.dummy",
+    "libcloud.backup.drivers.dummy",
+]
+
+SUPPORTED_VERSIONS = ["PyPy 3.6+", "Python 3.6+"]
 
 # NOTE: python_version syntax is only supported when build system has
 # setuptools >= 36.2
@@ -176,61 +192,66 @@ SUPPORTED_VERSIONS = ['PyPy 3.6+', 'Python 3.6+']
 # We rely on >= 2.26.0 to avoid issues with LGPL transitive dependency
 # See https://github.com/apache/libcloud/issues/1594 for more context
 INSTALL_REQUIREMENTS = []
-INSTALL_REQUIREMENTS.append('requests>=2.26.0')
+INSTALL_REQUIREMENTS.append("requests>=2.26.0")
 
 
 setuptools_version = tuple(setuptools.__version__.split(".")[0:2])
 setuptools_version = tuple([int(c) for c in setuptools_version])
 
 if setuptools_version < (36, 2):
-    if 'bdist_wheel' in sys.argv:
+    if "bdist_wheel" in sys.argv:
         # NOTE: We need to do that because we use universal wheel
-        msg = ('Need to use latest version of setuptools when building wheels to ensure included '
-               'metadata is correct. Current version: %s' % (setuptools.__version__))
+        msg = (
+            "Need to use latest version of setuptools when building wheels to ensure included "
+            "metadata is correct. Current version: %s" % (setuptools.__version__)
+        )
         raise RuntimeError(msg)
 
 TEST_REQUIREMENTS = [
-    'mock',
-    'requests_mock',
-    'pytest',
-    'pytest-runner'
+    "mock",
+    "requests_mock",
+    "pytest",
+    "pytest-runner",
 ] + INSTALL_REQUIREMENTS
 
 if PY_pre_36:
-    version = '.'.join([str(x) for x in sys.version_info[:3]])
-    print('Python version %s is not supported. Supported versions are: %s. '
-          'Latest version which supports Python 2.7 and Python 3 < 3.5.0 is '
-          'Libcloud v2.8.2 and Libcloud v3.4.0 for Python 3.5.' %
-          (version, ', '.join(SUPPORTED_VERSIONS)))
+    version = ".".join([str(x) for x in sys.version_info[:3]])
+    print(
+        "Python version %s is not supported. Supported versions are: %s. "
+        "Latest version which supports Python 2.7 and Python 3 < 3.5.0 is "
+        "Libcloud v2.8.2 and Libcloud v3.4.0 for Python 3.5."
+        % (version, ", ".join(SUPPORTED_VERSIONS))
+    )
     sys.exit(1)
 
 
 def read_version_string():
     version = None
     cwd = os.path.dirname(os.path.abspath(__file__))
-    version_file = os.path.join(cwd, 'libcloud/__init__.py')
+    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)
+    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')
+    raise Exception("Cannot find version in libcloud/__init__.py")
 
 
 def forbid_publish():
     argv = sys.argv
-    if 'upload'in argv:
-        print('You shouldn\'t use upload command to upload a release to PyPi. '
-              'You need to manually upload files generated using release.sh '
-              'script.\n'
-              'For more information, see "Making a release section" in the '
-              'documentation')
+    if "upload" in argv:
+        print(
+            "You shouldn't use upload command to upload a release to PyPi. "
+            "You need to manually upload files generated using release.sh "
+            "script.\n"
+            'For more information, see "Making a release section" in the '
+            "documentation"
+        )
         sys.exit(1)
 
 
@@ -249,63 +270,63 @@ class ApiDocsCommand(Command):
             raise RuntimeError('Missing "epydoc" package!')
 
         os.system(
-            'pydoctor'
-            ' --add-package=libcloud'
-            ' --project-name=libcloud'
-            ' --make-html'
+            "pydoctor"
+            " --add-package=libcloud"
+            " --project-name=libcloud"
+            " --make-html"
             ' --html-viewsource-base="%s"'
-            ' --project-base-dir=`pwd`'
-            ' --project-url="%s"'
-            % (HTML_VIEWSOURCE_BASE, PROJECT_BASE_DIR))
+            " --project-base-dir=`pwd`"
+            ' --project-url="%s"' % (HTML_VIEWSOURCE_BASE, PROJECT_BASE_DIR)
+        )
 
 
 forbid_publish()
 
-needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
-pytest_runner = ['pytest-runner'] if needs_pytest else []
+needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
+pytest_runner = ["pytest-runner"] if needs_pytest else []
 
 setup(
-    name='apache-libcloud',
+    name="apache-libcloud",
     version=read_version_string(),
-    description='A standard Python library that abstracts away differences' +
-                ' among multiple cloud provider APIs. For more information' +
-                ' and documentation, please see https://libcloud.apache.org',
-    long_description=open('README.rst').read(),
-    author='Apache Software Foundation',
-    author_email='dev@libcloud.apache.org',
+    description="A standard Python library that abstracts away differences"
+    + " among multiple cloud provider APIs. For more information"
+    + " and documentation, please see https://libcloud.apache.org",
+    long_description=open("README.rst").read(),
+    author="Apache Software Foundation",
+    author_email="dev@libcloud.apache.org",
     install_requires=INSTALL_REQUIREMENTS,
     python_requires=">=3.6, <4",
-    packages=get_packages('libcloud'),
+    packages=get_packages("libcloud"),
     package_dir={
-        'libcloud': 'libcloud',
+        "libcloud": "libcloud",
     },
     package_data={
-        'libcloud': get_data_files('libcloud', parent='libcloud') + ['py.typed'],
+        "libcloud": get_data_files("libcloud", parent="libcloud") + ["py.typed"],
     },
-    license='Apache License (2.0)',
-    url='https://libcloud.apache.org/',
+    license="Apache License (2.0)",
+    url="https://libcloud.apache.org/",
     setup_requires=pytest_runner,
     tests_require=TEST_REQUIREMENTS,
     cmdclass={
-        'apidocs': ApiDocsCommand,
+        "apidocs": ApiDocsCommand,
     },
     zip_safe=False,
     classifiers=[
-        'Development Status :: 5 - Production/Stable',
-        'Environment :: Console',
-        'Intended Audience :: Developers',
-        'Intended Audience :: System Administrators',
-        'License :: OSI Approved :: Apache Software License',
-        'Operating System :: OS Independent',
-        'Programming Language :: Python',
-        'Topic :: Software Development :: Libraries :: Python Modules',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-        'Programming Language :: Python :: 3.9',
-        'Programming Language :: Python :: 3.10',
-        'Programming Language :: Python :: Implementation :: CPython',
-        'Programming Language :: Python :: Implementation :: PyPy'
-    ]
+        "Development Status :: 5 - Production/Stable",
+        "Environment :: Console",
+        "Intended Audience :: Developers",
+        "Intended Audience :: System Administrators",
+        "License :: OSI Approved :: Apache Software License",
+        "Operating System :: OS Independent",
+        "Programming Language :: Python",
+        "Topic :: Software Development :: Libraries :: Python Modules",
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.10",
+        "Programming Language :: Python :: Implementation :: CPython",
+        "Programming Language :: Python :: Implementation :: PyPy",
+    ],
 )