Skip to content

Commit be36149

Browse files
Merge pull request #1831 from VWS-Python/sybil
Sybil
2 parents becbb7f + 8f70b7b commit be36149

File tree

9 files changed

+142
-120
lines changed

9 files changed

+142
-120
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ jobs:
5050
5151
- name: "Run tests"
5252
run: |
53-
pytest -s -vvv --cov-fail-under 100 --cov=src/ --cov=tests tests/ --cov-report=xml
53+
# We run tests against "." and not the tests directory as we test the README
54+
# and documentation.
55+
pytest -s -vvv --cov-fail-under 100 --cov=src/ --cov=tests . --cov-report=xml
5456
5557
- name: "Upload coverage to Codecov"
5658
uses: "codecov/codecov-action@v3"

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ lint: \
1010
black \
1111
check-manifest \
1212
doc8 \
13-
doctest \
1413
linkcheck \
1514
mypy \
1615
ruff \

README.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

README.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
|Build Status| |codecov| |PyPI| |Documentation Status|
2+
3+
vws-python
4+
==========
5+
6+
Python library for the Vuforia Web Services (VWS) API and the Vuforia
7+
Web Query API.
8+
9+
Installation
10+
------------
11+
12+
.. code:: sh
13+
14+
pip install vws-python
15+
16+
This is tested on Python 3.11+. Get in touch with
17+
``adamdangoor@gmail.com`` if you would like to use this with another
18+
language.
19+
20+
Getting Started
21+
---------------
22+
23+
.. invisible-code-block: python
24+
25+
import pathlib
26+
import shutil
27+
28+
import vws_test_fixtures
29+
from mock_vws import MockVWS
30+
from mock_vws.database import VuforiaDatabase
31+
32+
mock = MockVWS(real_http=False)
33+
database = VuforiaDatabase(
34+
server_access_key='[server-access-key]',
35+
server_secret_key='[server-secret-key]',
36+
client_access_key='[client-access-key]',
37+
client_secret_key='[client-secret-key]',
38+
)
39+
mock.add_database(database=database)
40+
mock.__enter__()
41+
42+
# We rely on implementation details of the fixtures package.
43+
image = pathlib.Path(vws_test_fixtures.__path__[0]) / 'high_quality_image.jpg'
44+
assert image.exists(), image.resolve()
45+
new_image = pathlib.Path('high_quality_image.jpg')
46+
shutil.copy(image, new_image)
47+
48+
49+
.. code-block:: python
50+
51+
import pathlib
52+
53+
from vws import VWS, CloudRecoService
54+
55+
server_access_key = '[server-access-key]'
56+
server_secret_key = '[server-secret-key]'
57+
client_access_key = '[client-access-key]'
58+
client_secret_key = '[client-secret-key]'
59+
60+
vws_client = VWS(
61+
server_access_key=server_access_key,
62+
server_secret_key=server_secret_key,
63+
)
64+
cloud_reco_client = CloudRecoService(
65+
client_access_key=client_access_key,
66+
client_secret_key=client_secret_key,
67+
)
68+
name = 'my_image_name'
69+
70+
image = pathlib.Path('high_quality_image.jpg')
71+
with image.open(mode='rb') as my_image_file:
72+
target_id = vws_client.add_target(
73+
name=name,
74+
width=1,
75+
image=my_image_file,
76+
active_flag=True,
77+
application_metadata=None,
78+
)
79+
vws_client.wait_for_target_processed(target_id=target_id)
80+
matching_targets = cloud_reco_client.query(image=my_image_file)
81+
82+
assert matching_targets[0].target_id == target_id
83+
84+
.. invisible-code-block: python
85+
new_image = pathlib.Path('high_quality_image.jpg')
86+
new_image.unlink()
87+
mock.__exit__()
88+
89+
Full Documentation
90+
------------------
91+
92+
See the `full
93+
documentation <https://vws-python.readthedocs.io/en/latest>`__.
94+
95+
.. |Build Status| image:: https://github.com/VWS-Python/vws-python/workflows/CI/badge.svg
96+
:target: https://github.com/VWS-Python/vws-python/actions
97+
.. |codecov| image:: https://codecov.io/gh/VWS-Python/vws-python/branch/master/graph/badge.svg
98+
:target: https://codecov.io/gh/VWS-Python/vws-python
99+
.. |PyPI| image:: https://badge.fury.io/py/VWS-Python.svg
100+
:target: https://badge.fury.io/py/VWS-Python
101+
.. |Documentation Status| image:: https://readthedocs.org/projects/vws-python/badge/?version=latest
102+
:target: https://vws-python.readthedocs.io/en/latest/?badge=latest

conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Setup for Sybil."""
2+
3+
from doctest import ELLIPSIS
4+
5+
from sybil import Sybil
6+
from sybil.parsers.rest import (
7+
DocTestParser,
8+
PythonCodeBlockParser,
9+
)
10+
11+
pytest_collect_file = Sybil(
12+
parsers=[
13+
DocTestParser(optionflags=ELLIPSIS),
14+
PythonCodeBlockParser(),
15+
],
16+
patterns=["*.rst", "*.py"],
17+
).pytest()

docs/source/conf.py

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

1414
extensions = [
1515
"sphinx.ext.autodoc",
16-
"sphinx.ext.doctest",
1716
"sphinx.ext.intersphinx",
1817
"sphinx.ext.napoleon",
1918
"sphinx_autodoc_typehints",

docs/source/index.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Usage
1616

1717
See the :doc:`api-reference` for full usage details.
1818

19-
.. testsetup:: simple
19+
.. invisible-code-block: python
2020
2121
import pathlib
2222
import shutil
@@ -41,7 +41,7 @@ See the :doc:`api-reference` for full usage details.
4141
new_image = pathlib.Path('high_quality_image.jpg')
4242
shutil.copy(image, new_image)
4343
44-
.. testcode:: simple
44+
.. code-block:: python
4545
4646
import pathlib
4747
@@ -76,7 +76,7 @@ See the :doc:`api-reference` for full usage details.
7676
7777
assert matching_targets[0].target_id == target_id
7878
79-
.. testcleanup:: simple
79+
.. invisible-code-block: python
8080
8181
new_image = pathlib.Path('high_quality_image.jpg')
8282
new_image.unlink()
@@ -91,7 +91,14 @@ To write unit tests for code which uses this library, without using your Vuforia
9191

9292
pip3 install vws-python-mock
9393

94-
.. testsetup:: testing
94+
.. invisible-code-block: python
95+
96+
# Reset test
97+
for i in list(globals().keys()):
98+
if not i.startswith('_'):
99+
exec('del ' + i)
100+
101+
.. invisible-code-block: python
95102
96103
import pathlib
97104
import shutil
@@ -104,7 +111,7 @@ To write unit tests for code which uses this library, without using your Vuforia
104111
new_image = pathlib.Path('high_quality_image.jpg')
105112
shutil.copy(image, new_image)
106113
107-
.. testcode:: testing
114+
.. code-block:: python
108115
109116
import pathlib
110117
@@ -135,7 +142,7 @@ To write unit tests for code which uses this library, without using your Vuforia
135142
active_flag=True,
136143
)
137144
138-
.. testcleanup:: testing
145+
.. invisible-code-block: python
139146
140147
new_image = pathlib.Path('high_quality_image.jpg')
141148
new_image.unlink()

lint.mk

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pip-missing-reqs:
4040

4141
.PHONY: pylint
4242
pylint:
43-
pylint src/ tests/ docs/
43+
pylint *.py src/ tests/ docs/
4444

4545
.PHONY: pyroma
4646
pyroma:
@@ -57,8 +57,3 @@ linkcheck:
5757
.PHONY: spelling
5858
spelling:
5959
$(MAKE) -C docs/ spelling SPHINXOPTS=$(SPHINXOPTS)
60-
61-
.PHONY: doctest
62-
doctest:
63-
$(MAKE) -C docs/ doctest SPHINXOPTS=$(SPHINXOPTS)
64-
pytest --codeblocks README.md

pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ strict = true
144144
[[tool.mypy.overrides]]
145145

146146
module = [
147-
"func_timeout",
148-
"func_timeout.exceptions"
147+
"func_timeout",
148+
"func_timeout.exceptions",
149+
"sybil",
150+
"sybil.parsers.rest",
149151
]
150152

151153
ignore_missing_imports = true
@@ -213,7 +215,7 @@ dynamic = ["version"]
213215
keywords = ["vuforia", "vws", "client"]
214216
license = { file = "LICENSE" }
215217
name = "vws-python"
216-
readme = { file = "README.md", content-type = "text/markdown"}
218+
readme = { file = "README.rst", content-type = "text/x-rst"}
217219
requires-python = ">=3.10"
218220
dependencies = [
219221
"VWS-Auth-Tools",
@@ -244,12 +246,12 @@ dev = [
244246
"pylint==2.17.0 ",
245247
"pyroma==4.2",
246248
"pytest-cov==4.0.0",
247-
"pytest_codeblocks==0.16.1",
248249
"pytest==7.2.2 ",
249250
"ruff==0.0.256",
250251
"sphinx-autodoc-typehints==1.22",
251252
"sphinx-prompt==1.5.0",
252253
"sphinxcontrib-spelling==8.0.0",
254+
"sybil==4.0.1",
253255
"types-freezegun==1.1.10",
254256
"types-requests==2.28.11.15",
255257
"vulture==2.7",

0 commit comments

Comments
 (0)