Skip to content

Commit 0b8c774

Browse files
authored
Merge pull request #69 from microsoftgraph/task/update-ci
Update Github actions config to use Pipenv to run tests and linter
2 parents 500bd71 + 066be4a commit 0b8c774

23 files changed

+395
-145
lines changed

.github/workflows/ci.yml

+26-21
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,39 @@ name: msgraph-sdk-python-core
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ dev ]
10+
branches: [dev]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615
strategy:
1716
matrix:
1817
python-version: [3.5, 3.6, 3.7, 3.8]
1918

2019
steps:
21-
- uses: actions/checkout@v2
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v1
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install -r requirements.txt
30-
pip install -r dev_requirements.txt
31-
- name: Lint with Pylint
32-
run: |
33-
pylint msgraphcore --disable=W --rcfile=.pylintrc
34-
- name: Test with pytest
35-
run: |
36-
coverage run --omit 'venv/*' -m unittest discover tests/unit
37-
coverage run --omit 'venv/*' -m unittest discover tests/integration
38-
coverage html
20+
- uses: actions/checkout@v2
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v1
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install pipenv
29+
pipenv install --dev
30+
- name: Check code format
31+
run: |
32+
pipenv run yapf -dr .
33+
- name: Check import order
34+
run: |
35+
pipenv run isort .
36+
- name: Lint with Pylint
37+
run: |
38+
pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
39+
- name: Test with unittest
40+
run: |
41+
pipenv run coverage run -m unittest discover tests/unit
42+
pipenv run coverage run -m unittest discover tests/integration
43+
pipenv run coverage html

.isort.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile=hug

.pre-commit-config.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
default_language_version:
2+
python: python3
3+
repos:
4+
- repo: local
5+
hooks:
6+
- id: yapf
7+
name: yapf
8+
stages: [commit]
9+
language: system
10+
entry: pipenv run yapf -ir .
11+
types: [python]
12+
13+
- id: isort
14+
name: isort
15+
stages: [commit]
16+
language: system
17+
entry: pipenv run isort .
18+
types: [python]
19+
20+
- id: pylint
21+
name: pylint
22+
stages: [commit]
23+
language: system
24+
entry: pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
25+
types: [python]

.pylintrc

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ disable=print-statement,
144144
missing-module-docstring,
145145
missing-class-docstring,
146146
missing-function-docstring,
147+
C0330,
148+
R0801,
147149

148150
# Enable the message, report, category or checker with the given id(s). You can
149151
# either give multiple identifier separated by comma (,) or put this option

.style.yapf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[style]
2+
based_on_style = pep8
3+
dedent_closing_brackets = true
4+
each_dict_entry_on_separate_line = true
5+
column_limit = 100

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.linting.enabled": true,
3+
"python.linting.pylintPath": "pylint",
4+
"editor.formatOnSave": true,
5+
"python.formatting.provider": "yapf",
6+
"python.linting.pylintEnabled": true,
7+
}

Pipfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ name = "pypi"
55

66
[packages] # Packages required to run the application
77
requests = "==2.23.0"
8+
pre-commit = "==2.10.1"
89

910
[dev-packages] # Packages required to develop the application
1011
coverage = "==5.0.3"
11-
pylint = "==2.4.4"
12+
pylint = "==2.6.0"
1213
responses = "==0.10.12"
1314
flit = "==2.2.0"
1415
azure-identity = "==1.5.0"
16+
isort = "==5.7.0"
17+
yapf = "==0.30.0"
18+
mypy = "==0.800"

Pipfile.lock

+268-76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![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)
2+
13
## Microsoft Graph Python Client Library
24

35
The Microsoft Graph Python client library is a lightweight wrapper around

docs/conf.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
1616

17-
1817
# -- Project information -----------------------------------------------------
1918

2019
project = 'msgraph-sdk-python'
@@ -24,14 +23,12 @@
2423
# The full version, including alpha/beta/rc tags
2524
release = '0.0.1'
2625

