-
Notifications
You must be signed in to change notification settings - Fork 3.3k
add core experimental #26272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add core experimental #26272
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
398b50f
add core experimental
xiangyan99 254b472
update
xiangyan99 f33fc6b
update
xiangyan99 92fa9ff
update
xiangyan99 8279243
fix typo
xiangyan99 32aeb70
update
xiangyan99 3cf9caa
update
xiangyan99 72ad920
update
xiangyan99 93545fb
update
xiangyan99 878cd01
update
xiangyan99 37a89e1
updates
xiangyan99 c2e859f
update
xiangyan99 f4fc124
update
xiangyan99 1b6af19
updates
xiangyan99 3b8013e
update
xiangyan99 804ecd4
Update dev_requirements.txt
xiangyan99 74bd77c
Update dev_requirements.txt
xiangyan99 f4032a6
update
xiangyan99 415c943
update
xiangyan99 6fa3b83
update
xiangyan99 6f1906f
update
xiangyan99 752ff7f
update
xiangyan99 ffc1920
updates
xiangyan99 da79d5b
update
xiangyan99 1e59798
Merge branch 'core-experimental' of https://github.com/Azure/azure-sd…
xiangyan99 8279f48
update
xiangyan99 398cc37
update
xiangyan99 ba0f1a9
Update CHANGELOG.md
xiangyan99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Release History | ||
|
|
||
| ## 1.0.0b1 (2022-10-06) | ||
|
|
||
| Initial release | ||
|
|
||
| ### Features Added | ||
|
|
||
| - pyodide implementation of azure-core transport protocol | ||
|
xiangyan99 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Copyright (c) Microsoft Corporation. | ||
|
|
||
| MIT License | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| recursive-include tests *.py | ||
| include *.md | ||
| include LICENSE | ||
| include azure/__init__.py | ||
| include azure/core/__init__.py | ||
| include azure/core/experimental/__init__.py | ||
| include azure/core/experimental/transport/*.py | ||
| recursive-include samples *.py | ||
| include azure/core/experimental/py.typed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
|
|
||
| # Azure Core Experimental client library for Python | ||
|
|
||
| Azure Core Experimental client library provides experimental features that are not ready for stable release. The main reason might be because the feature depends on some other packages that there is no stable version available yet. If its dependant package introduces breaking changes, the features maybe break. It is not recommended to use azure core experimental library in production environment. | ||
|
|
||
| ## Getting started | ||
|
|
||
| Install the azure core experimental package with [pip](https://pypi.org/project/pip/): | ||
|
|
||
| ```bash | ||
| pip install azure-core-experimental | ||
| ``` | ||
|
|
||
| ## Features list | ||
|
|
||
| - pyodide transport | ||
|
|
||
| ## Contributing | ||
|
|
||
| This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. | ||
|
|
||
| When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. | ||
|
|
||
| This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| __path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| __path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore |
28 changes: 28 additions & 0 deletions
28
sdk/core/azure-core-experimental/azure/core/experimental/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # | ||
| # The MIT License (MIT) | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the ""Software""), to | ||
| # deal in the Software without restriction, including without limitation the | ||
| # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| # sell copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| # IN THE SOFTWARE. | ||
| # | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| from ._version import VERSION | ||
|
annatisch marked this conversation as resolved.
|
||
| __version__ = VERSION | ||
6 changes: 6 additions & 0 deletions
6
sdk/core/azure-core-experimental/azure/core/experimental/_version.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| VERSION = "1.0.0b1" |
Empty file.
45 changes: 45 additions & 0 deletions
45
sdk/core/azure-core-experimental/azure/core/experimental/transport/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # | ||
| # The MIT License (MIT) | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the ""Software""), to | ||
| # deal in the Software without restriction, including without limitation the | ||
| # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| # sell copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| # IN THE SOFTWARE. | ||
| # | ||
| # -------------------------------------------------------------------------- | ||
| import sys | ||
|
|
||
| # pylint: disable=undefined-all-variable | ||
|
|
||
| if sys.version_info >= (3, 7): | ||
| __all__ = [ | ||
| 'PyodideTransport', | ||
| ] | ||
|
|
||
| def __dir__(): | ||
| return __all__ | ||
|
|
||
| def __getattr__(name): | ||
| if name == 'PyodideTransport': | ||
| try: | ||
| from ._pyodide import PyodideTransport | ||
| return PyodideTransport | ||
| except ImportError: | ||
| raise ImportError("pyodide package is not installed") | ||
| raise AttributeError(f"module 'azure.core.experimental.transport' has no attribute {name}") |
158 changes: 158 additions & 0 deletions
158
sdk/core/azure-core-experimental/azure/core/experimental/transport/_pyodide.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # | ||
| # The MIT License (MIT) | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the ""Software""), to | ||
| # deal in the Software without restriction, including without limitation the | ||
| # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| # sell copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| # IN THE SOFTWARE. | ||
| # | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
| from collections.abc import AsyncIterator | ||
| from io import BytesIO | ||
|
|
||
| import js # pylint: disable=import-error | ||
| from pyodide import JsException # pylint: disable=import-error | ||
| from pyodide.http import pyfetch # pylint: disable=import-error | ||
|
|
||
| from azure.core.exceptions import HttpResponseError | ||
| from azure.core.pipeline import Pipeline | ||
| from azure.core.utils import CaseInsensitiveDict | ||
|
|
||
| from azure.core.rest._http_response_impl_async import AsyncHttpResponseImpl | ||
| from azure.core.pipeline.transport import HttpRequest, AsyncioRequestsTransport | ||
|
|
||
|
|
||
| class PyodideTransportResponse(AsyncHttpResponseImpl): | ||
| """Async response object for the `PyodideTransport`.""" | ||
|
|
||
|
|
||
| def _js_stream(self): | ||
| """So we get a fresh stream every time.""" | ||
| return self._internal_response.clone().js_response.body | ||
|
|
||
| async def close(self) -> None: | ||
| """We don't actually have control over closing connections in the browser, so we just pretend | ||
| to close. | ||
| """ | ||
| self._is_closed = True | ||
|
|
||
| def body(self) -> bytes: | ||
| """The body is just the content.""" | ||
| return self.content | ||
|
|
||
| async def load_body(self) -> None: | ||
| """Backcompat""" | ||
| if self._content is None: | ||
| self._content = await self._internal_response.clone().bytes() | ||
|
|
||
| class PyodideStreamDownloadGenerator(AsyncIterator): | ||
| """Simple stream download generator that returns the contents of | ||
| a request. | ||
| """ | ||
|
|
||
| # pylint: disable=unused-argument | ||
| def __init__(self, pipeline: Pipeline, response: PyodideTransportResponse, *_, **kwargs): | ||
| self._block_size = response._block_size | ||
| self.response = response | ||
| # use this to efficiently store bytes. | ||
| if kwargs.pop("decompress", False) and self.response.headers.get("enc", None) in ("gzip", "deflate"): | ||
| self._js_reader = response._js_stream().pipeThrough(js.DecompressionStream.new("gzip")).getReader() | ||
| else: | ||
| self._js_reader = response._js_stream().getReader() | ||
| self._stream = BytesIO() | ||
|
|
||
| self._closed = False | ||
| # We cannot control how many bytes we get from `response.reader`. `self._buffer_left` | ||
| # indicates how many unread bytes there are in `self.stream` | ||
| self._buffer_left = 0 | ||
| self.done = False | ||
|
|
||
| async def __anext__(self) -> bytes: | ||
| """Get the next block of bytes.""" | ||
| if self._closed: | ||
| raise StopAsyncIteration() | ||
|
|
||
| # remember the initial stream position | ||
| start_pos = self._stream.tell() | ||
| # move stream position to the end | ||
| self._stream.read() | ||
| # read from reader until there is no more data or we have `self._block_size` unread bytes. | ||
| while self._buffer_left < self._block_size: | ||
| read = await self._js_reader.read() | ||
| if read.done: | ||
| self._closed = True | ||
| break | ||
| self._buffer_left += self._stream.write(bytes(read.value)) | ||
|
|
||
| # move the stream position back to where we started | ||
| self._stream.seek(start_pos) | ||
| self._buffer_left -= self._block_size | ||
| return self._stream.read(self._block_size) | ||
|
|
||
| class PyodideTransport(AsyncioRequestsTransport): | ||
| """**This object is experimental**, meaning it may be changed in a future release | ||
| or might break with a future Pyodide release. This transport was built with Pyodide | ||
| version 0.20.0. | ||
|
|
||
| Implements a basic HTTP sender using the Pyodide Javascript Fetch API. | ||
| """ | ||
|
|
||
| async def send(self, request: HttpRequest, **kwargs) -> PyodideTransportResponse: | ||
| """Send request object according to configuration. | ||
|
|
||
| :param request: The request object to be sent. | ||
| :type request: ~azure.core.pipeline.transport.HttpRequest | ||
| :return: An HTTPResponse object. | ||
| :rtype: PyodideResponseTransport | ||
| """ | ||
| stream_response = kwargs.pop("stream_response", False) | ||
| endpoint = request.url | ||
| request_headers = dict(request.headers) | ||
| init = { | ||
| "method": request.method, | ||
| "headers": request_headers, | ||
| "body": request.data, | ||
| "files": request.files, | ||
| "verify": kwargs.pop("connection_verify", self.connection_config.verify), | ||
| "cert": kwargs.pop("connection_cert", self.connection_config.cert), | ||
| "allow_redirects": False, | ||
| **kwargs, | ||
| } | ||
|
|
||
| try: | ||
| response = await pyfetch(endpoint, **init) | ||
| except JsException as error: | ||
| raise HttpResponseError(error, error=error) | ||
|
|
||
| headers = CaseInsensitiveDict(response.js_response.headers) | ||
| transport_response = PyodideTransportResponse( | ||
| request=request, | ||
| internal_response=response, | ||
| block_size=self.connection_config.data_block_size, | ||
| status_code=response.status, | ||
| reason=response.status_text, | ||
| content_type=headers.get("content-type"), | ||
| headers=headers, | ||
| stream_download_generator=PyodideStreamDownloadGenerator, | ||
| ) | ||
| if not stream_response: | ||
| await transport_response.load_body() | ||
|
|
||
| return transport_response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -e ../../../tools/azure-sdk-tools | ||
| ../azure-core | ||
| -e ../../../tools/azure-devtools | ||
| js | ||
| pyodide==0.19.0a1; python_version >= '3.8' |
27 changes: 27 additions & 0 deletions
27
sdk/core/azure-core-experimental/samples/pyodide_integration/async_testing.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import traceback | ||
| import sys | ||
|
|
||
|
|
||
| class AsyncTestSuite: | ||
| """Async test cases | ||
| Test must be asynchronous and follow the pattern `test*`. | ||
| """ | ||
|
|
||
| async def run(self): | ||
| """Run the tests an print the results.""" | ||
| print("".join(("-" * 8, type(self).__name__, "-" * 8))) | ||
| for method_name in dir(self): | ||
| if not method_name.startswith("test"): | ||
| continue | ||
| print(method_name, end="... ") | ||
| try: | ||
| await getattr(self, method_name)() | ||
| except AssertionError: | ||
| print("FAIL") | ||
| traceback.print_exception(*sys.exc_info()) | ||
| except Exception: # pylint: disable=broad-except | ||
| print("ERROR") | ||
| traceback.print_exception(*sys.exc_info()) | ||
| else: | ||
| print("PASS") | ||
| print() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.