Skip to content

Commit

Permalink
Merge pull request #68 from gene1wood/release-2.2.1
Browse files Browse the repository at this point in the history
Release 2.2.1
  • Loading branch information
gene1wood authored Oct 8, 2019
2 parents 8d5ef2d + 31b0d6b commit 86ef503
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# http://krlmlr.github.io/using-gitattributes-to-avoid-merge-conflicts/
/CHANGELOG.md merge=union
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
tags
*.py[co]
.*
MANIFEST
dist/*
agithub.egg-info/
build/
dist/
.tox
.eggs
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: python
python:
- '3.7'
- '2.7'

install: pip install -U tox-travis
script: tox
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.2.1] - 2019-10-07
### Added
* Mozilla code of conduct
* Long description to setup.py containing README
* End to end GitHub unit test and tox testing with pytest
* Integration with Travis CI

### Changed
* Moved to SCM (git) driven version instead of a hard coded one
* VERSION constant from semver list (e.g. [2, 2, 1]) to string version (e.g. 2.2.1)

### Removed
* mock module to avoid collision with builtin mock module
* STR_VERSION constant

### Fixed
* TypeError when paginate is `True` and `sleep_on_ratelimit` is the default (#66 by [@huma23](https://github.com/huma23))

## [2.2.0] - 2019-01-16
### Added
* GitHub pagination support, which can be enabled
Expand Down Expand Up @@ -71,7 +89,8 @@ contributed!)
* Has a version number. (Yippie!)
* First more-or-less stable version

[Unreleased]: https://github.com/mozilla/agithub/compare/v2.2.0...HEAD
[Unreleased]: https://github.com/mozilla/agithub/compare/v2.2.1...HEAD
[2.2.1]: https://github.com/mozilla/agithub/compare/v2.2.0...v2.2.1
[2.2.0]: https://github.com/mozilla/agithub/compare/v2.1...v2.2.0
[2.1]: https://github.com/mozilla/agithub/compare/v2.0...v2.1
[2.0]: https://github.com/mozilla/agithub/compare/v1.3...v2.0
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,4 @@ become an expert on the code. From there, anything's possible.

## License
Copyright 2012–2016 Jonathan Paugh and contributors
See [COPYING][LIC] for license details
[LIC]: COPYING
See [COPYING](COPYING) for license details
17 changes: 11 additions & 6 deletions agithub/GitHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import re
import logging

from agithub.base import API, ConnectionProperties, Client, RequestBody, ResponseBody
from agithub.base import (
API, ConnectionProperties, Client, RequestBody, ResponseBody)

logger = logging.getLogger(__name__)


class GitHub(API):
"""
The agnostic GitHub API. It doesn't know, and you don't care.
Expand Down Expand Up @@ -92,7 +94,7 @@ def request(self, method, url, bodyData, headers):
if 'content-type' in headers:
del headers['content-type']

#TODO: Context manager
# TODO: Context manager
requestBody = RequestBody(bodyData, headers)

if self.sleep_on_ratelimit and self.no_ratelimit_remaining():
Expand All @@ -107,12 +109,14 @@ def request(self, method, url, bodyData, headers):
self.headers = response.getheaders()

conn.close()
if status == 403 and self.sleep_on_ratelimit and self.no_ratelimit_remaining():
if (status == 403 and self.sleep_on_ratelimit and
self.no_ratelimit_remaining()):
self.sleep_until_more_ratelimit()
else:
data = content.processBody()
if self.paginate and type(data) == list:
data.extend(self.get_additional_pages(method, bodyData, headers))
data.extend(
self.get_additional_pages(method, bodyData, headers))
return status, data

def get_additional_pages(self, method, bodyData, headers):
Expand Down Expand Up @@ -165,9 +169,10 @@ def get_next_link_url(self):
"""Given a set of HTTP headers find the RFC 5988 Link header field,
determine if it contains a relation type indicating a next resource and
if so return the URL of the next resource, otherwise return an empty
string."""
string.
# From https://github.com/requests/requests/blob/master/requests/utils.py
From https://github.com/requests/requests/blob/master/requests/utils.py
"""
for value in [x[1] for x in self.headers if x[0].lower() == 'link']:
replace_chars = ' \'"'
value = value.strip(replace_chars)
Expand Down
4 changes: 2 additions & 2 deletions agithub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from agithub.base import VERSION, STR_VERSION
from agithub.base import VERSION

__all__ = ["VERSION", "STR_VERSION"]
__all__ = ["VERSION"]
40 changes: 38 additions & 2 deletions agithub/agithub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
# See COPYING for license details
from agithub.GitHub import GitHub
from agithub.base import IncompleteRequest
import mock
import unittest


class Client(object):
http_methods = ('demo', 'test')

def __init__(self, username=None, password=None, token=None,
connection_properties=None):
pass

def setConnectionProperties(self, props):
pass

def demo(self, *args, **params):
return self.methodCalled('demo', *args, **params)

def test(self, *args, **params):
return self.methodCalled('test', *args, **params)

def methodCalled(self, methodName, *args, **params):
return {
'methodName': methodName,
'args': args,
'params': params
}


class TestGitHubObjectCreation(unittest.TestCase):
def test_user_pw(self):
gh = GitHub('korfuri', '1234')
Expand All @@ -30,7 +53,7 @@ def test_token_password(self):
class TestIncompleteRequest(unittest.TestCase):

def newIncompleteRequest(self):
return IncompleteRequest(mock.Client())
return IncompleteRequest(Client())

def test_pathByGetAttr(self):
rb = self.newIncompleteRequest()
Expand Down Expand Up @@ -64,5 +87,18 @@ def test_callMethodTest(self):
}
)


def test_github():
g = GitHub()
status, data = g.users.octocat.get()
assert data.get('name') == 'The Octocat'
assert status == 200
# Workaround to https://github.com/mozilla/agithub/issues/67
response_headers = dict([(x.lower(), y) for x, y in g.getheaders()])
assert (
response_headers.get('Content-Type'.lower()) ==
'application/json; charset=utf-8')


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions agithub/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See COPYING for license details
import json
from functools import partial, update_wrapper
from setuptools_scm import get_version

import sys
if sys.version_info[0:2] > (3, 0):
Expand All @@ -14,14 +15,13 @@
class ConnectionError(OSError):
pass

VERSION = [2, 1]
STR_VERSION = 'v' + '.'.join(str(v) for v in VERSION)
VERSION = get_version(root='..', relative_to=__file__)

# These headers are implicitly included in each request; however, each
# can be explicitly overridden by the client code. (Used in Client
# objects.)
_default_headers = {
'user-agent': 'agithub/' + STR_VERSION,
'user-agent': 'agithub/' + VERSION,
'content-type': 'application/json'
}

Expand Down
27 changes: 0 additions & 27 deletions agithub/mock.py

This file was deleted.

5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

21 changes: 18 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from setuptools import setup, find_packages
from os import path

version = '2.2.0'
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md')) as f:
long_description = f.read()

test_requirements = ['pytest']

extras = {
"test": test_requirements,
}

setup(name='agithub',
version=version,
description="A lightweight, transparent syntax for REST clients",
long_description=long_description,
long_description_content_type='text/markdown',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand All @@ -17,9 +27,14 @@
keywords=['api', 'REST', 'GitHub', 'Facebook', 'SalesForce'],
author='Jonathan Paugh',
author_email='[email protected]',
url='https://github.com/jpaugh/agithub',
url='https://github.com/mozilla/agithub',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
tests_require=test_requirements,
extras_require=extras,
setup_requires=['setuptools-scm'],
use_scm_version=True,
install_requires=['setuptools-scm'],
)
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tox]
envlist = py27, py37, flake8

[travis]
python =
3.7: py37
2.7: py27

[testenv:flake8]
basepython = python
deps = flake8
commands = flake8 agithub setup.py

[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps = .[test]
commands =
pytest {posargs}

0 comments on commit 86ef503

Please sign in to comment.