Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 29ec3ed

Browse files
committedApr 28, 2019
refactor(*): Removing code from setup.py and add dedicated config module
1 parent 8a02bea commit 29ec3ed

17 files changed

+74
-102
lines changed
 

‎README.md

+23-25
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Shippo is a shipping API that connects you with [multiple shipping carriers](htt
77

88
Print a shipping label in 10 mins using our default USPS and DHL Express accounts. No need to register for a carrier account to get started.
99

10-
You will first need to [register for a Shippo account](https://goshippo.com/) to use our API. It's free to sign up, free to use the API. Only pay to print a live label, test labels are free.
10+
You will first need to [register for a Shippo account](https://goshippo.com/) to use our API. It's free to sign up, free to use the API. Only pay to print a live label, test labels are free.
1111

12-
### How do I get set up? ###
12+
### How do I get set up?
1313

1414
#### To install from the source file:
1515

@@ -19,10 +19,11 @@ python setup.py install
1919
```
2020

2121
or pip (https://pip.pypa.io/en/latest/index.html):
22+
2223
```
2324
#!shell
2425
sudo pip install shippo
25-
```
26+
```
2627

2728
#### To test:
2829

@@ -38,7 +39,6 @@ Run the test with the following command:
3839
python setup.py test --test-suite=shippo
3940
```
4041

41-
4242
#### Dependencies:
4343

4444
##### requests & mock
@@ -47,14 +47,14 @@ python setup.py test --test-suite=shippo
4747
#!shell
4848
sudo easy_install requests
4949
sudo easy_install mock
50-
```
50+
```
5151

5252
#### Using the API:
5353

5454
```python
5555

5656
import shippo
57-
shippo.api_key = "<API-KEY>"
57+
shippo.config.api_key = "shippo_test_d90f00698a0a8def0495fddb4212bb08051469d3"
5858

5959
address1 = shippo.Address.create(
6060
name='John Smith',
@@ -76,13 +76,12 @@ print 'Success with Address 1 : %r' % (address1, )
7676
We've created a number of examples to cover the most common use cases. You can find the sample code files in the [examples folder](examples/).
7777
Some of the use cases we covered include:
7878

79-
* [Basic domestic shipment](examples/basic-shipment.py)
80-
* [International shipment](examples/international-shipment.py) - Custom forms, interntational destinations
81-
* [Price estimation matrix](examples/estimate-shipping-prices.py)
82-
* [Retrieve rates, filter by delivery time and purchase cheapest label](examples/filter-by-delivery-time.py)
83-
* [Retrieve rates, purchase label for fastest delivery option](examples/purchase-fastest-service.py)
84-
* [Retrieve rates so customer can pick preferred shipping method, purchase label](examples/get-rates-to-show-customer.py)
85-
79+
- [Basic domestic shipment](examples/basic-shipment.py)
80+
- [International shipment](examples/international-shipment.py) - Custom forms, interntational destinations
81+
- [Price estimation matrix](examples/estimate-shipping-prices.py)
82+
- [Retrieve rates, filter by delivery time and purchase cheapest label](examples/filter-by-delivery-time.py)
83+
- [Retrieve rates, purchase label for fastest delivery option](examples/purchase-fastest-service.py)
84+
- [Retrieve rates so customer can pick preferred shipping method, purchase label](examples/get-rates-to-show-customer.py)
8685

8786
## Documentation
8887

@@ -96,15 +95,14 @@ Connect with multiple different carriers, get discounted shipping labels, track
9695

9796
The Shippo API provides in depth support of carrier and shipping functionalities. Here are just some of the features we support through the API:
9897

99-
* Shipping rates & labels - [Docs](https://goshippo.com/docs/first-shipment)
100-
* Tracking for any shipment with just the tracking number - [Docs](https://goshippo.com/docs/tracking)
101-
* Batch label generation - [Docs](https://goshippo.com/docs/batch)
102-
* Multi-piece shipments - [Docs](https://goshippo.com/docs/multipiece)
103-
* Manifests and SCAN forms - [Docs](https://goshippo.com/docs/manifests)
104-
* Customs declaration and commercial invoicing - [Docs](https://goshippo.com/docs/international)
105-
* Address verification - [Docs](https://goshippo.com/docs/address-validation)
106-
* Consolidator support including:
107-
* DHL eCommerce
108-
* UPS Mail Innovations
109-
* FedEx Smartpost
110-
* Additional services: cash-on-delivery, certified mail, delivery confirmation, and more - [Docs](https://goshippo.com/docs/reference#shipment-extras)
98+
- Shipping rates & labels - [Docs](https://goshippo.com/docs/first-shipment)
99+
- Tracking for any shipment with just the tracking number - [Docs](https://goshippo.com/docs/tracking)
100+
- Batch label generation - [Docs](https://goshippo.com/docs/batch)
101+
- Multi-piece shipments - [Docs](https://goshippo.com/docs/multipiece)
102+
- Manifests and SCAN forms - [Docs](https://goshippo.com/docs/manifests)
103+
- Customs declaration and commercial invoicing - [Docs](https://goshippo.com/docs/international)
104+
- Address verification - [Docs](https://goshippo.com/docs/address-validation)
105+
- Consolidator support including:
106+
_ DHL eCommerce
107+
_ UPS Mail Innovations \* FedEx Smartpost
108+
- Additional services: cash-on-delivery, certified mail, delivery confirmation, and more - [Docs](https://goshippo.com/docs/reference#shipment-extras)

‎examples/basic-shipment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
# Replace <API-KEY> with your key
9-
shippo.api_key = "<API-KEY>"
9+
shippo.config.api_key = "<API-KEY>"
1010

1111
# Example address_from object dict
1212
# The complete refence for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/batch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
# Replace <API-KEY> with your key
9-
shippo.api_key = "<API-KEY>"
9+
shippo.config.api_key = "<API-KEY>"
1010

1111
example_batch = {
1212
# replace with your carrier account

‎examples/estimate-shipping-prices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
DESTINATION_ADDRESSES_ZIP_CODES = [10007, 60290, 95122]
3636

3737
# replace <API-KEY> with your key
38-
shippo.api_key = "<API-KEY>"
38+
shippo.config.api_key = "<API-KEY>"
3939

4040
# sample address_from
4141
# The complete refence for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/filter-by-delivery-time.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
MAX_TRANSIT_TIME_DAYS = 3
1414

1515
# Replace <API-KEY> with your key
16-
shippo.api_key = "<API-KEY>"
16+
shippo.config.api_key = "<API-KEY>"
1717

1818
# Example address_from object dict
1919
# The complete refence for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/get-rates-to-show-customer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
MAX_TRANSIT_TIME_DAYS = 3
1212

1313
# replace <API-KEY> with your key
14-
shippo.api_key = "<API-KEY>"
14+
shippo.config.api_key = "<API-KEY>"
1515

1616
# Example address_from object dict
1717
# The complete refence for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/international-shipment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
# replace <API-KEY> with your key
14-
shippo.api_key = "<API-KEY>"
14+
shippo.config.api_key = "<API-KEY>"
1515

1616
# Example address_from object dict
1717
# The complete reference for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/purchase-fastest-service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
MAX_TRANSIT_TIME_DAYS = 3
1313

1414
# Replace <API-KEY> with your key
15-
shippo.api_key = "<API-KEY>"
15+
shippo.config.api_key = "<API-KEY>"
1616

1717
# Example address_from object dict
1818
# The complete refence for the address object is available here: https://goshippo.com/docs/reference#addresses

‎examples/tracking.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
'''
77

88
# Replace <API-KEY> with your key
9-
shippo.api_key = "<API-KEY>"
9+
shippo.config.api_key = "<API-KEY>"
1010

1111
# Tracking based on a Shippo transaction
12-
transaction_id = '7774eff962dd4ae3ad125dceed5c4858'
12+
transaction_id = '<TRANSACTION-ID>'
1313
transaction = shippo.Transaction.retrieve(transaction_id)
1414

1515
if transaction:

‎setup.py

+14-45
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,40 @@
1-
from version import VERSION
21
import os
32
import sys
43
import warnings
4+
from setuptools import setup
55

6-
try:
7-
from setuptools import setup
8-
except ImportError:
9-
from distutils.core import setup
106

11-
try:
12-
from distutils.command.build_py import build_py_2to3 as build_py
13-
except ImportError:
14-
from distutils.command.build_py import build_py
7+
version_contents = {}
158

16-
path, script = os.path.split(sys.argv[0])
17-
os.chdir(os.path.abspath(path))
18-
19-
install_requires = []
20-
21-
if sys.version_info < (2, 6):
22-
warnings.warn(
23-
'Python 2.5 is not officially supported by Shippo. '
24-
'If you have any questions, please file an issue on Github or '
25-
'contact us at support@goshippo.com.',
26-
DeprecationWarning)
27-
install_requires.append('requests >= 0.9.0, < 0.10.1')
28-
install_requires.append('ssl')
29-
else:
30-
install_requires.append('requests >= 0.9.0')
31-
32-
33-
# Don't import shippo module here, since deps may not be installed
34-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'shippo'))
35-
36-
# Get simplejson if we don't already have json
37-
if sys.version_info < (3, 0):
38-
try:
39-
from util import json
40-
except ImportError:
41-
install_requires.append('simplejson')
9+
here = os.path.abspath(os.path.dirname(__file__))
10+
with open(os.path.join(here, "shippo", "version.py"), encoding="utf-8") as f:
11+
exec(f.read(), version_contents)
4212

4313
setup(
4414
name='shippo',
45-
cmdclass={'build_py': build_py},
46-
version=VERSION,
15+
version=version_contents['VERSION'],
4716
description='Shipping API Python library (USPS, FedEx, UPS and more)',
4817
author='Shippo',
4918
author_email='support@goshippo.com',
5019
url='https://goshippo.com/',
5120
packages=['shippo', 'shippo.test', 'shippo.test.integration'],
5221
package_data={'shippo': ['../VERSION']},
53-
install_requires=install_requires,
22+
install_requires=[
23+
'requests == 2.21.0',
24+
'simplejson == 3.16.0',
25+
],
5426
test_suite='shippo.test.all',
5527
tests_require=['unittest2', 'mock', 'vcrpy'],
56-
use_2to3=True,
5728
classifiers=[
5829
"Development Status :: 5 - Production/Stable",
5930
"Intended Audience :: Developers",
6031
"License :: OSI Approved :: MIT License",
6132
"Operating System :: OS Independent",
6233
"Programming Language :: Python",
63-
"Programming Language :: Python :: 2",
64-
"Programming Language :: Python :: 2.6",
65-
"Programming Language :: Python :: 2.7",
66-
"Programming Language :: Python :: 3",
67-
"Programming Language :: Python :: 3.2",
68-
"Programming Language :: Python :: 3.3",
34+
"Programming Language :: Python :: 3.5",
35+
"Programming Language :: Python :: 3.6",
36+
"Programming Language :: Python :: 3.7",
37+
"Programming Language :: Python :: 3 :: Only",
6938
"Programming Language :: Python :: Implementation :: PyPy",
7039
"Topic :: Software Development :: Libraries :: Python Modules",
7140
]

‎shippo/__init__.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Configurable variables
21
from shippo.resource import (
32
Address,
43
Batch,
@@ -13,8 +12,3 @@
1312
Track,
1413
Transaction,
1514
)
16-
api_key = None
17-
api_base = 'https://api.goshippo.com/'
18-
api_version = None
19-
verify_ssl_certs = True
20-
rates_req_timeout = 20.0 # seconds

‎shippo/api_requestor.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class APIRequestor(object):
5959
def __init__(self, key=None, client=None):
6060
self.api_key = key
6161

62-
from shippo import verify_ssl_certs
62+
from shippo.config import verify_ssl_certs
6363

6464
self._client = client or http_client.new_default_http_client(
6565
verify_ssl_certs=verify_ssl_certs)
@@ -89,18 +89,18 @@ def request_raw(self, method, url, params=None):
8989
"""
9090
Mechanism for issuing an API call
9191
"""
92-
from shippo import api_version
92+
from shippo.config import api_version
9393

9494
if self.api_key:
9595
my_api_key = self.api_key
9696
else:
97-
from shippo import api_key
97+
from shippo.config import api_key
9898
my_api_key = api_key
9999

100100
if my_api_key is None:
101101
raise error.AuthenticationError(
102102
'No API key provided. (HINT: set your API key using '
103-
'"shippo.api_key = <API-KEY>"). You can generate API keys '
103+
'"shippo.api_key = shippo_test_d90f00698a0a8def0495fddb4212bb08051469d3"). You can generate API keys '
Has a conversation. Original line has a conversation.
104104
'from the Shippo web interface. See https://goshippo.com/api '
105105
'for details, or email support@goshippo.comom if you have any '
106106
'questions.')
@@ -109,7 +109,7 @@ def request_raw(self, method, url, params=None):
109109
if my_api_key.startswith('oauth.'):
110110
token_type = 'Bearer'
111111

112-
abs_url = '%s%s' % (shippo.api_base, url)
112+
abs_url = '%s%s' % (shippo.config.api_base, url)
113113

114114
if method == 'get' or method == 'delete':
115115
if params:
@@ -183,10 +183,10 @@ def _check_ssl_cert(self):
183183
the certificate before sending potentially sensitive data on the wire.
184184
This approach raises the bar for an attacker significantly."""
185185

186-
from shippo import verify_ssl_certs
186+
from shippo.config import verify_ssl_certs
187187

188188
if verify_ssl_certs and not self._CERTIFICATE_VERIFIED:
189-
uri = urllib.parse.urlparse(shippo.api_base)
189+
uri = urllib.parse.urlparse(shippo.config.api_base)
190190
try:
191191
certificate = ssl.get_server_certificate(
192192
(uri.hostname, uri.port or 443))

‎shippo/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Configurable variables
2+
api_key = None
3+
api_base = 'https://api.goshippo.com/'
4+
api_version = None
5+
verify_ssl_certs = True
6+
rates_req_timeout = 20.0

‎shippo/resource.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import sys
33
import time
44
import warnings
5+
import shippo.config as config
6+
from shippo import api_requestor, error, util
7+
from shippo.config import rates_req_timeout
58

6-
from shippo import api_requestor, error, util, rates_req_timeout
79

810
warnings.filterwarnings('always', category=DeprecationWarning, module='shippo')
911

‎shippo/test/helper.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,24 @@ def setUp(self):
336336
self._shippo_original_attributes = {}
337337

338338
for attr in self.RESTORE_ATTRIBUTES:
339-
self._shippo_original_attributes[attr] = getattr(shippo, attr)
339+
self._shippo_original_attributes[attr] = getattr(
340+
shippo.config, attr)
340341

341342
api_base = os.environ.get('SHIPPO_API_BASE')
342343
if api_base:
343-
shippo.api_base = api_base
344+
shippo.config.api_base = api_base
344345

345-
shippo.api_key = os.environ.get(
346+
shippo.config.api_key = os.environ.get(
346347
'SHIPPO_API_KEY', '51895b669caa45038110fd4074e61e0d')
347-
shippo.api_version = os.environ.get('SHIPPO_API_VERSION', '2017-03-29')
348+
shippo.config.api_version = os.environ.get(
349+
'SHIPPO_API_VERSION', '2017-03-29')
348350

349351
def tearDown(self):
350352
super(ShippoTestCase, self).tearDown()
351353

352354
for attr in self.RESTORE_ATTRIBUTES:
353-
setattr(shippo, attr, self._shippo_original_attributes[attr])
355+
setattr(shippo.config, attr,
356+
self._shippo_original_attributes[attr])
354357

355358
# Python < 2.7 compatibility
356359
def assertRaisesRegexp(self, exception, regexp, callable, *args, **kwargs):

‎shippo/test/integration/test_integration.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def tearDown(self):
3333
self.client_patcher.stop()
3434

3535
def test_dns_failure(self):
36-
api_base = shippo.api_base
36+
api_base = shippo.config.api_base
3737
try:
38-
shippo.api_base = 'https://my-invalid-domain.ireallywontresolve/v1'
38+
shippo.config.api_base = 'https://my-invalid-domain.ireallywontresolve/v1'
3939
self.assertRaises(shippo.error.APIConnectionError,
4040
shippo.Address.create)
4141
finally:
42-
shippo.api_base = api_base
42+
shippo.config.api_base = api_base
4343

4444
def test_run(self):
4545
try:

‎shippo/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.0.0'
1+
VERSION = '2.0.0rc1'

0 commit comments

Comments
 (0)
This repository has been archived.