Skip to content

Commit e79d75f

Browse files
authored
Merge pull request #344 from yozachar/workshop
maint: adds quick start docs
2 parents 110bd2f + dab6463 commit e79d75f

File tree

10 files changed

+209
-22
lines changed

10 files changed

+209
-22
lines changed

.github/workflows/docs.yaml.bkp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pip install .
2828
pip install -r package/requirements.mkdocs.txt
2929
- name: Build documentation
30-
run: python package/export docs
30+
run: python package/export doc
3131
# set up Pages
3232
- name: Set up Pages
3333
uses: actions/configure-pages@v4

docs/conf.py

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

3434
# -- Options for HTML output -------------------------------------------------
3535
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
36-
html_theme = "alabaster"
36+
html_theme = "furo"
37+
html_favicon = "./assets/icons/favicon.svg"
3738

3839
# -- Options for manpage generation -------------------------------------------------
3940
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-man_pages

docs/index.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ Resources
6363
.. toctree::
6464
:hidden:
6565
:maxdepth: 2
66-
:caption: Reference:
66+
:caption: Quick Start:
67+
:glob:
68+
69+
install_and_use
70+
71+
.. toctree::
72+
:hidden:
73+
:maxdepth: 2
74+
:caption: API Reference:
6775
:glob:
6876

