diff --git a/.travis.yml b/.travis.yml index d4de00a..556b2a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ cache: pip python: - "2.7" + - "3.5" + - "3.6" - "pypy" before_install: diff --git a/README.rst b/README.rst index 32756b9..0dfa70b 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,14 @@ Documentation is published on `ReadTheDocs `_. ####### Version ####### +**PyPexels v1.0.0b2 (beta, v2)** + + Second beta release introduces Python3 support. + + Note that using this library you still need to abide to Pexels Guidelines, which + are explained on `Pexels API page `_ + + **PyPexels v1.0.0b1 (beta, v1)** First release with wrappers around the two Pexels API for `search` and `popular`. diff --git a/docs/source/conf.py b/docs/source/conf.py index b857cb0..f5a03c3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -40,7 +40,8 @@ ] # autosummary_generate = False -# Boolean indicating whether to scan all found documents for autosummary directives, and to generate stub pages for each. +# Boolean indicating whether to scan all found documents for autosummary directives, +# and to generate stub pages for each. # Can also be a list of documents for which stub pages should be generated. # The new files will be placed in the directories specified in the :toctree: options of the directives. autosummary_generate = True @@ -135,10 +136,10 @@ # # html_theme = 'alabaster' # html_theme = 'classic' -html_theme = 'sphinxdoc' -html_theme = 'scrolls' -html_theme = 'agogo' -html_theme = 'nature' +# html_theme = 'sphinxdoc' +# html_theme = 'scrolls' +# html_theme = 'agogo' +# html_theme = 'nature' html_theme = 'sphinx_rtd_theme' diff --git a/docs/source/version.rst b/docs/source/version.rst index 9b837c4..722ae71 100644 --- a/docs/source/version.rst +++ b/docs/source/version.rst @@ -1,8 +1,8 @@ Version ======= -**PyPexels v1.0.0b1 (beta, v1)** +**PyPexels v1.0.0b2 (beta, v2)** - First release with wrappers around the two Pexels API for `search` and `popular`. + Second beta release introduces Python3 support. Note that using this library you still need to abide to Pexels Guidelines, which are explained on `Pexels API page `_ diff --git a/pypexels/__init__.py b/pypexels/__init__.py index 83d2d66..13f8cc6 100644 --- a/pypexels/__init__.py +++ b/pypexels/__init__.py @@ -11,14 +11,13 @@ # Comment: What's new in revision 1 # ############################################################################### - """An open source Python wrapper for the Unsplash REST API""" -from pypexels import PyPexels +from .pypexels import PyPexels # TRAVIS_BUILD_NUMBER # TRAVIS_COMMIT # TRAVIS_COMMIT_RANGE # TRAVIS_TAG -__version__ = '1.0.0b1' +__version__ = '1.0.0b2' __author__ = 'Salvatore Ventura ' __license__ = 'MIT' diff --git a/pypexels/src/pexelspage.py b/pypexels/src/pexelspage.py index 54bcc4c..cc54d64 100644 --- a/pypexels/src/pexelspage.py +++ b/pypexels/src/pexelspage.py @@ -120,7 +120,8 @@ def _sanitized_query_parameters(self, kwargs): return query_params def _parse_navigation(self): - nopaging_query_parameters = ['{}={}'.format(k, v) for k, v in self._query_parameters.items() if k not in ['page', 'per_page']] + nopaging_query_parameters = ['{}={}'.format(k, v) for k, v in self._query_parameters.items() if + k not in ['page', 'per_page']] self.nopaging_url = '?'.join([self._url, '&'.join(nopaging_query_parameters)]) self.page = int(self.body.get('page', 1)) self.per_page = int(self.body.get('per_page', 15)) @@ -131,7 +132,8 @@ def _parse_navigation(self): 'first': '%s&per_page=%s&page=%s' % (self.nopaging_url, self.per_page, 1), 'prev': self.body.get('prev_page', None), 'next': self.body.get('next_page', None), - 'last': '%s&per_page=%s&page=%s' % (self.nopaging_url, self.per_page, self.total_results/self.per_page + 1), + 'last': '%s&per_page=%s&page=%s' % ( + self.nopaging_url, self.per_page, self.total_results / self.per_page + 1), } def _ret_link(self, which): diff --git a/pypexels/src/popular.py b/pypexels/src/popular.py index 68a0eab..ad47484 100644 --- a/pypexels/src/popular.py +++ b/pypexels/src/popular.py @@ -20,13 +20,14 @@ class Popular(PexelsPage): - def __init__(self, api_key, url='/popular', api_version=API_VERSION, **kwargs): + def __init__(self, api_key, url='/popular', api_version=API_VERSION, **kwargs): if url.find('/popular') == -1: raise PexelsError('Invalid _url for class Popular(): %s' % url) valid_options = ['page', 'per_page'] - super(Popular, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, **kwargs) + super(Popular, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, + **kwargs) @property def entries(self): diff --git a/pypexels/src/rest.py b/pypexels/src/rest.py index 6e51792..2cf3ef0 100644 --- a/pypexels/src/rest.py +++ b/pypexels/src/rest.py @@ -67,7 +67,8 @@ def _request(self, url, method, query_params=None, data=None, **kwargs): logger.debug('Wiring REST %s %s %s %s', method, req_url, query_params, data) try: - response = requests.request(method, req_url, params=query_params, data=data, headers=self.req_headers, **kwargs) + response = requests.request(method, req_url, params=query_params, data=data, headers=self.req_headers, + **kwargs) except Exception as e: raise PexelsError("Connection error: %s" % e) @@ -80,7 +81,7 @@ def _request(self, url, method, query_params=None, data=None, **kwargs): 'HTTP status %s: %s', self._status_code, self._body.get('errors', ['No error message']) ) - except ValueError, e: + except ValueError as e: logger.error('EXCEPTION: %s', e) if self._status_code != requests.codes.ok: logger.error('HTTP EXC status %s: %s', self._status_code, response.text) diff --git a/pypexels/src/search.py b/pypexels/src/search.py index 37a3201..fe489b2 100644 --- a/pypexels/src/search.py +++ b/pypexels/src/search.py @@ -29,7 +29,8 @@ def __init__(self, api_key, url='/search', api_version=API_VERSION, **kwargs): raise PexelsError('Parameter "query" is mandatory for class Search()') valid_options = ['page', 'per_page', 'query'] - super(Search, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, **kwargs) + super(Search, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, + **kwargs) @property def entries(self): diff --git a/pypexels/tests/test_popular.py b/pypexels/tests/test_popular.py index 8442df4..cde4450 100644 --- a/pypexels/tests/test_popular.py +++ b/pypexels/tests/test_popular.py @@ -11,6 +11,7 @@ # Comment: What's new in revision 1 # ############################################################################### +from __future__ import print_function import responses import json import os @@ -29,7 +30,8 @@ class TestPopular: root_path = os.environ.get('TRAVIS_BUILD_DIR', None) or os.environ.get('TOXINIDIR', None) store_mapping = { - 'popular': os.sep.join([root_path, 'pypexels', 'tests', 'resources', 'resource__popular_per_page_5_page_2.json']), + 'popular': os.sep.join( + [root_path, 'pypexels', 'tests', 'resources', 'resource__popular_per_page_5_page_2.json']), } @responses.activate @@ -40,7 +42,8 @@ def test_popular(self): responses.add( responses.GET, - '{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), # _url contains only the short path like /popular?page=2&per_page=5 + '{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), + # _url contains only the short path like /popular?page=2&per_page=5 json=stored_response.get('body'), status=stored_response.get('status_code'), content_type='application/json', @@ -51,17 +54,17 @@ def test_popular(self): popular_results_page = py_pexels.popular(page=2, per_page=5) # Page properties - print popular_results_page.page - print popular_results_page.per_page - print popular_results_page.has_next - print popular_results_page.has_previous - print popular_results_page.link_self - print popular_results_page.link_first - print popular_results_page.link_last - print popular_results_page.link_next - print popular_results_page.link_previous + print(popular_results_page.page) + print(popular_results_page.per_page) + print(popular_results_page.has_next) + print(popular_results_page.has_previous) + print(popular_results_page.link_self) + print(popular_results_page.link_first) + print(popular_results_page.link_last) + print(popular_results_page.link_next) + print(popular_results_page.link_previous) # Entries for photo in popular_results_page.entries: - print photo.id, photo.photographer, photo.width, photo.height, photo.url - print photo.src + print(photo.id, photo.photographer, photo.width, photo.height, photo.url) + print(photo.src) diff --git a/pypexels/tests/test_search.py b/pypexels/tests/test_search.py index c07be07..0b80453 100644 --- a/pypexels/tests/test_search.py +++ b/pypexels/tests/test_search.py @@ -11,6 +11,7 @@ # Comment: What's new in revision 1 # ############################################################################### +from __future__ import print_function import responses import json import os @@ -29,7 +30,8 @@ class TestSearch: root_path = os.environ.get('TRAVIS_BUILD_DIR', None) or os.environ.get('TOXINIDIR', None) store_mapping = { - 'redflower': os.sep.join([root_path, 'pypexels', 'tests', 'resources', 'resource__search_per_page_5_page_2_query_red_flower.json']), + 'redflower': os.sep.join( + [root_path, 'pypexels', 'tests', 'resources', 'resource__search_per_page_5_page_2_query_red_flower.json']), } @responses.activate @@ -40,7 +42,8 @@ def test_search(self): responses.add( responses.GET, - '{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), # _url contains only the short path like /popular?page=2&per_page=5 + '{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), + # _url contains only the short path like /popular?page=2&per_page=5 json=stored_response.get('body'), status=stored_response.get('status_code'), content_type='application/json', @@ -51,17 +54,17 @@ def test_search(self): search_results_page = py_pexels.search(query='red flower', page=2, per_page=5) # Page properties - print search_results_page.page - print search_results_page.per_page - print search_results_page.has_next - print search_results_page.has_previous - print search_results_page.link_self - print search_results_page.link_first - print search_results_page.link_last - print search_results_page.link_next - print search_results_page.link_previous + print(search_results_page.page) + print(search_results_page.per_page) + print(search_results_page.has_next) + print(search_results_page.has_previous) + print(search_results_page.link_self) + print(search_results_page.link_first) + print(search_results_page.link_last) + print(search_results_page.link_next) + print(search_results_page.link_previous) # Entries for photo in search_results_page.entries: - print photo.id, photo.photographer, photo.width, photo.height, photo.url - print photo.src + print(photo.id, photo.photographer, photo.width, photo.height, photo.url) + print(photo.src) diff --git a/setup.py b/setup.py index 49d49f7..76a6c64 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='pypexels', - version='1.0.0b1', + version='1.0.0b2', packages=['pypexels', 'pypexels.src'], url='https://github.com/salvoventura/pypexels', license='MIT', @@ -25,10 +25,13 @@ # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 2.7' + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ], keywords=['pexels', 'rest', 'api', 'python', 'wrapper', 'development', 'pexels.com', 'photography'], install_requires=['requests'], - python_requires='>=2.7, <3' + python_requires='>=2.7' ) diff --git a/tox.ini b/tox.ini index e3955d3..add5ed2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27 +envlist = py27,py35,py36 [testenv] deps =