Skip to content

Commit e9e613b

Browse files
author
Jim Bennett
committed
Black
1 parent 90b5c4f commit e9e613b

File tree

10 files changed

+113
-130
lines changed

10 files changed

+113
-130
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
5050
- name: Check formatting
5151
run: |
52-
black --check --target-version=py35 .
52+
black --check --target-version=py35 --line-length 140 .
5353
- name: Build assets
5454
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
5555
- name: Build docs

circuitpython_customvision/prediction/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
from .custom_vision_prediction_client import CustomVisionPredictionClient
1313
from .version import VERSION
1414

15-
__all__ = ['CustomVisionPredictionClient']
15+
__all__ = ["CustomVisionPredictionClient"]
1616

1717
__version__ = VERSION

circuitpython_customvision/prediction/custom_vision_prediction_client.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .version import VERSION
66
from . import models
77

8+
89
def run_request(url, body, headers):
910
retry = 0
1011
r = None
@@ -29,7 +30,8 @@ def run_request(url, body, headers):
2930

3031
return r
3132

32-
class CustomVisionPredictionClient():
33+
34+
class CustomVisionPredictionClient:
3335
"""CustomVisionPredictionClient
3436
3537
:param api_key: API key.
@@ -38,56 +40,51 @@ class CustomVisionPredictionClient():
3840
:type endpoint: str
3941
"""
4042

41-
__classify_image_url_route = 'customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/url'
42-
__classify_image_route = 'customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/image'
43-
__detect_image_url_route = 'customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/url'
44-
__detect_image_route = 'customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/image'
43+
__classify_image_url_route = "customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/url"
44+
__classify_image_route = "customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/image"
45+
__detect_image_url_route = "customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/url"
46+
__detect_image_route = "customvision/v3.0/Prediction/{projectId}/classify/iterations/{publishedName}/image"
4547

46-
def __init__(
47-
self, api_key, endpoint):
48+
def __init__(self, api_key, endpoint):
4849

4950
self.__api_key = api_key
5051

5152
# build the root endpoint
52-
if not endpoint.lower().startswith('https://'):
53-
endpoint = 'https://' + endpoint
54-
if not endpoint.endswith('/'):
55-
endpoint = endpoint + '/'
53+
if not endpoint.lower().startswith("https://"):
54+
endpoint = "https://" + endpoint
55+
if not endpoint.endswith("/"):
56+
endpoint = endpoint + "/"
5657

5758
self.__base_endpoint = endpoint
5859
self.api_version = VERSION
5960

6061
def __format_endpoint(self, url_format: str, project_id: str, published_name: str, store: bool, application: Optional[str]):
6162
endpoint = self.__base_endpoint + url_format.format(projectId=project_id, publishedName=published_name)
6263
if not store:
63-
endpoint = endpoint + '/nostore'
64+
endpoint = endpoint + "/nostore"
6465
if application is not None:
65-
application = '?' + application
66+
application = "?" + application
6667
endpoint = endpoint + application
6768

6869
return endpoint
6970

7071
def __process_image_url(self, route: str, project_id: str, published_name: str, url: str, store: bool, application: Optional[str]):
7172
endpoint = self.__format_endpoint(route, project_id, published_name, store, application)
7273

73-
headers = {
74-
'Content-Type': 'application/json',
75-
'Prediction-Key': self.__api_key
76-
}
74+
headers = {"Content-Type": "application/json", "Prediction-Key": self.__api_key}
7775

78-
body = json.dumps({'url' : url})
76+
body = json.dumps({"url": url})
7977
result = run_request(endpoint, body, headers)
8078
result_text = result.text
8179

8280
return models.ImagePrediction(result_text)
8381

84-
def __process_image(self, route: str, project_id: str, published_name: str, image_data: bytearray, store: bool, application: Optional[str]):
82+
def __process_image(
83+
self, route: str, project_id: str, published_name: str, image_data: bytearray, store: bool, application: Optional[str]
84+
):
8585
endpoint = self.__format_endpoint(route, project_id, published_name, store, application)
8686

87-
headers = {
88-
'Content-Type': 'application/octet-stream',
89-
'Prediction-Key': self.__api_key
90-
}
87+
headers = {"Content-Type": "application/octet-stream", "Prediction-Key": self.__api_key}
9188

9289
result = run_request(endpoint, image_data, headers)
9390
result_text = result.text

circuitpython_customvision/prediction/models/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@
1414
from .image_prediction import ImagePrediction
1515
from .customvision_error import CustomVisionError
1616

