Skip to content

Commit 1642f2b

Browse files
committed
Add black hook and run on all files
1 parent b640f78 commit 1642f2b

File tree

86 files changed

+789
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+789
-542
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ repos:
1010
rev: v1.5.4
1111
hooks:
1212
- id: autopep8
13+
- repo: https://github.com/psf/black
14+
rev: 20.8b1
15+
hooks:
16+
- id: black
17+
args: [--line-length=120]

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[tool.autopep8]
22
max_line_length = 120
3+
4+
[tool.black]
5+
line-length = 120
6+
skip-string-normalization = true

scripts/shopify_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def start_interpreter(**variables):
1818
sys.path.append(os.getcwd())
1919
console = type('shopify ' + shopify.version.VERSION, (code.InteractiveConsole, object), {})
2020
import readline
21+
2122
console(variables).interact()
2223

2324

@@ -27,9 +28,11 @@ class ConfigFileError(Exception):
2728

2829
def usage(usage_string):
2930
"""Decorator to add a usage string to a function"""
31+
3032
def decorate(func):
3133
func.usage = usage_string
3234
return func
35+
3336
return decorate
3437

3538

@@ -44,6 +47,7 @@ def __new__(mcs, name, bases, new_attrs):
4447

4548
def filter_func(item):
4649
return not item.startswith("_") and hasattr(getattr(cls, item), "__call__")
50+
4751
tasks = filter(filter_func, tasks)
4852
cls._tasks = sorted(tasks)
4953

@@ -84,7 +88,7 @@ def help(cls, task=None):
8488
if desc:
8589
line = "%s%s # %s" % (line, " " * (max_len - len(line)), desc)
8690
if len(line) > cols:
87-
line = line[:cols - 3] + "..."
91+
line = line[: cols - 3] + "..."
8892
print(line)
8993
else:
9094
task_func = getattr(cls, task)
@@ -217,8 +221,10 @@ def version(cls, connection=None):
217221

218222
@classmethod
219223
def _available_connections(cls):
220-
return map(lambda item: os.path.splitext(os.path.basename(item))[0],
221-
glob.glob(os.path.join(cls._shop_config_dir, "*.yml")))
224+
return map(
225+
lambda item: os.path.splitext(os.path.basename(item))[0],
226+
glob.glob(os.path.join(cls._shop_config_dir, "*.yml")),
227+
)
222228

223229
@classmethod
224230
def _default_connection_target(cls):

