Skip to content

Update Github actions config to use Pipenv to run tests and linter #69

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 18 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@ name: msgraph-sdk-python-core

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ dev ]
branches: [dev]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev_requirements.txt
- name: Lint with Pylint
run: |
pylint msgraphcore --disable=W --rcfile=.pylintrc
- name: Test with pytest
run: |
coverage run --omit 'venv/*' -m unittest discover tests/unit
coverage run --omit 'venv/*' -m unittest discover tests/integration
coverage html
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
- name: Check code format
run: |
pipenv run yapf -dr .
- name: Check import order
run: |
pipenv run isort .
- name: Lint with Pylint
run: |
pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
- name: Test with unittest
run: |
pipenv run coverage run -m unittest discover tests/unit
pipenv run coverage run -m unittest discover tests/integration
pipenv run coverage html
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=hug
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default_language_version:
python: python3
repos:
- repo: local
hooks:
- id: yapf
name: yapf
stages: [commit]
language: system
entry: pipenv run yapf -ir .
types: [python]

- id: isort
name: isort
stages: [commit]
language: system
entry: pipenv run isort .
types: [python]

- id: pylint
name: pylint
stages: [commit]
language: system
entry: pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
types: [python]
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ disable=print-statement,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
C0330,
R0801,

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
5 changes: 5 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[style]
based_on_style = pep8
dedent_closing_brackets = true
each_dict_entry_on_separate_line = true
column_limit = 100
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.linting.enabled": true,
"python.linting.pylintPath": "pylint",
"editor.formatOnSave": true,
"python.formatting.provider": "yapf",
"python.linting.pylintEnabled": true,
}
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ name = "pypi"

[packages] # Packages required to run the application
requests = "==2.23.0"
pre-commit = "==2.10.1"

[dev-packages] # Packages required to develop the application
coverage = "==5.0.3"
pylint = "==2.4.4"
pylint = "==2.6.0"
responses = "==0.10.12"
flit = "==2.2.0"
azure-identity = "==1.5.0"
isort = "==5.7.0"
yapf = "==0.30.0"
mypy = "==0.800"
344 changes: 268 additions & 76 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![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)

## Microsoft Graph Python Client Library

The Microsoft Graph Python client library is a lightweight wrapper around
Expand Down
8 changes: 2 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

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


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
extensions = []

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


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand All @@ -52,4 +48,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
1 change: 1 addition & 0 deletions msgraphcore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""msgraph-core"""

from msgraphcore.graph_session import GraphSession

from .constants import SDK_VERSION

__version__ = SDK_VERSION
25 changes: 15 additions & 10 deletions msgraphcore/graph_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from requests import Session

from msgraphcore.constants import BASE_URL, SDK_VERSION
from msgraphcore.middleware.middleware import MiddlewarePipeline, BaseMiddleware
from msgraphcore.middleware.abc_token_credential import TokenCredential
from msgraphcore.middleware.authorization import AuthorizationHandler
from msgraphcore.middleware.middleware import BaseMiddleware, MiddlewarePipeline
from msgraphcore.middleware.options.middleware_control import middleware_control


Expand All @@ -15,12 +15,13 @@ class GraphSession(Session):

Extends Session by adding support for middleware options and middleware pipeline
"""
def __init__(self,
credential: TokenCredential,
scopes: [str] = ['.default'],
middleware: list = [],
api_version: str = 'v1.0'
):
def __init__(
self,
credential: TokenCredential,
scopes: [str] = ['.default'],
middleware: list = [],
api_version: str = 'v1.0'
):
super().__init__()
self._append_sdk_version()
self._base_url = BASE_URL + '/' + api_version
Expand Down Expand Up @@ -94,7 +95,7 @@ def _graph_url(self, url: str) -> str:
:param url: user provided path
:return: graph_url
"""
return self._base_url+url if (url[0] == '/') else url
return self._base_url + url if (url[0] == '/') else url

def _register(self, middleware: [BaseMiddleware]) -> None:
"""Adds middleware to middleware_pipeline
Expand All @@ -113,7 +114,11 @@ def _append_sdk_version(self) -> None:
"""Updates sdkVersion in headers with comma-separated new values
"""
if 'sdkVersion' in self.headers:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION + ', '
+ self.headers.get('sdkVersion')})
self.headers.update(
{
'sdkVersion':
'graph-python-' + SDK_VERSION + ', ' + self.headers.get('sdkVersion')
}
)
else:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
1 change: 0 additions & 1 deletion msgraphcore/middleware/abc_token_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ class TokenCredential(ABC):
@abstractmethod
def get_token(self, *scopes, **kwargs):
pass

