Skip to content

Commit 339c2be

Browse files
Merge pull request #1102 from adamtheturtle/better-docs
Add a usage example to the documentation
2 parents e51050d + 4a1fd1c commit 339c2be

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

README.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ Getting Started
2424
2525
from vws import VWS, CloudRecoService
2626
27-
vws_client = VWS(server_access_key='...', server_secret_key='...')
28-
cloud_reco_client = CloudRecoService(client_access_key='...', client_secret_key='...')
27+
server_access_key = '[server-access-key]'
28+
server_secret_key = '[server-secret-key]'
29+
client_access_key = '[client-access-key]'
30+
client_secret_key = '[client-secret-key]'
31+
32+
vws_client = VWS(
33+
server_access_key=server_access_key,
34+
server_secret_key=server_secret_key,
35+
)
36+
cloud_reco_client = CloudRecoService(
37+
client_access_key=client_access_key,
38+
client_secret_key=client_secret_key,
39+
)
2940
name = 'my_image_name'
3041
3142
with open('/path/to/image.png', 'rb') as my_image_file:

docs/source/api-reference.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
API Reference
2+
=============
3+
4+
.. automodule:: vws
5+
:undoc-members:
6+
:members:
7+
8+
.. automodule:: vws.include_target_data
9+
:undoc-members:
10+
:members:

docs/source/index.rst

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,99 @@ Installation
66

77
.. code:: sh
88
9-
pip install vws-python
9+
pip3 install vws-python
1010
1111
This is tested on Python 3.7+.
1212
Get in touch with ``[email protected]`` if you would like to use this with another language.
1313

14-
Reference
15-
---------
14+
Usage
15+
-----
16+
17+
See the :doc:`api-reference` for full usage details.
18+
19+
.. code:: python
20+
21+
import io
22+
23+
from vws import VWS, CloudRecoService
24+
25+
server_access_key = '[server-access-key]'
26+
server_secret_key = '[server-secret-key]'
27+
client_access_key = '[client-access-key]'
28+
client_secret_key = '[client-secret-key]'
29+
30+
vws_client = VWS(
31+
server_access_key=server_access_key,
32+
server_secret_key=server_secret_key,
33+
)
34+
cloud_reco_client = CloudRecoService(
35+
client_access_key=client_access_key,
36+
client_secret_key=client_secret_key,
37+
)
38+
name = 'my_image_name'
39+
40+
with open('/path/to/image.png', 'rb') as my_image_file:
41+
my_image = io.BytesIO(my_image_file.read())
42+
43+
target_id = vws_client.add_target(
44+
name=name,
45+
width=1,
46+
image=my_image,
47+
)
48+
vws_client.wait_for_target_processed(target_id=target_id)
49+
matching_targets = cloud_reco_client.query(image=my_image)
50+
51+
assert matching_targets[0]['target_id'] == target_id
52+
53+
Testing
54+
-------
55+
56+
To write unit tests for code which uses this library, without using your Vuforia quota, you can use the `VWS Python Mock`_ tool:
1657

17-
.. automodule:: vws
18-
:undoc-members:
19-
:members:
58+
.. code:: sh
59+
60+
pip3 install vws-python-mock
61+
62+
.. code:: python
63+
64+
from mock_vws import MockVWS, VuforiaDatabase
65+
66+
with MockVWS() as mock:
67+
database = VuforiaDatabase()
68+
mock.add_database(database=database)
69+
vws_client = VWS(
70+
server_access_key=server_access_key,
71+
server_secret_key=server_secret_key,
72+
)
73+
cloud_reco_client = CloudRecoService(
74+
client_access_key=client_access_key,
75+
client_secret_key=client_secret_key,
76+
)
77+
78+
name = 'my_image_name'
79+
80+
with open('/path/to/image.png', 'rb') as my_image_file:
81+
my_image = io.BytesIO(my_image_file.read())
2082
21-
.. automodule:: vws.include_target_data
22-
:undoc-members:
23-
:members:
83+
target_id = vws_client.add_target(
84+
name=name,
85+
width=1,
86+
image=my_image,
87+
)
88+
89+
There are some differences between the mock and the real Vuforia.
90+
See https://vws-python-mock.readthedocs.io/en/latest/differences-to-vws.html for details.
91+
92+
.. _VWS Python Mock: https://github.com/adamtheturtle/vws-python-mock
93+
94+
95+
Reference
96+
---------
2497

2598
.. toctree::
2699
:maxdepth: 3
27100

101+
api-reference
28102
exceptions
29103
contributing
30104
release-process

docs/source/release-process.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Store your PyPI password:
5252
5353
#. Get a GitHub access token:
5454

55-
Follow the `GitHub instructions <https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/>`__ for getting an access token.
55+
Follow the `GitHub access token instructions`_ for getting an access token.
5656

5757
#. Set environment variables to GitHub credentials, e.g.:
5858

@@ -66,3 +66,5 @@ Store your PyPI password:
6666
.. code:: sh
6767
6868
curl https://raw.githubusercontent.com/"$GITHUB_OWNER"/vws-python/master/admin/release.sh | bash
69+
70+
.. _GitHub access token instructions: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line/

spelling_private_dict.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
AuthenticationFailure
22
BadImage
33
ConnectionErrorPossiblyImageTooLarge
4+
DateRangeError
45
ImageTooLarge
6+
InactiveProject
57
MatchProcessing
68
MaxNumResultsOutOfRange
79
MetadataTooLarge
810
ProjectInactive
11+
RequestQuotaReached
912
RequestTimeTooSkewed
1013
TargetNameExist
1114
TargetProcessingTimeout
15+
TargetStatusNotSuccess
1216
TargetStatusProcessing
1317
Ubuntu
1418
UnknownTarget

src/vws/include_target_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
class CloudRecoIncludeTargetData(Enum):
99
"""
10-
Options for the ``include_target_data`` parameter of foo.
10+
Options for the ``include_target_data`` parameter of
11+
``CloudRecoService.query``.
1112
"""
1213

1314
TOP = 'top'

0 commit comments

Comments
 (0)