Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gh-docs:
release:
@[ $(TAG) ] || exit 1
@[ $(BODY) ] || exit 1
@sed -i -e "s/__version__ =.*/__version__ = '$(TAG)'/" planet/api/__init__.py
@sed -i -e "s/__version__ =.*/__version__ = '$(TAG)'/" planet/api/__version__.py
git --no-pager diff
@echo 'About to tag/release $(TAG)'
@echo -n 'Does the above diff look right (Y/N)? :'
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import shlex

from planet import api
from planet.api.__version__ import __version__

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -62,9 +62,9 @@
# built documents.
#
# The short X.Y version.
version = api.__version__
version = __version__
# The full version, including alpha/beta/rc tags.
release = api.__version__
release = __version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 0 additions & 2 deletions planet/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from .utils import write_to_file
from . import filters

__version__ = '1.0.1'

__all__ = [
ClientV1, APIException, BadQuery, InvalidAPIKey,
NoPermission, MissingResource, OverQuota, ServerError, RequestCancelled,
Expand Down
1 change: 1 addition & 0 deletions planet/api/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '1.0.1'
6 changes: 6 additions & 0 deletions planet/api/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . models import Response
from . exceptions import InvalidAPIKey
from . exceptions import TooManyRequests
from . __version__ import __version__
from requests.compat import urlparse


Expand Down Expand Up @@ -92,6 +93,10 @@ def rebuild_auth(self, prepared_request, response):
)


def _get_user_agent():
return 'planet-client-python/%s' % __version__


def _headers(request):
headers = {}
if request.data:
Expand Down Expand Up @@ -131,6 +136,7 @@ class RequestsDispatcher(object):
def __init__(self, workers=4):
# general session for sync api calls
self.session = RedirectSession()
self.session.headers.update({'User-Agent': _get_user_agent()})
# ensure all calls to the session are throttled
self.session.request = _Throttler().wrap(self.session.request)
# the asyncpool is reserved for long-running async tasks
Expand Down
16 changes: 13 additions & 3 deletions planet/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys

from planet import api
from planet.api.__version__ import __version__
from planet.api.utils import write_planet_json
from .util import call_and_wrap

Expand All @@ -37,8 +38,17 @@ def configure_logging(verbosity):
)

urllib3_logger = logging.getLogger(
'requests.packages.urllib3.connectionpool')
urllib3_logger.setLevel(logging.CRITICAL)
'requests.packages.urllib3')
urllib3_logger.setLevel(log_level)

# if debug level set then its nice to see the headers of the request
if log_level == logging.DEBUG:
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1


@click.group()
Expand All @@ -52,7 +62,7 @@ def configure_logging(verbosity):
@click.option('-u', '--base-url', envvar='PL_API_BASE_URL',
help='Change the base Planet API URL or ENV PL_API_BASE_URL'
' - Default https://api.planet.com/')
@click.version_option(version=api.__version__, message='%(version)s')
@click.version_option(version=__version__, message='%(version)s')
def cli(context, verbose, api_key, base_url, workers):
'''Planet API Client'''

Expand Down
4 changes: 3 additions & 1 deletion planet/scripts/item_asset_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
from planet.api.dispatch import _get_user_agent

ITEM_TYPE_URL = 'https://api.planet.com/data/v1/item-types/'
ASSET_TYPE_URL = 'https://api.planet.com/data/v1/asset-types/'
Expand Down Expand Up @@ -32,7 +33,8 @@


def _get_json_or_raise(url, timeout=0.7):
resp = requests.get(url, timeout=timeout)
headers = {'User-Agent': _get_user_agent()}
resp = requests.get(url, timeout=timeout, headers=headers)
resp.raise_for_status()
return resp.json()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
long_description = ''


with open('planet/api/__init__.py') as f:
with open('planet/api/__version__.py') as f:
for line in f:
if line.find("__version__") >= 0:
version = line.split("=")[1].strip()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

from mock import MagicMock

import planet
from planet import api
from planet.api.__version__ import __version__
from planet.scripts import util
from planet.scripts import main
from planet.scripts import cli
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_exception_translation():

def test_version_flag():
results = run_cli(['--version'])
assert results.output == "%s\n" % planet.api.__version__
assert results.output == "%s\n" % __version__


def test_workers_flag():
Expand Down