3 changes: 2 additions & 1 deletion msgraphcore/middleware/authorization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS

from .abc_token_credential import TokenCredential
from ..constants import AUTH_MIDDLEWARE_OPTIONS
from .middleware import BaseMiddleware
from .options.middleware_control import middleware_control

Expand Down
2 changes: 1 addition & 1 deletion msgraphcore/middleware/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ssl
from urllib3 import PoolManager

from requests.adapters import HTTPAdapter
from urllib3 import PoolManager


class MiddlewarePipeline(HTTPAdapter):
Expand Down
1 change: 0 additions & 1 deletion msgraphcore/middleware/options/auth_middleware_options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class AuthMiddlewareOptions:
def __init__(self, scopes: [str]):
self.scopes = scopes
4 changes: 3 additions & 1 deletion msgraphcore/middleware/options/middleware_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS
from ..options.auth_middleware_options import AuthMiddlewareOptions

from .auth_middleware_options import AuthMiddlewareOptions


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

return wrapper

def _reset_middleware_options(self):
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
files=msgraphcore
ignore_missing_imports=true
14 changes: 7 additions & 7 deletions samples/samples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from pprint import pprint

from azure.identity import InteractiveBrowserCredential

from msgraphcore import GraphSession

scopes = ['user.read']
Expand All @@ -16,13 +18,12 @@ def post_sample():
'contentType': 'Text',
'content': 'The new cafeteria is open.'
},
'toRecipients': [
{
'emailAddress': {
'address': 'ENTER_RECEPIENT_EMAIL_ADDRESS'
}
'toRecipients': [{
'emailAddress': {
'address': 'ENTER_RECEPIENT_EMAIL_ADDRESS'
}
]}
}]
}
}

result = graph_session \
Expand All @@ -42,4 +43,3 @@ def get_sample():
if __name__ == '__main__':
post_sample()
get_sample()

7 changes: 3 additions & 4 deletions tests/integration/test_middleware_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

class MiddlewarePipelineTest(TestCase):
def setUp(self):
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
warnings.filterwarnings(
"ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>"
)

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



4 changes: 1 addition & 3 deletions tests/unit/test_auth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from msgraphcore.constants import AUTH_MIDDLEWARE_OPTIONS
from msgraphcore.middleware.authorization import AuthorizationHandler
from msgraphcore.middleware.options.middleware_control import middleware_control
from msgraphcore.middleware.options.auth_middleware_options import AuthMiddlewareOptions
from msgraphcore.middleware.options.middleware_control import middleware_control


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

self.assertEqual(auth_handler.scopes, default_scopes)


9 changes: 5 additions & 4 deletions tests/unit/test_graph_session.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from unittest import TestCase

import responses
from requests import Session
from requests.adapters import HTTPAdapter
import responses

from msgraphcore.graph_session import GraphSession
from msgraphcore.constants import BASE_URL, SDK_VERSION
from msgraphcore.graph_session import GraphSession


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

def test_updated_sdk_version(self):
self.assertTrue(self.requests.headers.get('sdkVersion')
.startswith('graph-python-'+SDK_VERSION))
self.assertTrue(
self.requests.headers.get('sdkVersion').startswith('graph-python-' + SDK_VERSION)
)

def test_initialized_with_middlewares(self):
graph_session = GraphSession(self.credential)
Expand Down
Loading