Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jul 16, 2023
1 parent 6df67c9 commit f6c70d1
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 23 deletions.
8 changes: 4 additions & 4 deletions docs/make_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ def write_examples(maker: ReadmeMaker) -> None:
maker.write_chapter("Check a filename")
maker.write_file(example_root.joinpath("is_valid_filename_code.txt"))

maker.write_chapter("filename/filepath validator for argparse")
maker.write_chapter("filename/filepath validator for ``argparse``")
maker.write_file(example_root.joinpath("argparse_validator.txt"))

maker.write_chapter("filename/filepath sanitizer for argparse")
maker.write_chapter("filename/filepath sanitizer for ``argparse``")
maker.write_file(example_root.joinpath("argparse_sanitizer.txt"))

maker.write_chapter("filename/filepath validator for click")
maker.write_chapter("filename/filepath validator for ``click``")
maker.write_file(example_root.joinpath("click_validator.txt"))

maker.write_chapter("filename/filepath sanitizer for click")
maker.write_chapter("filename/filepath sanitizer for ``click``")
maker.write_file(example_root.joinpath("click_sanitizer.txt"))

maker.write_chapter("For more information")
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/examples/argparse_validator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
from pathvalidate.argparse import validate_filename_arg, validate_filepath_arg

parser = ArgumentParser()
parser.add_argument("--filepath", type=validate_filepath_arg)
parser.add_argument("--filename", type=validate_filename_arg)
parser.add_argument("--filepath", type=validate_filepath_arg)
options = parser.parse_args()

if options.filename:
print("filename: {}".format(options.filename))
print(f"filename: {options.filename}")

if options.filepath:
print("filepath: {}".format(options.filepath))
print(f"filepath: {options.filepath}")

:Output:
.. code-block:: none

$ ./examples/argparse_validate.py --filename eg
filename: eg
$ ./examples/argparse_validate.py --filepath e?g
usage: argparse_validate.py [-h] [--filepath FILEPATH] [--filename FILENAME]
argparse_validate.py: error: argument --filepath: invalid char found: invalids=('?'), value='e?g', reason=INVALID_CHARACTER, target-platform=Windows
$ ./examples/argparse_validate.py --filename e?g
usage: argparse_validate.py [-h] [--filename FILENAME] [--filepath FILEPATH]
argparse_validate.py: error: argument --filename: [PV1100] invalid characters found: invalids=(':'), value='e:g', target-platform=Windows

.. note::
``validate_filepath_arg`` consider ``platform`` as of ``"auto"`` if the input is an absolute file path.
4 changes: 2 additions & 2 deletions docs/pages/examples/click.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
filename/filepath validator for click
filename/filepath validator for ``click``
--------------------------------------------------------
.. include:: click_validator.txt

filename/filepath sanitizer for click
filename/filepath sanitizer for ``click``
--------------------------------------------------------
.. include:: click_sanitizer.txt

4 changes: 2 additions & 2 deletions docs/pages/examples/click_sanitizer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@click.option("--filepath", callback=sanitize_filepath_arg)
def cli(filename, filepath):
if filename:
click.echo("filename: {}".format(filename))
click.echo(f"filename: {filename}")
if filepath:
click.echo("filepath: {}".format(filepath))
click.echo(f"filepath: {filepath}")


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions docs/pages/examples/click_validator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
@click.command()
@click.option("--filename", callback=validate_filename_arg)
@click.option("--filepath", callback=validate_filepath_arg)
def cli(filename, filepath):
def cli(filename: str, filepath: str) -> None:
if filename:
click.echo("filename: {}".format(filename))
click.echo(f"filename: {filename}")
if filepath:
click.echo("filepath: {}".format(filepath))
click.echo(f"filepath: {filepath}")


if __name__ == "__main__":
Expand All @@ -26,5 +26,6 @@
filename: ab
$ ./examples/click_validate.py --filepath e?g
Usage: click_validate.py [OPTIONS]
Try 'click_validate.py --help' for help.

Error: Invalid value for "--filepath": invalid char found: invalids=('?'), value='e?g', reason=INVALID_CHARACTER, target-platform=Windows
Error: Invalid value for '--filename': [PV1100] invalid characters found: invalids=('?'), value='e?g', target-platform=Windows
4 changes: 2 additions & 2 deletions docs/pages/examples/validate_filename_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
:Output:
.. code-block:: none

invalid char found: invalids=(':', '*', '/', '"', '?', '>', '|', '<'), value='fi:l*e/p"a?t>h|.t<xt', reason=INVALID_CHARACTER, target-platform=Windows
[PV1100] invalid characters found: target-platform=universal, description=invalids=('/'), value='fi:l*e/p"a?t>h|.t<xt'

'COM1' is a reserved name, reason=RESERVED_NAME, target-platform=universal
[PV1002] found a reserved name by a platform: 'COM1' is a reserved name, target-platform=universal, reusable_name=False
2 changes: 1 addition & 1 deletion docs/pages/examples/validate_filepath_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
:Output:
.. code-block:: none

invalid char found: invalids=(':', '*', '"', '?', '>', '|', '<'), value='fi:l*e/p"a?t>h|.t<xt', reason=INVALID_CHARACTER, target-platform=Windows
[PV1100] invalid characters found: invalids=(':', '*', '"', '?', '>', '|', '<'), value='fi:l*e/p"a?t>h|.t<xt', target-platform=Windows
2 changes: 1 addition & 1 deletion docs/pages/introduction/feature.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Features
- file path
- file name/path argument validator/sanitizer for ``argparse`` and ``click``
- Multi platform support:
- sanitize/validate file names/paths for a specific platform (``Linux``/``Windows``/``macOS``/``Posix``) or ``universal`` (platform independent)
- sanitize/validate file names/paths for a specific platform (``Linux``/``Windows``/``macOS``/``POSIX``) or ``universal`` (platform independent)
- Multibyte character support
2 changes: 1 addition & 1 deletion docs/pages/introduction/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Installation: apt

Dependencies
============
Python 3.6+
Python 3.7+
no external dependencies.
21 changes: 21 additions & 0 deletions docs/pages/reference/error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ Errors
:undoc-members:
:show-inheritance:

.. table:: Liar od Errors

+--------+------------------------+------------------------------------------------------+
| Code | Name | Description |
+========+========================+======================================================+
| PV1001 | NULL_NAME | the value must not be an empty |
+--------+------------------------+------------------------------------------------------+
| PV1002 | RESERVED_NAME | found a reserved name by a platform |
+--------+------------------------+------------------------------------------------------+
| PV1100 | INVALID_CHARACTER | invalid characters found |
+--------+------------------------+------------------------------------------------------+
| PV1101 | INVALID_LENGTH | found an invalid string length |
+--------+------------------------+------------------------------------------------------+
| PV1200 | FOUND_ABS_PATH | found an absolute path where must be a relative path |
+--------+------------------------+------------------------------------------------------+
| PV1201 | MALFORMED_ABS_PATH | found a malformed absolute path |
+--------+------------------------+------------------------------------------------------+
| PV2000 | INVALID_AFTER_SANITIZE | found invalid value after sanitizing |
+--------+------------------------+------------------------------------------------------+

.. autoexception:: pathvalidate.error.ValidationError
:members:
:undoc-members:
:show-inheritance:

0 comments on commit f6c70d1

Please sign in to comment.