27-
2826
# -- General configuration ---------------------------------------------------
2927

3028
# Add any Sphinx extension module names here, as strings. They can be
3129
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3230
# ones.
33-
extensions = [
34-
]
31+
extensions = []
3532

3633
# Add any paths that contain templates here, relative to this directory.
3734
templates_path = ['_templates']
@@ -41,7 +38,6 @@
4138
# This pattern also affects html_static_path and html_extra_path.
4239
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
4340

44-
4541
# -- Options for HTML output -------------------------------------------------
4642

4743
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -52,4 +48,4 @@
5248
# Add any paths that contain custom static files (such as style sheets) here,
5349
# relative to this directory. They are copied after the builtin static files,
5450
# so a file named "default.css" will overwrite the builtin "default.css".
55-
html_static_path = ['_static']
51+
html_static_path = ['_static']

msgraphcore/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""msgraph-core"""
22

33
from msgraphcore.graph_session import GraphSession
4+
45
from .constants import SDK_VERSION
56

67
__version__ = SDK_VERSION

msgraphcore/graph_session.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from requests import Session
55

66
from msgraphcore.constants import BASE_URL, SDK_VERSION
7-
from msgraphcore.middleware.middleware import MiddlewarePipeline, BaseMiddleware
87
from msgraphcore.middleware.abc_token_credential import TokenCredential
98
from msgraphcore.middleware.authorization import AuthorizationHandler
9+
from msgraphcore.middleware.middleware import BaseMiddleware, MiddlewarePipeline
1010
from msgraphcore.middleware.options.middleware_control import middleware_control
1111

1212

@@ -15,12 +15,13 @@ class GraphSession(Session):
1515
1616
Extends Session by adding support for middleware options and middleware pipeline
1717
"""
18-
def __init__(self,
19-
credential: TokenCredential,
20-
scopes: [str] = ['.default'],
21-
middleware: list = [],
22-
api_version: str = 'v1.0'
23-
):
18+
def __init__(
19+
self,
20+
credential: TokenCredential,
21+
scopes: [str] = ['.default'],
22+
middleware: list = [],
23+
api_version: str = 'v1.0'
24+
):
2425
super().__init__()
2526
self._append_sdk_version()
2627
self._base_url = BASE_URL + '/' + api_version
@@ -94,7 +95,7 @@ def _graph_url(self, url: str) -> str:
9495
:param url: user provided path
9596
:return: graph_url
9697
"""
97-
return self._base_url+url if (url[0] == '/') else url
98+
return self._base_url + url if (url[0] == '/') else url
9899

99100
def _register(self, middleware: [BaseMiddleware]) -> None:
100101
"""Adds middleware to middleware_pipeline
@@ -113,7 +114,11 @@ def _append_sdk_version(self) -> None:
113114
"""Updates sdkVersion in headers with comma-separated new values
114115
"""
115116
if 'sdkVersion' in self.headers:
116-
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION + ', '
117-
+ self.headers.get('sdkVersion')})
117+
self.headers.update(
118+
{
119+
'sdkVersion':
120+
'graph-python-' + SDK_VERSION + ', ' + self.headers.get('sdkVersion')
121+
}
122+
)
118123
else:
119124
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})

msgraphcore/middleware/abc_token_credential.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ class TokenCredential(ABC):
55
@abstractmethod
66
def get_token(self, *scopes, **kwargs):
77
pass
8-

msgraphcore/middleware/authorization.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS
2+
13
from .abc_token_credential import TokenCredential
2-
from ..constants import AUTH_MIDDLEWARE_OPTIONS
34
from .middleware import BaseMiddleware
45
from .options.middleware_control import middleware_control
56

msgraphcore/middleware/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ssl
2-
from urllib3 import PoolManager
32

43
from requests.adapters import HTTPAdapter
4+
from urllib3 import PoolManager
55

66

77
class MiddlewarePipeline(HTTPAdapter):
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class AuthMiddlewareOptions:
32
def __init__(self, scopes: [str]):
43
self.scopes = scopes