setup.py

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,43 @@
1010
requests to Shopify in order to list, create, update, or delete
1111
resources (e.g. Order, Product, Collection)."""
1212

13-
setup(name=NAME,
14-
version=VERSION,
15-
description=DESCRIPTION,
16-
long_description=LONG_DESCRIPTION,
17-
author='Shopify',
18-
author_email='[email protected]',
19-
url='https://github.com/Shopify/shopify_python_api',
20-
packages=['shopify', 'shopify/resources'],
21-
scripts=['scripts/shopify_api.py'],
22-
license='MIT License',
23-
install_requires=[
24-
'pyactiveresource>=2.2.2',
25-
'PyYAML',
26-
'six',
27-
],
28-
test_suite='test',
29-
tests_require=[
30-
'mock>=1.0.1',
31-
],
32-
platforms='Any',
33-
classifiers=['Development Status :: 5 - Production/Stable',
34-
'Intended Audience :: Developers',
35-
'License :: OSI Approved :: MIT License',
36-
'Operating System :: OS Independent',
37-
'Programming Language :: Python',
38-
'Programming Language :: Python :: 2',
39-
'Programming Language :: Python :: 2.7',
40-
'Programming Language :: Python :: 3',
41-
'Programming Language :: Python :: 3.4',
42-
'Programming Language :: Python :: 3.5',
43-
'Programming Language :: Python :: 3.6',
44-
'Programming Language :: Python :: 3.8',
45-
'Programming Language :: Python :: 3.9',
46-
'Topic :: Software Development',
47-
'Topic :: Software Development :: Libraries',
48-
'Topic :: Software Development :: Libraries :: Python Modules']
49-
)
13+
setup(
14+
name=NAME,
15+
version=VERSION,
16+
description=DESCRIPTION,
17+
long_description=LONG_DESCRIPTION,
18+
author='Shopify',
19+
author_email='[email protected]',
20+
url='https://github.com/Shopify/shopify_python_api',
21+
packages=['shopify', 'shopify/resources'],
22+
scripts=['scripts/shopify_api.py'],
23+
license='MIT License',
24+
install_requires=[
25+
'pyactiveresource>=2.2.2',
26+
'PyYAML',
27+
'six',
28+
],
29+
test_suite='test',
30+
tests_require=[
31+
'mock>=1.0.1',
32+
],
33+
platforms='Any',
34+
classifiers=[
35+
'Development Status :: 5 - Production/Stable',
36+
'Intended Audience :: Developers',
37+
'License :: OSI Approved :: MIT License',
38+
'Operating System :: OS Independent',
39+
'Programming Language :: Python',
40+
'Programming Language :: Python :: 2',
41+
'Programming Language :: Python :: 2.7',
42+
'Programming Language :: Python :: 3',
43+
'Programming Language :: Python :: 3.4',
44+
'Programming Language :: Python :: 3.5',
45+
'Programming Language :: Python :: 3.6',
46+
'Programming Language :: Python :: 3.8',
47+
'Programming Language :: Python :: 3.9',
48+
'Topic :: Software Development',
49+
'Topic :: Software Development :: Libraries',
50+
'Topic :: Software Development :: Libraries :: Python Modules',
51+
],
52+
)

shopify/base.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
class ShopifyConnection(pyactiveresource.connection.Connection):
1818
response = None
1919

20-
def __init__(self, site, user=None, password=None, timeout=None,
21-
format=formats.JSONFormat):
20+
def __init__(self, site, user=None, password=None, timeout=None, format=formats.JSONFormat):
2221
super(ShopifyConnection, self).__init__(site, user, password, timeout, format)
2322

2423
def _open(self, *args, **kwargs):
@@ -30,11 +29,11 @@ def _open(self, *args, **kwargs):
3029
raise
3130
return self.response
3231

32+
3333
# Inherit from pyactiveresource's metaclass in order to use ShopifyConnection
3434

3535

3636
class ShopifyResourceMeta(ResourceMeta):
37-
3837
@property
3938
def connection(cls):
4039
"""HTTP connection for the current thread"""
@@ -51,8 +50,7 @@ def connection(cls):
5150
local.url = cls.url
5251
if cls.site is None:
5352
raise ValueError("No shopify session is active")
54-
local.connection = ShopifyConnection(
55-
cls.site, cls.user, cls.password, cls.timeout, cls.format)
53+
local.connection = ShopifyConnection(cls.site, cls.user, cls.password, cls.timeout, cls.format)
5654
return local.connection
5755

5856
def get_user(cls):
@@ -62,8 +60,7 @@ def set_user(cls, value):
6260
cls._threadlocal.connection = None
6361
ShopifyResource._user = cls._threadlocal.user = value
6462

65-
user = property(get_user, set_user, None,
66-
"The username for HTTP Basic Auth.")
63+
user = property(get_user, set_user, None, "The username for HTTP Basic Auth.")
6764

6865
def get_password(cls):
6966
return getattr(cls._threadlocal, 'password', ShopifyResource._password)
@@ -72,8 +69,7 @@ def set_password(cls, value):
7269
cls._threadlocal.connection = None
7370
ShopifyResource._password = cls._threadlocal.password = value
7471

75-
password = property(get_password, set_password, None,
76-
"The password for HTTP Basic Auth.")
72+
password = property(get_password, set_password, None, "The password for HTTP Basic Auth.")
7773

7874
def get_site(cls):
7975
return getattr(cls._threadlocal, 'site', ShopifyResource._site)
@@ -93,8 +89,7 @@ def set_site(cls, value):
9389
if parts.password:
9490
cls.password = urllib.parse.unquote(parts.password)
9591

96-
site = property(get_site, set_site, None,
97-
'The base REST site to connect to.')
92+
site = property(get_site, set_site, None, 'The base REST site to connect to.')
9893

9994
def get_timeout(cls):
10095
return getattr(cls._threadlocal, 'timeout', ShopifyResource._timeout)
@@ -103,8 +98,7 @@ def set_timeout(cls, value):
10398
cls._threadlocal.connection = None
10499
ShopifyResource._timeout = cls._threadlocal.timeout = value
105100

106-
timeout = property(get_timeout, set_timeout, None,
107-
'Socket timeout for HTTP requests')
101+
timeout = property(get_timeout, set_timeout, None, 'Socket timeout for HTTP requests')
108102

109103
def get_headers(cls):
110104
if not hasattr(cls._threadlocal, 'headers'):
@@ -114,8 +108,7 @@ def get_headers(cls):
114108
def set_headers(cls, value):
115109
cls._threadlocal.headers = value
116110

117-
headers = property(get_headers, set_headers, None,
118-
'The headers sent with HTTP requests')
111+
headers = property(get_headers, set_headers, None, 'The headers sent with HTTP requests')
119112

120113
def get_format(cls):
121114
return getattr(cls._threadlocal, 'format', ShopifyResource._format)
@@ -124,8 +117,7 @@ def set_format(cls, value):
124117
cls._threadlocal.connection = None
125118
ShopifyResource._format = cls._threadlocal.format = value
126119

127-
format = property(get_format, set_format, None,
128-
'Encoding used for request and responses')
120+
format = property(get_format, set_format, None, 'Encoding used for request and responses')
129121

130122
def get_prefix_source(cls):
131123
"""Return the prefix source, by default derived from site."""
@@ -141,8 +133,7 @@ def set_prefix_source(cls, value):
141133
"""Set the prefix source, which will be rendered into the prefix."""
142134
cls._prefix_source = value
143135

144-
prefix_source = property(get_prefix_source, set_prefix_source, None,
145-
'prefix for lookups for this type of object.')
136+
prefix_source = property(get_prefix_source, set_prefix_source, None, 'prefix for lookups for this type of object.')
146137

147138
def get_version(cls):
148139
if hasattr(cls._threadlocal, 'version') or ShopifyResource._version:
@@ -153,25 +144,22 @@ def get_version(cls):
153144
def set_version(cls, value):
154145
ShopifyResource._version = cls._threadlocal.version = value
155146

156-
version = property(get_version, set_version, None,
157-
'Shopify Api Version')
147+
version = property(get_version, set_version, None, 'Shopify Api Version')
158148

159149
def get_url(cls):
160150
return getattr(cls._threadlocal, 'url', ShopifyResource._url)
161151

162152
def set_url(cls, value):
163153
ShopifyResource._url = cls._threadlocal.url = value
164154

165-
url = property(get_url, set_url, None,
166-
'Base URL including protocol and shopify domain')
155+
url = property(get_url, set_url, None, 'Base URL including protocol and shopify domain')
167156

168157

169158
@six.add_metaclass(ShopifyResourceMeta)
170159
class ShopifyResource(ActiveResource, mixins.Countable):
171160
_format = formats.JSONFormat
172161
_threadlocal = threading.local()
173-
_headers = {
174-
'User-Agent': 'ShopifyPythonAPI/%s Python/%s' % (shopify.VERSION, sys.version.split(' ', 1)[0])}
162+
_headers = {'User-Agent': 'ShopifyPythonAPI/%s Python/%s' % (shopify.VERSION, sys.version.split(' ', 1)[0])}
175163
_version = None
176164
_url = None
177165

shopify/collection.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ def __parse_pagination(self):
5656
return result
5757

5858
def has_previous_page(self):
59-
"""Returns true if the current page has any previous pages before it.
60-
"""
59+
"""Returns true if the current page has any previous pages before it."""
6160
return bool(self.previous_page_url)
6261

6362
def has_next_page(self):
64-
"""Returns true if the current page has any pages beyond the current position.
65-
"""
63+
"""Returns true if the current page has any pages beyond the current position."""
6664
return bool(self.next_page_url)
6765

6866
def previous_page(self, no_cache=False):

shopify/limits.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Limits(object):
88
99
Conversion of lib/shopify_api/limits.rb
1010
"""
11+
1112
# num_requests_executed/max_requests
1213
# Eg: 1/40
1314
CREDIT_LIMIT_HEADER_PARAM = 'X-Shopify-Shop-Api-Call-Limit'

