From 708eb267461fe379a7a34c676a30b256b760ddbb Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 14:34:57 -0600 Subject: [PATCH 1/7] Style: Moved docstring to bottom of file --- tests/test_methods.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_methods.py b/tests/test_methods.py index 06cf808..3fc8463 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -18,8 +18,7 @@ def test_client_methods_are_lower_case(self): pass # ignore non-class attributes def test_method_has_doc_string(self): - assert Octokit( - ).oauth_authorizations.list_grants.__doc__ == """You can use this API to list the set of OAuth applications that have been granted access to your account. Unlike the [list your authorizations](https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations) API, this API does not manage individual tokens. This API will return one entry for each OAuth application that has been granted access to your account, regardless of the number of tokens an application has generated for your user. The list of OAuth applications returned matches what is shown on [the application authorizations settings screen within GitHub](https://github.com/settings/applications#authorized). The `scopes` returned are the union of scopes authorized for the application. For example, if an application has one token with `repo` scope and another token with `user` scope, the grant will return `[\"repo\", \"user\"]`.""" # noqa E501 + assert Octokit().oauth_authorizations.list_grants.__doc__ == self.doc_string def test_method_has_name_string(self): assert Octokit().oauth_authorizations.list_grants.__name__ == 'list_grants' @@ -261,3 +260,7 @@ def test_dictionary_keys_are_validated(self, mocker): data=json.dumps(data, sort_keys=True), headers=headers ) + + @property + def doc_string(self): + return """You can use this API to list the set of OAuth applications that have been granted access to your account. Unlike the [list your authorizations](https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations) API, this API does not manage individual tokens. This API will return one entry for each OAuth application that has been granted access to your account, regardless of the number of tokens an application has generated for your user. The list of OAuth applications returned matches what is shown on [the application authorizations settings screen within GitHub](https://github.com/settings/applications#authorized). The `scopes` returned are the union of scopes authorized for the application. For example, if an application has one token with `repo` scope and another token with `user` scope, the grant will return `[\"repo\", \"user\"]`.""" # noqa E501 From 7fa46f114a9f88fd9cae90cbe7999d470961b770 Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 14:39:03 -0600 Subject: [PATCH 2/7] Dependency: routes data from an egg --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e8bfeb3..94711ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ python-jose==3.0.1 requests==2.21.0 +octokitpy-routes==0.0.5 From ff6203be278a24efd0f37232e9c92eb31c8a4933 Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 14:39:28 -0600 Subject: [PATCH 3/7] Feature: Use route data Data is updated from @octokit/routes -> npm -> octokitpy-routes -> pypi --- src/octokit/__init__.py | 3 ++- tests/test_octokit.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/octokit/__init__.py b/src/octokit/__init__.py index ed30d66..dc7fd9c 100644 --- a/src/octokit/__init__.py +++ b/src/octokit/__init__.py @@ -9,6 +9,7 @@ from jose import jwt from octokit import errors from octokit import utils +from routes import specifications page_regex = re.compile(r'[\?\&]page=(\d+)[_&=\w\d]*>; rel="(\w+)"') @@ -164,7 +165,7 @@ class Octokit(Base): def __init__(self, *args, **kwargs): super().__init__() - self._create(utils.get_json_data('index.json')) + self._create(specifications[kwargs.get('routes', 'api.github.com')]) self._setup_authentication(kwargs) self._attribute_cache = defaultdict(dict) diff --git a/tests/test_octokit.py b/tests/test_octokit.py index eb69a57..a629370 100644 --- a/tests/test_octokit.py +++ b/tests/test_octokit.py @@ -47,3 +47,12 @@ def test_pagination(self): assert next(p) == {'page': 2, 'kwargs': {'param': 'value'}} assert next(p) == {'page': 3, 'kwargs': {'param': 'value'}} assert next(p) == {'page': 4, 'kwargs': {'param': 'value'}} + + def test_can_speficy_the_route_specifications_used(self): + from octokit import Octokit + octokit = Octokit(routes='ghe-2.15') + assert '/enterprise/2.15' in octokit.issues.create.__doc__ + octokit = Octokit() + assert '/developer.github.com' in octokit.issues.create.__doc__ + octokit = Octokit(routes='api.github.com') + assert '/developer.github.com' in octokit.issues.create.__doc__ From 7c9519c7feb4107a3b9fd17388586b8b14ede50e Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 14:41:20 -0600 Subject: [PATCH 4/7] Version: 0.10.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f165332..84d1ff9 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def read(*names, **kwargs): setup( name='octokitpy', - version='0.9.2', + version='0.10.0', license='MIT license', description='Python client for GitHub API', long_description='%s\n%s' % ( From 6cac70edd7abf6edf15eae9cb93d3a60e9be215c Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 14:47:07 -0600 Subject: [PATCH 5/7] Doc: Add specification selection --- README.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 10116b4..20b9140 100644 --- a/README.rst +++ b/README.rst @@ -133,6 +133,11 @@ For applications provide the application id either from the ping webhook or the The :code:`private_key` is a string of your private key provided for the application. The :code:`app` scheme will use the application id and private key to get a token for the first installation id of the application. +API Schema/Routes/Specifications +-------------------------------- + +One can instantiate the ``Octokit`` with ``routes=specification`` where the ``specification`` is one of ``api.github.com``, ``ghe-2.15``, etc. + TODOs =========== @@ -158,7 +163,7 @@ The :code:`octokit` client based on the available `route data Date: Wed, 2 Jan 2019 15:23:34 -0600 Subject: [PATCH 6/7] Refactor: Drop python 3.4 support --- .travis.yml | 6 +++--- README.rst | 2 +- tox.ini | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 36073ee..59f53df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,15 +12,15 @@ env: - TOXENV=docs matrix: include: + - python: '3.7' + env: + - TOXENV=py37 - python: '3.6' env: - TOXENV=py36 - python: '3.5' env: - TOXENV=py35 - - python: '3.4' - env: - - TOXENV=py34 before_install: - python --version - uname -a diff --git a/README.rst b/README.rst index 20b9140..9b60903 100644 --- a/README.rst +++ b/README.rst @@ -57,7 +57,7 @@ Python client for GitHub API Installation ============ -**requires python 3.4+** +**requires python 3.5+** Yes that is opinionated. Python 2 is near the end of the life and this is a new project. diff --git a/tox.ini b/tox.ini index 477460b..b878b1b 100644 --- a/tox.ini +++ b/tox.ini @@ -3,14 +3,14 @@ [tox] envlist = check, - {py36,py35,py34}, + {py37,py36,py35}, docs [testenv] basepython = + py37: {env:TOXPYTHON:python3.7} py36: {env:TOXPYTHON:python3.6} py35: {env:TOXPYTHON:python3.5} - py34: {env:TOXPYTHON:python3.4} {bootstrap,check,docs}: {env:TOXPYTHON:python3} setenv = PYTHONPATH={toxinidir}/tests From 14d8f987bf41f204bc7175ed391c6ff37ccce15c Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Wed, 2 Jan 2019 16:32:56 -0600 Subject: [PATCH 7/7] Peripheral: Try different dist --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 59f53df..98510c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: python +dist: xenial python: - '3.6' sudo: false