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 2019/12/21 16:44:34 UTC

[libcloud] branch trunk updated (dc494b5 -> 9ce7d84)

This is an automated email from the ASF dual-hosted git repository.

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


    from dc494b5  Add some docs on how to access the output of a deployment step.
     new d0ebd7b  Add type hints / annotations for the rest of the base compute API.
     new c7d0740  Include py.typed data file to signal that this package (atm only libcloud.compute base API) includes type annotations.
     new 9ce7d84  Update docs.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGES.rst                                     | 11 ++++++
 docs/developer_information.rst                  | 21 +++++++++-
 libcloud/compute/base.py                        | 51 ++++++++++++++++++++-----
 pylint_plugins/__init__.py => libcloud/py.typed |  0
 setup.py                                        |  4 +-
 5 files changed, 75 insertions(+), 12 deletions(-)
 copy pylint_plugins/__init__.py => libcloud/py.typed (100%)


[libcloud] 03/03: Update docs.

Posted by to...@apache.org.
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 9ce7d847c14f8fbbbff33e3fe465a9aa7f93f702
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sat Dec 21 17:40:29 2019 +0100

    Update docs.
---
 docs/developer_information.rst | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/docs/developer_information.rst b/docs/developer_information.rst
index 57da5ab..3ab027a 100644
--- a/docs/developer_information.rst
+++ b/docs/developer_information.rst
@@ -5,7 +5,7 @@ Type Annotations
 ----------------
 
 Python type annotations / hints for the base Libcloud compute API have been
-added in v2.7.0.
+added in v2.8.0.
 
 The goal behind type annotations is to make developer lives easier by
 introducing optional static typing for Python programs.
@@ -19,6 +19,25 @@ An example of how to use type annotations correctly is shown below.
 
 .. literalinclude:: /examples/compute/example_compute.py
 
+If you reference an invalid object attribute or a method, you would
+see an error similar to the one beloe when running mypy:
+
+.. sourcecode:: python
+
+    ...
+    print(nodes[0].name)
+    print(nodes[0].invalid)
+    print(nodes[0].rebbot())
+    print(nodes[0].reboot(foo='invalid'))
+    ...
+
+.. sourcecode:: bash
+
+    $ mypy --no-incremental example_compute.py
+    example_compute.py:41: error: "Node" has no attribute "invalid"
+    example_compute.py:42: error: "Node" has no attribute "rebbot"; maybe "reboot"?
+    example_compute.py:43: error: Unexpected keyword argument "foo" for "reboot" of "Node"
+
 If you are using driver methods which are not part of the Libcloud standard
 API, you need to use ``cast()`` method as shown below to cast the driver class
 to the correct type. If you don't do that, ``mypy`` will only be aware of the


[libcloud] 02/03: Include py.typed data file to signal that this package (atm only libcloud.compute base API) includes type annotations.

Posted by to...@apache.org.
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 c7d074001d825b58fdaa389635b893aa78819c74
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sat Dec 21 17:32:38 2019 +0100

    Include py.typed data file to signal that this package (atm only
    libcloud.compute base API) includes type annotations.
---
 CHANGES.rst       | 7 +++++++
 libcloud/py.typed | 0
 setup.py          | 4 +++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 653544e..adcd6a2 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,6 +20,13 @@ Common
   (GITHUB-1391, GITHUB-1390)
   [Tomaz Muraus]
 
+- Include ``py.typed`` data file to signal that this package contains type
+  annotations / hints.
+
+  NOTE: At the moment, type annotations are only available for the base
+  compute API.
+  [Tomaz Muraus]
+
 Compute
 -------
 