msgraphcore/middleware/options/middleware_control.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS
2-
from ..options.auth_middleware_options import AuthMiddlewareOptions
2+
3+
from .auth_middleware_options import AuthMiddlewareOptions
34

45

56
class MiddlewareControl:
@@ -22,6 +23,7 @@ def wrapper(*args, **kwargs):
2223
# Set middleware options, for use by middleware in the middleware pipeline
2324
self.set(AUTH_MIDDLEWARE_OPTIONS, AuthMiddlewareOptions(scopes))
2425
return func(*args, **kwargs)
26+
2527
return wrapper
2628

2729
def _reset_middleware_options(self):

mypy.ini

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
files=msgraphcore
3+
ignore_missing_imports=true

samples/samples.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
from pprint import pprint
3+
34
from azure.identity import InteractiveBrowserCredential
5+
46
from msgraphcore import GraphSession
57

68
scopes = ['user.read']
@@ -16,13 +18,12 @@ def post_sample():
1618
'contentType': 'Text',
1719
'content': 'The new cafeteria is open.'
1820
},
19-
'toRecipients': [
20-
{
21-
'emailAddress': {
22-
'address': 'ENTER_RECEPIENT_EMAIL_ADDRESS'
23-
}
21+
'toRecipients': [{
22+
'emailAddress': {
23+
'address': 'ENTER_RECEPIENT_EMAIL_ADDRESS'
2424
}
25-
]}
25+
}]
26+
}
2627
}
2728

2829
result = graph_session \
@@ -42,4 +43,3 @@ def get_sample():
4243
if __name__ == '__main__':
4344
post_sample()
4445
get_sample()
45-

tests/integration/test_middleware_pipeline.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
class MiddlewarePipelineTest(TestCase):
88
def setUp(self):
9-
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
9+
warnings.filterwarnings(
10+
"ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>"
11+
)
1012

1113
def test_middleware_pipeline(self):
1214
url = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
@@ -21,6 +23,3 @@ def test_middleware_pipeline(self):
2123
class _CustomTokenCredential:
2224
def get_token(self, scopes):
2325
return ['{token:https://graph.microsoft.com/}']
24-
25-
26-

tests/unit/test_auth_handler.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS
44
from msgraphcore.middleware.authorization import AuthorizationHandler
5-
from msgraphcore.middleware.options.middleware_control import middleware_control
65
from msgraphcore.middleware.options.auth_middleware_options import AuthMiddlewareOptions
6+
from msgraphcore.middleware.options.middleware_control import middleware_control
77

88

99
class TestAuthorizationHandler(unittest.TestCase):
@@ -26,5 +26,3 @@ def test_auth_handler_get_scopes_does_not_overwrite_default_scopes(self):
2626
auth_handler.get_scopes()
2727

2828
self.assertEqual(auth_handler.scopes, default_scopes)
29-
30-

tests/unit/test_graph_session.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from unittest import TestCase
22

3+
import responses
34
from requests import Session
45
from requests.adapters import HTTPAdapter
5-
import responses
66

7-
from msgraphcore.graph_session import GraphSession
87
from msgraphcore.constants import BASE_URL, SDK_VERSION
8+
from msgraphcore.graph_session import GraphSession
99

1010

1111
class GraphSessionTest(TestCase):
@@ -26,8 +26,9 @@ def test_has_sdk_version_header(self):
2626
self.assertTrue('sdkVersion' in self.requests.headers)
2727

2828
def test_updated_sdk_version(self):
29-
self.assertTrue(self.requests.headers.get('sdkVersion')
30-
.startswith('graph-python-'+SDK_VERSION))
29+
self.assertTrue(
30+
self.requests.headers.get('sdkVersion').startswith('graph-python-' + SDK_VERSION)
31+
)
3132

3233
def test_initialized_with_middlewares(self):
3334
graph_session = GraphSession(self.credential)

0 commit comments

Comments
 (0)