Skip to content

Commit 6b4aad2

Browse files
committed
move version and update user agent with client name and version
1 parent 155ac83 commit 6b4aad2

File tree

9 files changed

+30
-13
lines changed

9 files changed

+30
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ gh-docs:
3737
release:
3838
@[ $(TAG) ] || exit 1
3939
@[ $(BODY) ] || exit 1
40-
@sed -i -e "s/__version__ =.*/__version__ = '$(TAG)'/" planet/api/__init__.py
40+
@sed -i -e "s/__version__ =.*/__version__ = '$(TAG)'/" planet/api/__version__.py
4141
git --no-pager diff
4242
@echo 'About to tag/release $(TAG)'
4343
@echo -n 'Does the above diff look right (Y/N)? :'

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
import shlex
1818

19-
from planet import api
19+
from planet.api.__version__ import __version__
2020

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

6969
# The language for content autogenerated by Sphinx. Refer to documentation
7070
# for a list of supported languages.

planet/api/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from .utils import write_to_file
2020
from . import filters
2121

22-
__version__ = '1.0.1'
23-
2422
__all__ = [
2523
ClientV1, APIException, BadQuery, InvalidAPIKey,
2624
NoPermission, MissingResource, OverQuota, ServerError, RequestCancelled,

planet/api/__version__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.1'

planet/api/dispatch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from . models import Response
2525
from . exceptions import InvalidAPIKey
2626
from . exceptions import TooManyRequests
27+
from . __version__ import __version__
2728
from requests.compat import urlparse
2829

2930

@@ -92,6 +93,10 @@ def rebuild_auth(self, prepared_request, response):
9293
)
9394

9495

96+
def _get_user_agent():
97+
return 'planet-python-client/%s' % __version__
98+
99+
95100
def _headers(request):
96101
headers = {}
97102
if request.data:
@@ -131,6 +136,7 @@ class RequestsDispatcher(object):
131136
def __init__(self, workers=4):
132137
# general session for sync api calls
133138
self.session = RedirectSession()
139+
self.session.headers.update({'User-Agent': _get_user_agent()})
134140
# ensure all calls to the session are throttled
135141
self.session.request = _Throttler().wrap(self.session.request)
136142
# the asyncpool is reserved for long-running async tasks

planet/scripts/cli.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sys
1818

1919
from planet import api
20+
from planet.api.__version__ import __version__
2021
from planet.api.utils import write_planet_json
2122
from .util import call_and_wrap
2223

@@ -37,8 +38,17 @@ def configure_logging(verbosity):
3738
)
3839

3940
urllib3_logger = logging.getLogger(
40-
'requests.packages.urllib3.connectionpool')
41-
urllib3_logger.setLevel(logging.CRITICAL)
41+
'requests.packages.urllib3')
42+
urllib3_logger.setLevel(log_level)
43+
44+
# if debug level set then its nice to see the headers of the request
45+
if log_level == logging.DEBUG:
46+
try:
47+
import http.client as http_client
48+
except ImportError:
49+
# Python 2
50+
import httplib as http_client
51+
http_client.HTTPConnection.debuglevel = 1
4252

4353

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

planet/scripts/item_asset_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
from planet.api.dispatch import _get_user_agent
23

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

3334

3435
def _get_json_or_raise(url, timeout=0.7):
35-
resp = requests.get(url, timeout=timeout)
36+
headers = {'User-Agent': _get_user_agent()}
37+
resp = requests.get(url, timeout=timeout, headers=headers)
3638
resp.raise_for_status()
3739
return resp.json()
3840

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
long_description = ''
2626

2727

28-
with open('planet/api/__init__.py') as f:
28+
with open('planet/api/__version__.py') as f:
2929
for line in f:
3030
if line.find("__version__") >= 0:
3131
version = line.split("=")[1].strip()

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
from mock import MagicMock
3535

36-
import planet
3736
from planet import api
37+
from planet.api.__version__ import __version__
3838
from planet.scripts import util
3939
from planet.scripts import main
4040
from planet.scripts import cli
@@ -122,7 +122,7 @@ def test_exception_translation():
122122

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

127127

128128
def test_workers_flag():

0 commit comments

Comments
 (0)