diff --git a/libcloud/py.typed b/libcloud/py.typed
new file mode 100644
index 0000000..e69de29
diff --git a/setup.py b/setup.py
index 7eec1f1..0436fe4 100644
--- a/setup.py
+++ b/setup.py
@@ -273,7 +273,9 @@ setup(
     package_dir={
         'libcloud': 'libcloud',
     },
-    package_data={'libcloud': get_data_files('libcloud', parent='libcloud')},
+    package_data={
+        'libcloud': get_data_files('libcloud', parent='libcloud') + ['py.typed'],
+    },
     license='Apache License (2.0)',
     url='http://libcloud.apache.org/',
     setup_requires=pytest_runner,


[libcloud] 01/03: Add type hints / annotations for the rest of the base compute API.

Posted by to...@apache.org.
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 d0ebd7b41cb90fc69e90a056519b5e25cf0e2866
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sat Dec 21 17:26:04 2019 +0100

    Add type hints / annotations for the rest of the base compute API.
---
 CHANGES.rst              |  4 ++++
 libcloud/compute/base.py | 51 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 8196fbc..653544e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -73,6 +73,10 @@ Compute
   and ``__str__`` method to the ``ScriptDeployment`` class.
   [Tomaz Muraus]
 
+- [Common] Add type annotations / hints for rest of the base compute API
+  classes and methods.
+  [Tomaz Muraus]
+
 Storage
 -------
 
diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index 35a0b82..56737d7 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -247,6 +247,7 @@ class Node(UuidMixin):
         UuidMixin.__init__(self)
 
     def reboot(self):
+        # type: () -> bool
         """
         Reboot this node
 
@@ -287,6 +288,7 @@ class Node(UuidMixin):
         return self.driver.stop_node(self)
 
     def destroy(self):
+        # type: () -> bool
         """
         Destroy this node
 
@@ -568,7 +570,7 @@ class NodeAuthSSHKey(object):
     def __init__(self, pubkey):
         # type: (str) -> None
         """
-        :param pubkey: Public key matetiral.
+        :param pubkey: Public key material.
         :type pubkey: ``str``
         """
         self.pubkey = pubkey
@@ -582,6 +584,7 @@ class NodeAuthPassword(object):
     A password to be used for authentication to a node.
     """
     def __init__(self, password, generated=False):
+        # type: (str, bool) -> None
         """
         :param password: Password.
         :type password: ``str``
@@ -601,8 +604,15 @@ class StorageVolume(UuidMixin):
     A base StorageVolume class to derive from.
     """
 
-    def __init__(self, id, name, size, driver,
-                 state=None, extra=None):
+    def __init__(self,
+                 id,  # type: str
+                 name,  # type: str
+                 size,  # type: int
+                 driver,  # type: NodeDriver
+                 state=None,  # type: Optional[StorageVolumeState]
+                 extra=None  # type: Optional[Dict]
+                 ):
+        # type: (...) -> None
         """
         :param id: Storage volume ID.
         :type id: ``str``
@@ -632,12 +642,14 @@ class StorageVolume(UuidMixin):
         UuidMixin.__init__(self)
 
     def list_snapshots(self):
+        # type: () -> List[VolumeSnapshot]
         """
         :rtype: ``list`` of ``VolumeSnapshot``
         """
         return self.driver.list_volume_snapshots(volume=self)
 
     def attach(self, node, device=None):
+        # type: (Node, Optional[str]) -> bool
         """
         Attach this volume to a node.
 
@@ -651,20 +663,20 @@ class StorageVolume(UuidMixin):
         :return: ``True`` if attach was successful, ``False`` otherwise.
         :rtype: ``bool``
         """
-
         return self.driver.attach_volume(node=node, volume=self, device=device)
 
     def detach(self):
+        # type: () -> bool
         """
         Detach this volume from its node
 
         :return: ``True`` if detach was successful, ``False`` otherwise.
         :rtype: ``bool``
         """
-
         return self.driver.detach_volume(volume=self)
 
     def snapshot(self, name):
+        # type: (str) -> VolumeSnapshot
         """
         Creates a snapshot of this volume.
 
@@ -674,6 +686,7 @@ class StorageVolume(UuidMixin):
         return self.driver.create_volume_snapshot(volume=self, name=name)
 
     def destroy(self):
+        # type: () -> bool
         """
         Destroy this storage volume.
 
@@ -692,8 +705,16 @@ class VolumeSnapshot(object):
     """
     A base VolumeSnapshot class to derive from.
     """
-    def __init__(self, id, driver, size=None, extra=None, created=None,
-                 state=None, name=None):
+    def __init__(self,
+                 id,  # type: str
+                 driver,  # type: NodeDriver
+                 size=None,  # type: int
+                 extra=None,  # type: Optional[Dict]
+                 created=None,  # type: Optional[datetime.datetime]
+                 state=None,  # type: StorageVolumeState
+                 name=None  # type: Optional[str]
+                 ):
+        # type: (...) -> None
         """
         VolumeSnapshot constructor.
 
@@ -716,7 +737,7 @@ class VolumeSnapshot(object):
 
         :param      state: A string representing the state the snapshot is
                            in. See `libcloud.compute.types.StorageVolumeState`.
-        :type       state: ``str``
+        :type       state: ``StorageVolumeState``
 
         :param      name: A string representing the name of the snapshot
         :type       name: ``str``
@@ -730,6 +751,7 @@ class VolumeSnapshot(object):
         self.name = name
 
     def destroy(self):
+        # type: () -> bool
         """
         Destroys this snapshot.
 
@@ -747,8 +769,15 @@ class KeyPair(object):
     Represents a SSH key pair.
     """
 
-    def __init__(self, name, public_key, fingerprint, driver, private_key=None,
-                 extra=None):
+    def __init__(self,
+                 name,  # type: str
+                 public_key,  # type: str
+                 fingerprint,  # type: str
+                 driver,  # type: NodeDriver
+                 private_key=None,  # type: Optional[str]
+                 extra=None  # type: Optional[Dict]
+                 ):
+        # type: (...) -> None
         """
         Constructor.
 
@@ -1613,6 +1642,7 @@ class NodeDriver(BaseDriver):
                             driver=self)
 
     def _get_and_check_auth(self, auth):
+        # type: (T_Auth) -> T_Auth
         """
         Helper function for providers supporting :class:`.NodeAuthPassword` or
         :class:`.NodeAuthSSHKey`
@@ -1799,6 +1829,7 @@ class NodeDriver(BaseDriver):
         return node
 
     def _get_size_price(self, size_id):
+        # type: (str) -> float
         """
         Return pricing information for the provided size id.
         """