6977
api/*

docs/install_and_use.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Install and Use
2+
3+
## Installation
4+
5+
Execute the following command:
6+
7+
```text
8+
pip install validators
9+
```
10+
11+
> It's preferable to use `pip` within a virtual environment.
12+
13+
## Usage
14+
15+
```python
16+
import validators
17+
print(validators.email('[email protected]'))
18+
```
19+
20+
### To raise validation error
21+
22+
1. Either set the environment variable `RAISE_VALIDATION_ERROR` to `True`
23+
24+
```console
25+
$ export RAISE_VALIDATION_ERROR=True
26+
$ python -c "from validators import url; print(url('https//bad_url'))"
27+
Traceback (most recent call last):
28+
File "<string>", line 1, in <module>
29+
File "/path/to/lib/validators/utils.py", line 87, in wrapper
30+
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
31+
validators.utils.ValidationError: ValidationError(func=url, args={'value': 'https//bad_url'})
32+
```
33+
34+
2. Or pass `r_ve=True` to each caller function:
35+
36+
```console
37+
$ python -c "from validators.card import visa; print(visa('bad_visa_number', r_ve=True))"
38+
Traceback (most recent call last):
39+
File "<string>", line 1, in <module>
40+
File "/path/to/lib/validators/utils.py", line 87, in wrapper
41+
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
42+
validators.utils.ValidationError: ValidationError(func=visa, args={'value': 'bad_visa_number'})
43+
```

docs/install_and_use.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Install and Use
2+
===============
3+
4+
Installation
5+
------------
6+
7+
Execute the following command:
8+
9+
.. code:: text
10+
11+
pip install validators
12+
13+
..
14+
15+
It's preferable to use ``pip`` within a virtual environment.
16+
17+
Usage
18+
-----
19+
20+
.. code:: python
21+
22+
import validators
23+
print(validators.email('[email protected]'))
24+
25+
To raise validation error
26+
~~~~~~~~~~~~~~~~~~~~~~~~~
27+
28+
1. Either set the environment variable ``RAISE_VALIDATION_ERROR`` to
29+
``True``
30+
31+
.. code:: console
32+
33+
$ export RAISE_VALIDATION_ERROR=True
34+
$ python -c "from validators import url; print(url('https//bad_url'))"
35+
Traceback (most recent call last):
36+
File "<string>", line 1, in <module>
37+
File "/path/to/lib/validators/utils.py", line 87, in wrapper
38+
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
39+
validators.utils.ValidationError: ValidationError(func=url, args={'value': 'https//bad_url'})
40+
41+
2. Or pass ``r_ve=True`` to each caller function:
42+
43+
.. code:: console
44+
45+
$ python -c "from validators.card import visa; print(visa('bad_visa_number', r_ve=True))"
46+
Traceback (most recent call last):
47+
File "<string>", line 1, in <module>
48+
File "/path/to/lib/validators/utils.py", line 87, in wrapper
49+
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
50+
validators.utils.ValidationError: ValidationError(func=visa, args={'value': 'bad_visa_number'})

mkdocs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ theme:
1515
font:
1616
text: Inter
1717
code: "Fira Code"
18+
features:
19+
- content.code.copy
1820
palette:
1921
- media: "(prefers-color-scheme: light)"
2022
scheme: default
@@ -65,6 +67,7 @@ copyright: Copyright &copy; 2013 - 2024 Konsta Vesterinen
6567

6668
nav:
6769
- Home: index.md
70+
- Install and Use: install_and_use.md
6871
- API:
6972
- api/between.md
7073
- api/btc_address.md

package/export/__main__.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from os import getenv
66
from os.path import getsize
77
from pathlib import Path
8-
from shutil import copy, rmtree
8+
from shutil import copy
99
from subprocess import Popen # nosec
1010

1111

@@ -71,10 +71,24 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
7171
+ "\n\n.. toctree::"
7272
+ "\n :hidden:"
7373
+ "\n :maxdepth: 2"
74-
+ "\n :caption: Reference:"
74+
+ "\n :caption: Quick Start:"
75+
+ "\n :glob:\n"
76+
+ "\n install_and_use"
77+
+ "\n\n.. toctree::"
78+
+ "\n :hidden:"
79+
+ "\n :maxdepth: 2"
80+
+ "\n :caption: API Reference:"
7581
+ "\n :glob:\n"
7682
+ "\n api/*\n"
7783
)
84+
85+
with open(source / "docs/install_and_use.rst", "wt") as iau_f:
86+
iau_f.write(
87+
convert_file(source_file=source / "docs/install_and_use.md", format="md", to="rst")
88+
.replace("\r\n", "\n") # remove carriage return in windows
89+
.replace("’", "'")
90+
)
91+
7892
# generate rST reference documentation
7993
for module_name, aliases in _parse_package(source / "src/validators/__init__.py"):
8094
for alias in aliases:
@@ -85,6 +99,7 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
8599
web_build = Popen(("sphinx-build", "docs", "docs/_build/web"), shell=False) # nosec
86100
web_build.communicate()
87101
exit_code = web_build.returncode
102+
print("Run `python -m http.server -d docs/_build/web` to preview.")
88103
if not only_web:
89104
# build sphinx man pages as subprocess
90105
man_build = Popen( # nosec
@@ -102,7 +117,6 @@ def _generate_documentation(
102117
only_md: bool = False,
103118
only_rst_web: bool = False,
104119
only_rst_man: bool = False,
105-
discard_refs: bool = True,
106120
):
107121
"""Generate documentation."""
108122
if only_md is only_rst_web is only_rst_man is True:
@@ -123,16 +137,12 @@ def _generate_documentation(
123137
if exit_code == 0
124138
else exit_code
125139
)
126-
# optionally discard reference folder
127-
if discard_refs:
128-
rmtree(refs_path)
129140
return exit_code
130141

131142

132143
def package(source: Path):
133144
"""Package the source code."""
134-
_generate_documentation(source, only_rst_man=True, discard_refs=False)
135-
# print()
145+
_generate_documentation(source, only_rst_man=True)
136146
if getenv("CI", "false") == "true":
137147
process = Popen(("./.venv/bin/python", "-m", "build"), shell=False) # nosec
138148
else:
@@ -149,18 +159,17 @@ def package(source: Path):
149159
from sys import argv
150160

151161
if len(argv) != 2:
152-
quit(exit_code)
162+
print("Expected one of these augments: `pkg` `doc` `man` or `web`")
163+
quit(1)
153164

154165
if argv[1] == "pkg":
155166
exit_code = package(project_root)
156-
if argv[1] == "docs":
157-
exit_code = _generate_documentation(
158-
project_root,
159-
only_md=True,
160-
only_rst_web=False,
161-
only_rst_man=False,
162-
discard_refs=False,
163-
)
167+
elif argv[1] == "doc":
168+
exit_code = _generate_documentation(project_root, only_md=True)
169+
elif argv[1] == "man":
170+
exit_code = _generate_documentation(project_root, only_rst_man=True)
171+
elif argv[1] == "web":
172+
exit_code = _generate_documentation(project_root, only_rst_web=True)
164173
quit(exit_code)
165174

166175
# TODO: Address all '# nosec'

package/requirements.sphinx.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ alabaster==0.7.13 \
77
babel==2.14.0 \
88
--hash=sha256:6919867db036398ba21eb5c7a0f6b28ab8cbc3ae7a73a44ebe34ae74a4e7d363 \
99
--hash=sha256:efb1a25b7118e67ce3a259bed20545c29cb68be8ad2c784c83689981b7a57287
10+
beautifulsoup4==4.12.3 \
11+
--hash=sha256:74e3d1928edc070d21748185c46e3fb33490f22f52a3addee9aee0f4f7781051 \
12+
--hash=sha256:b80878c9f40111313e55da8ba20bdba06d8fa3969fc68304167741bbf9e082ed
1013
certifi==2024.2.2 \
1114
--hash=sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f \
1215
--hash=sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1
@@ -94,6 +97,9 @@ colorama==0.4.6 \
9497
docutils==0.20.1 \
9598
--hash=sha256:96f387a2c5562db4476f09f13bbab2192e764cac08ebbf3a34a95d9b1e4a59d6 \
9699
--hash=sha256:f08a4e276c3a1583a86dce3e34aba3fe04d02bba2dd51ed16106244e8a923e3b
100+
furo==2024.1.29 \
101+
--hash=sha256:3548be2cef45a32f8cdc0272d415fcb3e5fa6a0eb4ddfe21df3ecf1fe45a13cf \
102+
--hash=sha256:4d6b2fe3f10a6e36eb9cc24c1e7beb38d7a23fc7b3c382867503b7fcac8a1e02
97103
idna==3.6 \
98104
--hash=sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca \
99105
--hash=sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f
@@ -233,9 +239,15 @@ requests==2.31.0 \
233239
snowballstemmer==2.2.0 \
234240
--hash=sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1 \
235241
--hash=sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a
242+
soupsieve==2.5 \
243+
--hash=sha256:5663d5a7b3bfaeee0bc4372e7fc48f9cff4940b3eec54a6451cc5299f1097690 \
244+
--hash=sha256:eaa337ff55a1579b6549dc679565eac1e3d000563bcb1c8ab0d0fefbc0c2cdc7
236245
sphinx==7.1.2 \
237246
--hash=sha256:780f4d32f1d7d1126576e0e5ecc19dc32ab76cd24e950228dcf7b1f6d3d9e22f \
238247
--hash=sha256:d170a81825b2fcacb6dfd5a0d7f578a053e45d3f2b153fecc948c37344eb4cbe
248+
sphinx-basic-ng==1.0.0b2 \
249+
--hash=sha256:9ec55a47c90c8c002b5960c57492ec3021f5193cb26cebc2dc4ea226848651c9 \
250+
--hash=sha256:eb09aedbabfb650607e9b4b68c9d240b90b1e1be221d6ad71d61c52e29f7932b
239251
sphinxcontrib-applehelp==1.0.4 \
240252
--hash=sha256:29d341f67fb0f6f586b23ad80e072c8e6ad0b48417db2bde114a4c9746feb228 \
241253
--hash=sha256:828f867945bbe39817c210a1abfd1bc4895c8b73fcaade56d45357a348a07d7e

pdm.lock

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ Changelog = "https://github.com/python-validators/validators/blob/master/CHANGES
5454
##############################
5555

5656
[tool.pdm.dev-dependencies]
57-
docs-offline = ["myst-parser>=2.0.0", "pypandoc-binary>=1.13", "sphinx>=7.1.2"]
57+
docs-offline = [
58+
"myst-parser>=2.0.0",
59+
"pypandoc-binary>=1.13",
60+
"sphinx>=7.1.2",
61+
"furo>=2024.1.29",
62+
]
5863
docs-online = [
5964
"mkdocs>=1.5.3",
6065
"mkdocs-git-revision-date-localized-plugin>=1.2.4",

0 commit comments

Comments
 (0)