Skip to content

Commit 6d193dd

Browse files
committed
Fix conflicts with base branch
2 parents 4288405 + 368daff commit 6d193dd

File tree

11 files changed

+71
-44
lines changed

11 files changed

+71
-44
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
name: msgraph-sdk-python-core
55

66
on:
7-
push:
8-
branches: [master]
97
pull_request:
10-
branches: [dev]
8+
branches: [master, dev]
119

1210
jobs:
1311
build:

.pypirc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ index-servers =
55

66
[pypi]
77
repository = https://upload.pypi.org/legacy/
8-
username = msgraphsdkteam # Replace with your PyPI username
8+
username = msgraphsdkteam
99

1010
[testpypi]
1111
repository = https://test.pypi.org/legacy/
12-
username = msgraphsdkteam # Replace with your TestPyPI username
12+
username = msgraphsdkteam-test

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[![CI Actions Status](https://github.com/microsoftgraph/msgraph-sdk-python-core/workflows/msgraph-sdk-python-core/badge.svg)](https://github.com/microsoftgraph/msgraph-sdk-python-core/actions)
22

3-
## Microsoft Graph Core Python Client Library
3+
## Microsoft Graph Core Python Client Library (preview).
44

55
The Microsoft Graph Core Python client library is a lightweight wrapper around the Microsoft Graph API. It provides functionality to create clients with desired configuration and middleware.
66

7+
**Disclaimer**: Please, be aware that preview versions of `msgraph-core` package are for testing purpose only. Do not use them in a production environment.
8+
79
## Prerequisites
810

911
Python 3.5+ (this library doesn't support older versions of Python)
@@ -15,13 +17,17 @@ The Microsoft Graph Core Python client library is a lightweight wrapper around t
1517
To call Microsoft Graph, your app must acquire an access token from the Microsoft identity platform. Learn more about this -
1618

1719
- [Authentication and authorization basics for Microsoft Graph](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)
18-
- [Register your app with the Microsoft identity platform](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)
20+
- [Register your app with the Microsoft identity platform](https://docs.microsoft.com/en-us/graph/auth-register-app-v2)
1921

2022

2123
### 2. Install the required packages
2224

23-
`pip install msgraph-core`
24-
`pip install azure-identity`
25+
msgraph-core is available on PyPI.
26+
27+
```cmd
28+
python -m pip install msgraph-core
29+
python -m pip install azure-identity
30+
```
2531

2632
### 3. Import modules
2733

@@ -53,7 +59,7 @@ result = client.get('/me')
5359
print(result.json())
5460
```
5561

56-
For more information on how to use the package, refer to the [samples](https://github.com/microsoftgraph/msgraph-sdk-python-core/tree/dev/samples)
62+
For more information on how to use the package, refer to the [samples](https://github.com/microsoftgraph/msgraph-sdk-python-core/tree/dev/samples).
5763

5864

5965
## Telemetry Metadata
@@ -66,7 +72,7 @@ View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-sdk
6672

6773
## Contributing
6874

69-
Please see the [contributing guidelines](CONTRIBUTING.rst)
75+
Please see the [contributing guidelines](CONTRIBUTING.rst).
7076

7177
## Copyright and license
7278

msgraph/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# -----------------------------------
5+
6+
# pylint: disable=line-too-long
7+
# This is to allow complete package description on PyPI
8+
"""
9+
Core component of the Microsoft Graph Python SDK consisting of HTTP/Graph Client and a configurable middleware pipeline (Preview).
10+
"""
11+
from .core import SDK_VERSION
12+
13+
__version__ = SDK_VERSION

msgraph/core/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"""
99
DEFAULT_REQUEST_TIMEOUT = 100
1010
DEFAULT_CONNECTION_TIMEOUT = 30
11-
SDK_VERSION = '0.1.0'
11+
SDK_VERSION = '0.1.2'

msgraph/core/_graph_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ._client_factory import HTTPClientFactory
88
from .middleware.request_context import RequestContext
99

10+
# These are middleware options that can be configured per request.
11+
# Supports options for default middleware as well as custom middleware.
1012
supported_options = [
1113
# Auth Options
1214
'scopes',
@@ -24,6 +26,7 @@
2426

2527

2628
def attach_context(func):
29+
"""Attaches a request context object to every graph request"""
2730
def wrapper(*args, **kwargs):
2831
middleware_control = dict()
2932

msgraph/core/middleware/request_context.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88

99

1010
class RequestContext:
11+
"""A request context contains data that is persisted throughout the request and
12+
includes a ClientRequestId property, MiddlewareControl property to control behavior
13+
of middleware as well as a FeatureUsage  property to keep track of middleware used
14+
in making the request.
15+
"""
1116
def __init__(self, middleware_control, headers):
17+
"""Constructor for request context instances
18+
19+
Args:
20+
middleware_control (dict): A dictionary of optional middleware options
21+
that can be accessed by middleware components to override the options provided
22+
during middleware initialization,
23+
24+
headers (dict): A dictionary containing the request headers. Used to check for a
25+
user provided client request id.
26+
"""
1227
self.middleware_control = middleware_control
1328
self.client_request_id = headers.get('client-request-id', str(uuid.uuid4()))
1429
self._feature_usage = FeatureUsageFlag.NONE

msgraph/core/middleware/retry.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,28 @@ def send(self, request, **kwargs):
112112
retry_valid = True
113113

114114
while retry_valid:
115-
try:
116-
start_time = time.time()
115+
start_time = time.time()
116+
if retry_count > 0:
117117
request.headers.update({'retry-attempt': '{}'.format(retry_count)})
118-
request.context.set_feature_usage = FeatureUsageFlag.RETRY_HANDLER_ENABLED
119-
response = super().send(request, **kwargs)
120-
# Check if the request needs to be retried based on the response method
121-
# and status code
122-
if self.should_retry(retry_options, response):
123-
# check that max retries has not been hit
124-
retry_valid = self.check_retry_valid(retry_options, retry_count)
125-
126-
# Get the delay time between retries
127-
delay = self.get_delay_time(retry_options, retry_count, response)
128-
129-
if retry_valid and delay < absolute_time_limit:
130-
time.sleep(delay)
131-
end_time = time.time()
132-
absolute_time_limit -= (end_time - start_time)
133-
# increment the count for retries
134-
retry_count += 1
135-
136-
continue
137-
break
138-
except Exception as error:
139-
raise error
118+
response = super().send(request, **kwargs)
119+
# Check if the request needs to be retried based on the response method
120+
# and status code
121+
if self.should_retry(retry_options, response):
122+
# check that max retries has not been hit
123+
retry_valid = self.check_retry_valid(retry_options, retry_count)
124+
125+
# Get the delay time between retries
126+
delay = self.get_delay_time(retry_options, retry_count, response)
127+
128+
if retry_valid and delay < absolute_time_limit:
129+
time.sleep(delay)
130+
end_time = time.time()
131+
absolute_time_limit -= (end_time - start_time)
132+
# increment the count for retries
133+
retry_count += 1
134+
135+
continue
136+
break
140137
return response
141138

142139
def should_retry(self, retry_options, response):

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ build-backend = "flit_core.buildapi"
66
module = "msgraph"
77
author = "Microsoft"
88
author-email = "[email protected]"
9-
home-page="https://github.com/microsoftgraph/msgraph-sdk-python-core"
9+
home-page = "https://github.com/microsoftgraph/msgraph-sdk-python-core"
1010
dist-name="msgraph-core"
11-
requires=[
12-
"requests >= 2.23.0",
13-
]
1411
requires-python=">=3.5"
15-
classifiers = ["License :: OSI Approved :: MIT License"]
12+
classifiers = [ "License :: OSI Approved :: MIT License",]
1613
description-file = "README.md"
1714

samples/retry_handler_samples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
def sample_http_client_with_custom_retry_defaults():
2121
"""
22-
Initializing a sample client with default middleware using the HTTPClientand passing
22+
Initializing a sample client with default middleware using the HTTPClient and passing
2323
default configs to the retryhandler. These defaults will be used for every subsequent
2424
request using the client."""
2525

0 commit comments

Comments
 (0)