shopify/mixins.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class Countable(object):
5-
65
@classmethod
76
def count(cls, _options=None, **kwargs):
87
if _options is None:
@@ -11,7 +10,6 @@ def count(cls, _options=None, **kwargs):
1110

1211

1312
class Metafields(object):
14-
1513
def metafields(self, _options=None, **kwargs):
1614
if _options is None:
1715
_options = kwargs
@@ -32,6 +30,5 @@ def add_metafield(self, metafield):
3230

3331

3432
class Events(object):
35-
3633
def events(self):
3734
return shopify.resources.Event.find(resource=self.__class__.plural, resource_id=self.id)

shopify/resources/api_permission.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class ApiPermission(ShopifyResource):
5-
65
@classmethod
76
def delete(cls):
87
cls.connection.delete(cls.site + '/api_permissions/current.' + cls.format.extension, cls.headers)

shopify/resources/application_charge.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33

44
class ApplicationCharge(ShopifyResource):
5-
65
def activate(self):
76
self._load_attributes_from_response(self.post("activate"))

shopify/resources/asset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ def _prefix(cls, options={}):
1818
def _element_path(cls, id, prefix_options={}, query_options=None):
1919
if query_options is None:
2020
prefix_options, query_options = cls._split_options(prefix_options)
21-
return "%s%s.%s%s" % (cls._prefix(prefix_options) + '/', cls.plural,
22-
cls.format.extension, cls._query_string(query_options))
21+
return "%s%s.%s%s" % (
22+
cls._prefix(prefix_options) + '/',
23+
cls.plural,
24+
cls.format.extension,
25+
cls._query_string(query_options),
26+
)
2327

2428
@classmethod
2529
def find(cls, key=None, **kwargs):

shopify/resources/blog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44

55

66
class Blog(ShopifyResource, mixins.Metafields, mixins.Events):
7-
87
def articles(self):
98
return shopify.Article.find(blog_id=self.id)

shopify/resources/comment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class Comment(ShopifyResource):
5-
65
def remove(self):
76
self._load_attributes_from_response(self.post("remove"))
87

shopify/resources/custom_collection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class CustomCollection(ShopifyResource, mixins.Metafields, mixins.Events):
7-
87
def products(self):
98
return shopify.Product.find(collection_id=self.id)
109

shopify/resources/customer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Customer(ShopifyResource, mixins.Metafields):
7-
87
@classmethod
98
def search(cls, **kwargs):
109
"""

shopify/resources/customer_saved_search.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33

44

55
class CustomerSavedSearch(ShopifyResource):
6-
76
def customers(cls, **kwargs):
87
return Customer._build_collection(cls.get("customers", **kwargs))

0 commit comments

Comments
 (0)