Skip to content

Instantly share code, notes, and snippets.

View lmazuel's full-sized avatar

Laurent Mazuel lmazuel

View GitHub Profile
def wrapper(url, awaitable=False):
"""This is wrapper, that return the result or a awaitable future to get the result.
This wrapper does not involve asyncio and can parsed by Python 2.7."""
if awaitable:
from async_version import foo
return foo(url)
else:
from sync_version import foo
return foo(url)
@lmazuel
lmazuel / device_code.py
Created July 1, 2017 00:17
device code SDK
context = adal.AuthenticationContext(authority_url, api_version=None)
code = context.acquire_user_code(RESOURCE, clientid)
print(code['message'])
credentials = AdalAuthentication(
context.acquire_token_with_device_code,
resource,
code,
clientid
)
@lmazuel
lmazuel / template_uploader.py
Created June 8, 2017 20:44
Batch Template peuso code
def upload_template(client, resource_group, json_template):
api_version = extract_from_template(json_template)
new_batch_client = BatchClient(client.config.credentials, client.config.subscription_id, api_version)
models = new_batch_client.models(api_version)
built_model = build_template_model(models, json_template)
return new_batch_client.template.upload(resource_group, built_model).result()
@lmazuel
lmazuel / adflist.py
Created April 14, 2017 22:51
adf list
import time
while True:
pipeline_runs = list(self._adf_client.pipeline_runs.list_by_factory(self.group_name, df_name))
if pipeline_runs:
break
time.sleep(15)
@lmazuel
lmazuel / setup.py
Created March 23, 2017 19:59
Wheel override proto
#!/usr/bin/env python
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------
from setuptools import setup
from distutils import log as logger
@lmazuel
lmazuel / fspath.py
Last active September 19, 2018 14:57
Fspath for Python < 3.6
def fspath(path):
'''https://www.python.org/dev/peps/pep-0519/#os'''
if isinstance(path, (str, bytes)):
return path
# Work from the object's type to match method resolution of other magic
# methods.
path_type = type(path)
try:
path = path_type.__fspath__(path)