Skip to content

Commit 767f18b

Browse files
Merge pull request #2349 from VWS-Python/simplify-pre-commit
Simplify documentation examples
2 parents d87302b + fdcd473 commit 767f18b

File tree

4 files changed

+96
-110
lines changed

4 files changed

+96
-110
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ repos:
132132

133133
- id: pylint-docs
134134
name: pylint-docs
135-
entry: doccmd --language=python --command="pylint" --lowercase-file-name
135+
entry: doccmd --language=python --command="pylint"
136136
language: system
137137
stages: [manual]
138138
types_or: [markdown, rst, python, toml]

README.rst

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,40 @@ Getting Started
2828
import uuid
2929
3030
from vws import VWS, CloudRecoService
31-
from vws.reports import QueryResult
3231
33-
34-
def add_target() -> str:
35-
"""Add a target to VWS and return its ID."""
36-
server_access_key = "[server-access-key]"
37-
server_secret_key = "[server-secret-key]"
38-
vws_client = VWS(
39-
server_access_key=server_access_key,
40-
server_secret_key=server_secret_key,
41-
)
42-
name = "my_image_name_" + uuid.uuid4().hex
43-
44-
image = pathlib.Path("high_quality_image.jpg")
45-
with image.open(mode="rb") as my_image_file:
46-
target_id = vws_client.add_target(
47-
name=name,
48-
width=1,
49-
image=my_image_file,
50-
active_flag=True,
51-
application_metadata=None,
52-
)
53-
vws_client.wait_for_target_processed(target_id=target_id)
54-
55-
return target_id
56-
57-
58-
def get_matching_targets() -> list[QueryResult]:
59-
"""Query VWS for matching targets."""
60-
client_access_key = "[client-access-key]"
61-
client_secret_key = "[client-secret-key]"
62-
63-
cloud_reco_client = CloudRecoService(
64-
client_access_key=client_access_key,
65-
client_secret_key=client_secret_key,
32+
server_access_key = "[server-access-key]"
33+
server_secret_key = "[server-secret-key]"
34+
client_access_key = "[client-access-key]"
35+
client_secret_key = "[client-secret-key]"
36+
37+
vws_client = VWS(
38+
server_access_key=server_access_key,
39+
server_secret_key=server_secret_key,
40+
)
41+
42+
cloud_reco_client = CloudRecoService(
43+
client_access_key=client_access_key,
44+
client_secret_key=client_secret_key,
45+
)
46+
47+
name = "my_image_name_" + uuid.uuid4().hex
48+
49+
image = pathlib.Path("high_quality_image.jpg")
50+
with image.open(mode="rb") as my_image_file:
51+
target_id = vws_client.add_target(
52+
name=name,
53+
width=1,
54+
image=my_image_file,
55+
active_flag=True,
56+
application_metadata=None,
6657
)
6758
68-
image = pathlib.Path("high_quality_image.jpg")
69-
with image.open(mode="rb") as my_image_file:
70-
return cloud_reco_client.query(image=my_image_file)
59+
vws_client.wait_for_target_processed(target_id=target_id)
7160
61+
with image.open(mode="rb") as my_image_file:
62+
matching_targets = cloud_reco_client.query(image=my_image_file)
7263
73-
TARGET_ID = add_target()
74-
MATCHING_TARGETS = get_matching_targets()
75-
assert MATCHING_TARGETS[0].target_id == TARGET_ID
64+
assert matching_targets[0].target_id == target_id
7665
7766
Full Documentation
7867
------------------

docs/source/index.rst

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,40 @@ See the :doc:`api-reference` for full usage details.
2424
import uuid
2525
2626
from vws import VWS, CloudRecoService
27-
from vws.reports import QueryResult
2827
29-
30-
def add_target() -> str:
31-
"""Add a target to VWS and return its ID."""
32-
server_access_key = "[server-access-key]"
33-
server_secret_key = "[server-secret-key]"
34-
vws_client = VWS(
35-
server_access_key=server_access_key,
36-
server_secret_key=server_secret_key,
37-
)
38-
name = "my_image_name_" + uuid.uuid4().hex
39-
40-
image = pathlib.Path("high_quality_image.jpg")
41-
with image.open(mode="rb") as my_image_file:
42-
target_id = vws_client.add_target(
43-
name=name,
44-
width=1,
45-
image=my_image_file,
46-
active_flag=True,
47-
application_metadata=None,
48-
)
49-
vws_client.wait_for_target_processed(target_id=target_id)
50-
51-
return target_id
52-
53-
54-
def get_matching_targets() -> list[QueryResult]:
55-
"""Query VWS for matching targets."""
56-
client_access_key = "[client-access-key]"
57-
client_secret_key = "[client-secret-key]"
58-
59-
cloud_reco_client = CloudRecoService(
60-
client_access_key=client_access_key,
61-
client_secret_key=client_secret_key,
28+
server_access_key = "[server-access-key]"
29+
server_secret_key = "[server-secret-key]"
30+
client_access_key = "[client-access-key]"
31+
client_secret_key = "[client-secret-key]"
32+
33+
vws_client = VWS(
34+
server_access_key=server_access_key,
35+
server_secret_key=server_secret_key,
36+
)
37+
38+
cloud_reco_client = CloudRecoService(
39+
client_access_key=client_access_key,
40+
client_secret_key=client_secret_key,
41+
)
42+
43+
name = "my_image_name_" + uuid.uuid4().hex
44+
45+
image = pathlib.Path("high_quality_image.jpg")
46+
with image.open(mode="rb") as my_image_file:
47+
target_id = vws_client.add_target(
48+
name=name,
49+
width=1,
50+
image=my_image_file,
51+
active_flag=True,
52+
application_metadata=None,
6253
)
6354
64-
image = pathlib.Path("high_quality_image.jpg")
65-
with image.open(mode="rb") as my_image_file:
66-
return cloud_reco_client.query(image=my_image_file)
55+
vws_client.wait_for_target_processed(target_id=target_id)
6756
57+
with image.open(mode="rb") as my_image_file:
58+
matching_targets = cloud_reco_client.query(image=my_image_file)
6859
69-
TARGET_ID = add_target()
70-
MATCHING_TARGETS = get_matching_targets()
71-
assert MATCHING_TARGETS[0].target_id == TARGET_ID
60+
assert matching_targets[0].target_id == target_id
7261
7362
Testing
7463
-------
@@ -92,38 +81,32 @@ To write unit tests for code which uses this library, without using your Vuforia
9281
9382
from vws import VWS, CloudRecoService
9483
95-
96-
def test_add_target() -> None:
97-
"""Test adding a target to VWS."""
98-
with MockVWS() as mock:
99-
database = VuforiaDatabase()
100-
mock.add_database(database=database)
101-
vws_client = VWS(
102-
server_access_key=database.server_access_key,
103-
server_secret_key=database.server_secret_key,
104-
)
105-
cloud_reco_client = CloudRecoService(
106-
client_access_key=database.client_access_key,
107-
client_secret_key=database.client_secret_key,
84+
with MockVWS() as mock:
85+
database = VuforiaDatabase()
86+
mock.add_database(database=database)
87+
vws_client = VWS(
88+
server_access_key=database.server_access_key,
89+
server_secret_key=database.server_secret_key,
90+
)
91+
cloud_reco_client = CloudRecoService(
92+
client_access_key=database.client_access_key,
93+
client_secret_key=database.client_secret_key,
94+
)
95+
96+
image = pathlib.Path("high_quality_image.jpg")
97+
with image.open(mode="rb") as my_image_file:
98+
target_id = vws_client.add_target(
99+
name="example_image_name",
100+
width=1,
101+
image=my_image_file,
102+
application_metadata=None,
103+
active_flag=True,
108104
)
109105
110-
image = pathlib.Path("high_quality_image.jpg")
111-
with image.open(mode="rb") as my_image_file:
112-
target_id = vws_client.add_target(
113-
name="example_image_name",
114-
width=1,
115-
image=my_image_file,
116-
application_metadata=None,
117-
active_flag=True,
118-
)
119-
120-
vws_client.wait_for_target_processed(target_id=target_id)
121-
matching_targets = cloud_reco_client.query(image=my_image_file)
122-
123-
assert matching_targets[0].target_id == target_id
124-
106+
vws_client.wait_for_target_processed(target_id=target_id)
107+
matching_targets = cloud_reco_client.query(image=my_image_file)
125108
126-
test_add_target()
109+
assert matching_targets[0].target_id == target_id
127110
128111
There are some differences between the mock and the real Vuforia.
129112
See https://vws-python-mock.readthedocs.io/en/latest/differences-to-vws.html for details.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ optional-dependencies.dev = [
5353
"pyenchant==3.2.2",
5454
"pygments==2.18.0",
5555
"pylint==3.2.7",
56+
"pylint-per-file-ignores==1.3.2",
5657
"pyproject-fmt==2.2.3",
5758
"pyright==1.1.380",
5859
"pyroma==4.2",
@@ -154,12 +155,14 @@ jobs = 0
154155
# List of plugins (as comma separated values of python modules names) to load,
155156
# usually to register additional checkers.
156157
# See https://chezsoi.org/lucas/blog/pylint-strict-base-configuration.html.
158+
# and we also add `pylint_per_file_ignores` to allow per-file ignores.
157159
# We do not use the plugins:
158160
# - pylint.extensions.code_style
159161
# - pylint.extensions.magic_value
160162
# - pylint.extensions.while_used
161163
# as they seemed to get in the way.
162164
load-plugins = [
165+
"pylint_per_file_ignores",
163166
'pylint.extensions.bad_builtin',
164167
'pylint.extensions.comparison_placement',
165168
'pylint.extensions.consider_refactoring_into_while_condition',
@@ -231,6 +234,17 @@ disable = [
231234
'useless-type-doc',
232235
]
233236

237+
# This format is described in the following issue:
238+
# https://github.com/christopherpickering/pylint-per-file-ignores/issues/160
239+
#
240+
# We ignore invalid names because:
241+
# - We want to use generated module names, which may not be valid, but are never seen.
242+
# - We want to use global variables in documentation, which may not be uppercase
243+
per-file-ignores = """
244+
docs/:invalid-name
245+
doccmd_README_rst.*.py:invalid-name
246+
"""
247+
234248
[tool.pylint.'FORMAT']
235249

236250
# Allow the body of an if to be on the same line as the test if there is no

0 commit comments

Comments
 (0)