17-
__all__ = [
18-
'BoundingBox',
19-
'Prediction',
20-
'ImagePrediction',
21-
'CustomVisionError'
22-
]
17+
__all__ = ["BoundingBox", "Prediction", "ImagePrediction", "CustomVisionError"]

circuitpython_customvision/prediction/models/bounding_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class BoundingBox():
1+
class BoundingBox:
22
"""Bounding box that defines a region of an image.
33
44
All required parameters must be populated in order to send to Azure.

circuitpython_customvision/prediction/models/customvision_error.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class CustomVisionError(Exception):
22
"""
33
An error from the custom vision service
44
"""
5+
56
def __init__(self, message):
67
super(CustomVisionError, self).__init__(message)
78
self.message = message

circuitpython_customvision/prediction/models/image_prediction.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from .prediction import Prediction
33
from .bounding_box import BoundingBox
44

5-
class ImagePrediction():
5+
6+
class ImagePrediction:
67
"""Result of an image prediction request.
78
89
Variables are only populated by the server, and will be ignored when
@@ -26,20 +27,16 @@ def __init__(self, response) -> None:
2627
if not isinstance(response, dict):
2728
response = json.loads(response)
2829

29-
self.id = response['id']
30-
self.project = response['project']
31-
self.iteration = response['iteration']
32-
self.created = response['created']
30+
self.prediction_id = response["id"]
31+
self.project = response["project"]
32+
self.iteration = response["iteration"]
33+
self.created = response["created"]
3334
self.predictions = []
3435

35-
for pred in response['predictions']:
36-
box = pred['boundingBox']
37-
bounding_box = BoundingBox(left=box['left'],
38-
top=box['top'],
39-
width=box['width'],
40-
height=box['height'])
41-
prediction = Prediction(probability=pred['probability'],
42-
tag_id=pred['tagId'],
43-
tag_name=pred['tagName'],
44-
bounding_box=bounding_box)
36+
for pred in response["predictions"]:
37+
box = pred["boundingBox"]
38+
bounding_box = BoundingBox(left=box["left"], top=box["top"], width=box["width"], height=box["height"])
39+
prediction = Prediction(
40+
probability=pred["probability"], tag_id=pred["tagId"], tag_name=pred["tagName"], bounding_box=bounding_box
41+
)
4542
self.predictions.append(prediction)

circuitpython_customvision/prediction/models/prediction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .bounding_box import BoundingBox
22

3-
class Prediction():
3+
4+
class Prediction:
45
"""Prediction result.
56
67
Variables are only populated by the server, and will be ignored when

docs/conf.py

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
# autodoc_mock_imports = ["digitalio", "busio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'CircuitPython-CustomVision Library'
38-
copyright = u'2020 Jim Bennett'
39-
author = u'Jim Bennett'
41+
project = "CircuitPython-CustomVision Library"
42+
copyright = "2020 Jim Bennett"
43+
author = "Jim Bennett"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,77 +88,77 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'Circuitpython-customvisionLibrarydoc'
117+
htmlhelp_basename = "Circuitpython-customvisionLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'CircuitPython-CustomVisionLibrary.tex', u'CircuitPython-CustomVision Library Documentation',
139-
author, 'manual'),
140+
(master_doc, "CircuitPython-CustomVisionLibrary.tex", "CircuitPython-CustomVision Library Documentation", author, "manual"),
140141
]
141142

142143
# -- Options for manual page output ---------------------------------------
143144

144145
# One entry per manual page. List of tuples
145146
# (source start file, name, description, authors, manual section).
146-
man_pages = [
147-
(master_doc, 'CircuitPython-CustomVisionlibrary', u'CircuitPython-CustomVision Library Documentation',
148-
[author], 1)
149-
]
147+
man_pages = [(master_doc, "CircuitPython-CustomVisionlibrary", "CircuitPython-CustomVision Library Documentation", [author], 1)]
150148

151149
# -- Options for Texinfo output -------------------------------------------
152150

153151
# Grouping the document tree into Texinfo files. List of tuples
154152
# (source start file, target name, title, author,
155153
# dir menu entry, description, category)
156154
texinfo_documents = [
157-
(master_doc, 'CircuitPython-CustomVisionLibrary', u'CircuitPython-CustomVision Library Documentation',
158-
author, 'CircuitPython-CustomVisionLibrary', 'One line description of project.',
159-
'Miscellaneous'),
155+
(
156+
master_doc,
157+
"CircuitPython-CustomVisionLibrary",
158+
"CircuitPython-CustomVision Library Documentation",
159+
author,
160+
"CircuitPython-CustomVisionLibrary",
161+
"One line description of project.",
162+
"Miscellaneous",
163+
),
160164
]

0 commit comments

Comments
 (0)