From c20e9253c4721d3ecafde849136e64a9303831d3 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 20:48:15 -0300 Subject: [PATCH 01/13] Add python docstring --- fluent_validator/validators/type_validator.py | 34 ++++- .../validators/value_validator.py | 119 +++++++++++++++--- 2 files changed, 131 insertions(+), 22 deletions(-) diff --git a/fluent_validator/validators/type_validator.py b/fluent_validator/validators/type_validator.py index 77435b6..f7488e8 100644 --- a/fluent_validator/validators/type_validator.py +++ b/fluent_validator/validators/type_validator.py @@ -4,20 +4,42 @@ class TypeValidator(BaseValidator): - def _is_instance(self, *args) -> bool: + def _is_instance(self, *args): + """ + Check if the object is an instance of one or more specified types. + + Args: + *args: One or more types to check against. + """ + return isinstance(self.obj, args) - def _is_callable(self) -> bool: + def _is_callable(self): + """ + Check if the object is callable (e.g., a function or method). + """ return callable(self.obj) - def _is_iterable(self) -> bool: + def _is_iterable(self): + """ + Check if the object is iterable. + """ return self._is_instance(Iterable) - def _is_string(self) -> bool: + def _is_string(self): + """ + Check if the object is a string. + """ return self._is_instance(str) - def _is_number(self) -> bool: + def _is_number(self): + """ + Check if the object is a number (int or float). + """ return self._is_instance(int, float) - def _is_bool(self) -> bool: + def _is_bool(self): + """ + Check if the object is a boolean. + """ return self._is_instance(bool) diff --git a/fluent_validator/validators/value_validator.py b/fluent_validator/validators/value_validator.py index 9d0f34d..c2bd039 100644 --- a/fluent_validator/validators/value_validator.py +++ b/fluent_validator/validators/value_validator.py @@ -2,50 +2,137 @@ class ValueValidator(TypeValidator): - def _equal(self, value) -> bool: + def _equal(self, value): + """ + Check if the object is equal to the specified value. + + Args: + value: The value to compare with. + """ return self.obj == value - def _is_in(self, *args) -> bool: + def _is_in(self, *args): + """ + Check if the object is in a collection of values. + + Args: + *args: Values to check for containment. + """ return self.obj in args - def _greater_than(self, value) -> bool: + def _greater_than(self, value): + """ + Check if the object is greater than the specified value. + + Args: + value: The value to compare with. + """ return self.obj > value - def _less_than(self, value) -> bool: + def _less_than(self, value): + """ + Check if the object is less than the specified value. + + Args: + value: The value to compare with. + """ return self.obj < value - def _greater_or_equal_than(self, value) -> bool: + def _greater_or_equal_than(self, value): + """ + Check if the object is greater than or equal to the specified value. + + Args: + value: The value to compare with. + """ return self.obj >= value - def _less_or_equal_than(self, value) -> bool: + def _less_or_equal_than(self, value): + """ + Check if the object is less than or equal to the specified value. + + Args: + value: The value to compare with. + """ return self.obj <= value - def _min(self, value) -> bool: + def _min(self, value): + """ + Check if the object is greater than or equal to the specified minimum value. + + Args: + value: The minimum value to compare with. + """ return self._greater_or_equal_than(value) - def _max(self, value) -> bool: + def _max(self, value): + """ + Check if the object is less than or equal to the specified maximum value. + + Args: + value: The maximum value to compare with. + """ return self._less_or_equal_than(value) - def _between(self, min, max) -> bool: + def _between(self, min, max): + """ + Check if the object is within the specified range. + + Args: + min: The minimum value of the range. + max: The maximum value of the range. + """ return self._min(min) and self._max(max) - def _is_true(self) -> bool: + def _is_true(self): + """ + Check if the object is a boolean and has a value of True. + """ return self._is_bool() and self.obj is True - def _is_false(self) -> bool: + def _is_false(self): + """ + Check if the object is a boolean and has a value of False. + """ return self._is_bool() and self.obj is False - def _contains_at_least(self, value) -> bool: + def _contains_at_least(self, value): + """ + Check if the object (assumed to be iterable) contains at least the specified number of elements. + + Args: + value: The minimum number of elements to check for. + """ return len(self.obj) >= value - def _contains_at_most(self, value) -> bool: + def _contains_at_most(self, value): + """ + Check if the object (assumed to be iterable) contains at most the specified number of elements. + + Args: + value: The maximum number of elements to check for. + """ return len(self.obj) <= value - def _contains_exactly(self, value) -> bool: + def _contains_exactly(self, value): + """ + Check if the object (assumed to be iterable) contains exactly the specified number of elements. + + Args: + value: The exact number of elements to check for. + """ return len(self.obj) == value - def _is_none(self) -> bool: + def _is_none(self): + """ + Check if the object is None. + """ return self.obj is None - def _has_unique_values(self) -> bool: + def _has_unique_values(self): + """ + Check if the object (assumed to be iterable) contains unique values. + + Note: This function assumes that the object's elements are hashable. + """ return len(self.obj) == len(set(self.obj)) From 76b6e0b2a2568de6e948ca1fcde26f9b901863b6 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 21:28:08 -0300 Subject: [PATCH 02/13] Generate docs from docsstring --- fluent_validator/validators/type_validator.py | 3 -- .../validators/value_validator.py | 53 +++---------------- scripts/generate_docs.py | 36 +++++++++++++ 3 files changed, 44 insertions(+), 48 deletions(-) create mode 100644 scripts/generate_docs.py diff --git a/fluent_validator/validators/type_validator.py b/fluent_validator/validators/type_validator.py index f7488e8..791e200 100644 --- a/fluent_validator/validators/type_validator.py +++ b/fluent_validator/validators/type_validator.py @@ -7,9 +7,6 @@ class TypeValidator(BaseValidator): def _is_instance(self, *args): """ Check if the object is an instance of one or more specified types. - - Args: - *args: One or more types to check against. """ return isinstance(self.obj, args) diff --git a/fluent_validator/validators/value_validator.py b/fluent_validator/validators/value_validator.py index c2bd039..76389e0 100644 --- a/fluent_validator/validators/value_validator.py +++ b/fluent_validator/validators/value_validator.py @@ -5,82 +5,54 @@ class ValueValidator(TypeValidator): def _equal(self, value): """ Check if the object is equal to the specified value. - - Args: - value: The value to compare with. """ return self.obj == value - def _is_in(self, *args): + def _is_in(self, *values): """ Check if the object is in a collection of values. - - Args: - *args: Values to check for containment. """ - return self.obj in args + return self.obj in values def _greater_than(self, value): """ Check if the object is greater than the specified value. - - Args: - value: The value to compare with. """ return self.obj > value def _less_than(self, value): """ Check if the object is less than the specified value. - - Args: - value: The value to compare with. """ return self.obj < value def _greater_or_equal_than(self, value): """ Check if the object is greater than or equal to the specified value. - - Args: - value: The value to compare with. """ return self.obj >= value def _less_or_equal_than(self, value): """ Check if the object is less than or equal to the specified value. - - Args: - value: The value to compare with. """ return self.obj <= value def _min(self, value): """ Check if the object is greater than or equal to the specified minimum value. - - Args: - value: The minimum value to compare with. """ return self._greater_or_equal_than(value) def _max(self, value): """ Check if the object is less than or equal to the specified maximum value. - - Args: - value: The maximum value to compare with. """ return self._less_or_equal_than(value) def _between(self, min, max): """ Check if the object is within the specified range. - - Args: - min: The minimum value of the range. - max: The maximum value of the range. """ return self._min(min) and self._max(max) @@ -96,32 +68,23 @@ def _is_false(self): """ return self._is_bool() and self.obj is False - def _contains_at_least(self, value): + def _contains_at_least(self, num_of_min_elements): """ Check if the object (assumed to be iterable) contains at least the specified number of elements. - - Args: - value: The minimum number of elements to check for. """ - return len(self.obj) >= value + return len(self.obj) >= num_of_min_elements - def _contains_at_most(self, value): + def _contains_at_most(self, num_of_max_elements): """ Check if the object (assumed to be iterable) contains at most the specified number of elements. - - Args: - value: The maximum number of elements to check for. """ - return len(self.obj) <= value + return len(self.obj) <= num_of_max_elements - def _contains_exactly(self, value): + def _contains_exactly(self, num_of_elements): """ Check if the object (assumed to be iterable) contains exactly the specified number of elements. - - Args: - value: The exact number of elements to check for. """ - return len(self.obj) == value + return len(self.obj) == num_of_elements def _is_none(self): """ diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py new file mode 100644 index 0000000..087b4f8 --- /dev/null +++ b/scripts/generate_docs.py @@ -0,0 +1,36 @@ +import ast +import glob +import os + + +def extract_validators_docs(filename): + with open(filename, "r", encoding="utf-8") as file: + tree = ast.parse(file.read()) + + for node in ast.walk(tree): + if isinstance(node, ast.FunctionDef): + docstring = ast.get_docstring(node) + if docstring: + docstring = [ + line.strip() for line in docstring.split("\n") if line.strip() != "" + ] + docstring = "\n".join(docstring) + + method_name = node.name.strip("_") + args = [arg.arg for arg in node.args.args if arg.arg != "self"] + yield f"**{method_name}({', '.join(args)})** {docstring}" + + +def main(): + project_dir = os.path.join(os.path.dirname(__file__), "..") + validators_dir = os.path.join(project_dir, "fluent_validator", "validators") + output_file = os.path.join(project_dir, "validators.md") + + with open(output_file, "w", encoding="utf-8") as out: + for file in glob.glob(os.path.join(validators_dir, "*.py")): + for validator_doc in extract_validators_docs(file): + out.write(f"{validator_doc}\n") + + +if __name__ == "__main__": + main() From 90d69795fc60d9f9be7a11cfdebb18b7f998c123 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:34:43 -0300 Subject: [PATCH 03/13] Generate template --- README.md | 80 +++++++++++++++++++++++++++++++++++++++- scripts/generate_docs.py | 75 ++++++++++++++++++++++++++++++++++--- tests/validator_test.py | 2 +- 3 files changed, 150 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 239b23d..91a5fe7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,81 @@ + # fluent_validator -Package to validate data in a fluent way +**Validate Your Data with Ease!** + +[![GitHub stars](https://img.shields.io/github/stars/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/network) +[![GitHub issues](https://img.shields.io/github/issues/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/issues) +[![GitHub license](https://img.shields.io/github/license/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/blob/main/LICENSE) + +## Overview + +`fluent_validator` is a Python package that makes data validation a breeze! Say goodbye to complex, nested if statements and hello to a fluent and expressive way to validate your data. With `fluent_validator`, you can easily define and execute validation rules for your data in a clean and readable manner. + +## Features + +- **Fluent Syntax**: Define validation rules in a clean and fluent manner. +- **No Extra Dependencies**: `fluent_validator` is lightweight and doesn't require any additional packages. +- **Python 3.7+ Support**: It works seamlessly with Python versions 3.7, 3.8, 3.9, 3.10, and 3.11. +- **Extensive Validation Library**: Check out our extensive list of available validations to cover all your validation needs. + +## Installation + +You can install `fluent_validator` using pip: + +```bash +pip install fluent_validator +```` + +## Usage + +Here's a quick example of how to use `fluent_validator`: + +```python +from fluent_validator import validate, validate_all + +# Validate a single value +validate(10).not_is_none().greater_than(5).not_equal(40) + +# Or validate multiple values +validate_all(10, 100).not_is_none().greater_than(5).not_equal(40) +``` + +## Available Validations + +`fluent_validator` offers a wide range of validations to suit your needs. Check out the full list of available above. +Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. For example, the negative of `is_none()` is `not_is_none()`. This allows you to easily express and handle both affirmative and negative validation scenarios with clarity and precision. + +**equal(value)** Check if the object is equal to the specified value. +**is_in()** Check if the object is in a collection of values. +**greater_than(value)** Check if the object is greater than the specified value. +**less_than(value)** Check if the object is less than the specified value. +**greater_or_equal_than(value)** Check if the object is greater than or equal to the specified value. +**less_or_equal_than(value)** Check if the object is less than or equal to the specified value. +**min(value)** Check if the object is greater than or equal to the specified minimum value. +**max(value)** Check if the object is less than or equal to the specified maximum value. +**between(min, max)** Check if the object is within the specified range. +**is_true()** Check if the object is a boolean and has a value of True. +**is_false()** Check if the object is a boolean and has a value of False. +**contains_at_least(num_of_min_elements)** Check if the object (assumed to be iterable) contains at least the specified number of elements. +**contains_at_most(num_of_max_elements)** Check if the object (assumed to be iterable) contains at most the specified number of elements. +**contains_exactly(num_of_elements)** Check if the object (assumed to be iterable) contains exactly the specified number of elements. +**is_none()** Check if the object is None. +**has_unique_values()** Check if the object (assumed to be iterable) contains unique values. +Note: This function assumes that the object's elements are hashable. +**is_instance()** Check if the object is an instance of one or more specified types. +**is_callable()** Check if the object is callable (e.g., a function or method). +**is_iterable()** Check if the object is iterable. +**is_string()** Check if the object is a string. +**is_number()** Check if the object is a number (int or float). +**is_bool()** Check if the object is a boolean. + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Support + +If you encounter any issues or have questions about `fluent_validator`, please feel free to [open an issue](https://github.com/mariotaddeucci/fluent_validator/issues). We're here to help! + +Happy Validating! 🚀 diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 087b4f8..1a5be1a 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -2,6 +2,67 @@ import glob import os +TEMPLATE = """ +# fluent_validator + +**Validate Your Data with Ease!** + +[![GitHub stars](https://img.shields.io/github/stars/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/network) +[![GitHub issues](https://img.shields.io/github/issues/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/issues) +[![GitHub license](https://img.shields.io/github/license/mariotaddeucci/fluent_validator.svg?style=flat-square)](https://github.com/mariotaddeucci/fluent_validator/blob/main/LICENSE) + +## Overview + +`fluent_validator` is a Python package that makes data validation a breeze! Say goodbye to complex, nested if statements and hello to a fluent and expressive way to validate your data. With `fluent_validator`, you can easily define and execute validation rules for your data in a clean and readable manner. + +## Features + +- **Fluent Syntax**: Define validation rules in a clean and fluent manner. +- **No Extra Dependencies**: `fluent_validator` is lightweight and doesn't require any additional packages. +- **Python 3.7+ Support**: It works seamlessly with Python versions 3.7, 3.8, 3.9, 3.10, and 3.11. +- **Extensive Validation Library**: Check out our extensive list of available validations to cover all your validation needs. + +## Installation + +You can install `fluent_validator` using pip: + +```bash +pip install fluent_validator +```` + +## Usage + +Here's a quick example of how to use `fluent_validator`: + +```python +from fluent_validator import validate, validate_all + +# Validate a single value +validate(10).not_is_none().greater_than(5).not_equal(40) + +# Or validate multiple values +validate_all(10, 100).not_is_none().greater_than(5).not_equal(40) +``` + +## Available Validations + +`fluent_validator` offers a wide range of validations to suit your needs. Check out the full list of available above. +Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. For example, the negative of `is_none()` is `not_is_none()`. This allows you to easily express and handle both affirmative and negative validation scenarios with clarity and precision. + +{{ validation_list }} + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Support + +If you encounter any issues or have questions about `fluent_validator`, please feel free to [open an issue](https://github.com/mariotaddeucci/fluent_validator/issues). We're here to help! + +Happy Validating! 🚀 +""" + def extract_validators_docs(filename): with open(filename, "r", encoding="utf-8") as file: @@ -24,12 +85,16 @@ def extract_validators_docs(filename): def main(): project_dir = os.path.join(os.path.dirname(__file__), "..") validators_dir = os.path.join(project_dir, "fluent_validator", "validators") - output_file = os.path.join(project_dir, "validators.md") + output_file = os.path.join(project_dir, "README.md") + + validation_list = "\n".join( + validator_doc.strip() + for file in glob.glob(os.path.join(validators_dir, "*.py")) + for validator_doc in extract_validators_docs(file) + ) - with open(output_file, "w", encoding="utf-8") as out: - for file in glob.glob(os.path.join(validators_dir, "*.py")): - for validator_doc in extract_validators_docs(file): - out.write(f"{validator_doc}\n") + with open(output_file, "w", encoding="utf-8") as file: + file.write(TEMPLATE.replace("{{ validation_list }}", validation_list)) if __name__ == "__main__": diff --git a/tests/validator_test.py b/tests/validator_test.py index df0c61c..abc8a6b 100644 --- a/tests/validator_test.py +++ b/tests/validator_test.py @@ -4,7 +4,7 @@ def test_chained_validation(): - validate(True).is_true().not_is_false().not_is_none() + validate(10).not_is_none().greater_than(5).not_equal(40) with pytest.raises(ValueError): validate(True).is_false() From 9a74efc08c13007081ba55236887f2581af08b7d Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:38:44 -0300 Subject: [PATCH 04/13] Generate template --- README.md | 56 ++++++++++++++++++++++------------------ scripts/generate_docs.py | 13 +++++++--- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 91a5fe7..459790f 100644 --- a/README.md +++ b/README.md @@ -43,32 +43,38 @@ validate_all(10, 100).not_is_none().greater_than(5).not_equal(40) ## Available Validations -`fluent_validator` offers a wide range of validations to suit your needs. Check out the full list of available above. -Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. For example, the negative of `is_none()` is `not_is_none()`. This allows you to easily express and handle both affirmative and negative validation scenarios with clarity and precision. - -**equal(value)** Check if the object is equal to the specified value. -**is_in()** Check if the object is in a collection of values. -**greater_than(value)** Check if the object is greater than the specified value. -**less_than(value)** Check if the object is less than the specified value. -**greater_or_equal_than(value)** Check if the object is greater than or equal to the specified value. -**less_or_equal_than(value)** Check if the object is less than or equal to the specified value. -**min(value)** Check if the object is greater than or equal to the specified minimum value. -**max(value)** Check if the object is less than or equal to the specified maximum value. -**between(min, max)** Check if the object is within the specified range. -**is_true()** Check if the object is a boolean and has a value of True. -**is_false()** Check if the object is a boolean and has a value of False. -**contains_at_least(num_of_min_elements)** Check if the object (assumed to be iterable) contains at least the specified number of elements. -**contains_at_most(num_of_max_elements)** Check if the object (assumed to be iterable) contains at most the specified number of elements. -**contains_exactly(num_of_elements)** Check if the object (assumed to be iterable) contains exactly the specified number of elements. -**is_none()** Check if the object is None. -**has_unique_values()** Check if the object (assumed to be iterable) contains unique values. +`fluent_validator` offers a wide range of validations to suit your needs. + +Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. + +For example, the negative of `is_none()` is `not_is_none()`. + +Check out the full list of available above. + +`equal(value)` Check if the object is equal to the specified value. +`is_in()` Check if the object is in a collection of values. +`greater_than(value)` Check if the object is greater than the specified value. +`less_than(value)` Check if the object is less than the specified value. +`greater_or_equal_than(value)` Check if the object is greater than or equal to the specified value. +`less_or_equal_than(value)` Check if the object is less than or equal to the specified value. +`min(value)` Check if the object is greater than or equal to the specified minimum value. +`max(value)` Check if the object is less than or equal to the specified maximum value. +`between(min, max)` Check if the object is within the specified range. +`is_true()` Check if the object is a boolean and has a value of True. +`is_false()` Check if the object is a boolean and has a value of False. +`contains_at_least(num_of_min_elements)` Check if the object (assumed to be iterable) contains at least the specified number of elements. +`contains_at_most(num_of_max_elements)` Check if the object (assumed to be iterable) contains at most the specified number of elements. +`contains_exactly(num_of_elements)` Check if the object (assumed to be iterable) contains exactly the specified number of elements. +`is_none()` Check if the object is None. +`has_unique_values()` Check if the object (assumed to be iterable) contains unique values. + Note: This function assumes that the object's elements are hashable. -**is_instance()** Check if the object is an instance of one or more specified types. -**is_callable()** Check if the object is callable (e.g., a function or method). -**is_iterable()** Check if the object is iterable. -**is_string()** Check if the object is a string. -**is_number()** Check if the object is a number (int or float). -**is_bool()** Check if the object is a boolean. +`is_instance()` Check if the object is an instance of one or more specified types. +`is_callable()` Check if the object is callable (e.g., a function or method). +`is_iterable()` Check if the object is iterable. +`is_string()` Check if the object is a string. +`is_number()` Check if the object is a number (int or float). +`is_bool()` Check if the object is a boolean. ## License diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 1a5be1a..3e710df 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -47,8 +47,13 @@ ## Available Validations -`fluent_validator` offers a wide range of validations to suit your needs. Check out the full list of available above. -Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. For example, the negative of `is_none()` is `not_is_none()`. This allows you to easily express and handle both affirmative and negative validation scenarios with clarity and precision. +`fluent_validator` offers a wide range of validations to suit your needs. + +Notably, all validations have a corresponding negative form. Simply prefix the method with `not_`. + +For example, the negative of `is_none()` is `not_is_none()`. + +Check out the full list of available above. {{ validation_list }} @@ -75,11 +80,11 @@ def extract_validators_docs(filename): docstring = [ line.strip() for line in docstring.split("\n") if line.strip() != "" ] - docstring = "\n".join(docstring) + docstring = "\n\n".join(docstring) method_name = node.name.strip("_") args = [arg.arg for arg in node.args.args if arg.arg != "self"] - yield f"**{method_name}({', '.join(args)})** {docstring}" + yield f"`{method_name}({', '.join(args)})` {docstring}" def main(): From 0e5e7c1932e2f18e95dfdb4e91bf216093f88ff5 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:40:05 -0300 Subject: [PATCH 05/13] Generate template --- scripts/generate_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 3e710df..48ad687 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -53,7 +53,7 @@ For example, the negative of `is_none()` is `not_is_none()`. -Check out the full list of available above. +### Check out the full list of available above. {{ validation_list }} @@ -92,7 +92,7 @@ def main(): validators_dir = os.path.join(project_dir, "fluent_validator", "validators") output_file = os.path.join(project_dir, "README.md") - validation_list = "\n".join( + validation_list = "\n\n".join( validator_doc.strip() for file in glob.glob(os.path.join(validators_dir, "*.py")) for validator_doc in extract_validators_docs(file) From c135c126255635a8fbe36ffd3ddd7d0213c01c28 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:40:50 -0300 Subject: [PATCH 06/13] Generate template --- README.md | 44 +++++++++++++++++++++++++++++++++++++++- scripts/generate_docs.py | 2 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 459790f..80abee8 100644 --- a/README.md +++ b/README.md @@ -49,31 +49,73 @@ Notably, all validations have a corresponding negative form. Simply prefix the m For example, the negative of `is_none()` is `not_is_none()`. -Check out the full list of available above. +### Check out the full list of available above. `equal(value)` Check if the object is equal to the specified value. + + `is_in()` Check if the object is in a collection of values. + + `greater_than(value)` Check if the object is greater than the specified value. + + `less_than(value)` Check if the object is less than the specified value. + + `greater_or_equal_than(value)` Check if the object is greater than or equal to the specified value. + + `less_or_equal_than(value)` Check if the object is less than or equal to the specified value. + + `min(value)` Check if the object is greater than or equal to the specified minimum value. + + `max(value)` Check if the object is less than or equal to the specified maximum value. + + `between(min, max)` Check if the object is within the specified range. + + `is_true()` Check if the object is a boolean and has a value of True. + + `is_false()` Check if the object is a boolean and has a value of False. + + `contains_at_least(num_of_min_elements)` Check if the object (assumed to be iterable) contains at least the specified number of elements. + + `contains_at_most(num_of_max_elements)` Check if the object (assumed to be iterable) contains at most the specified number of elements. + + `contains_exactly(num_of_elements)` Check if the object (assumed to be iterable) contains exactly the specified number of elements. + + `is_none()` Check if the object is None. + + `has_unique_values()` Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. + + `is_instance()` Check if the object is an instance of one or more specified types. + + `is_callable()` Check if the object is callable (e.g., a function or method). + + `is_iterable()` Check if the object is iterable. + + `is_string()` Check if the object is a string. + + `is_number()` Check if the object is a number (int or float). + + `is_bool()` Check if the object is a boolean. ## License diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 48ad687..c69535a 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -92,7 +92,7 @@ def main(): validators_dir = os.path.join(project_dir, "fluent_validator", "validators") output_file = os.path.join(project_dir, "README.md") - validation_list = "\n\n".join( + validation_list = "\n\n\n".join( validator_doc.strip() for file in glob.glob(os.path.join(validators_dir, "*.py")) for validator_doc in extract_validators_docs(file) From 6daec74377b5b2b3a1076262ce909825fbae58a6 Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:44:08 -0300 Subject: [PATCH 07/13] Generate template --- README.md | 84 ++++++++++------------------------------ scripts/generate_docs.py | 2 +- 2 files changed, 22 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 80abee8..0f5179f 100644 --- a/README.md +++ b/README.md @@ -51,71 +51,29 @@ For example, the negative of `is_none()` is `not_is_none()`. ### Check out the full list of available above. -`equal(value)` Check if the object is equal to the specified value. - - -`is_in()` Check if the object is in a collection of values. - - -`greater_than(value)` Check if the object is greater than the specified value. - - -`less_than(value)` Check if the object is less than the specified value. - - -`greater_or_equal_than(value)` Check if the object is greater than or equal to the specified value. - - -`less_or_equal_than(value)` Check if the object is less than or equal to the specified value. - - -`min(value)` Check if the object is greater than or equal to the specified minimum value. - - -`max(value)` Check if the object is less than or equal to the specified maximum value. - - -`between(min, max)` Check if the object is within the specified range. - - -`is_true()` Check if the object is a boolean and has a value of True. - - -`is_false()` Check if the object is a boolean and has a value of False. - - -`contains_at_least(num_of_min_elements)` Check if the object (assumed to be iterable) contains at least the specified number of elements. - - -`contains_at_most(num_of_max_elements)` Check if the object (assumed to be iterable) contains at most the specified number of elements. - - -`contains_exactly(num_of_elements)` Check if the object (assumed to be iterable) contains exactly the specified number of elements. - - -`is_none()` Check if the object is None. - - +`equal(value)` Check if the object is equal to the specified value.\ +`is_in()` Check if the object is in a collection of values.\ +`greater_than(value)` Check if the object is greater than the specified value.\ +`less_than(value)` Check if the object is less than the specified value.\ +`greater_or_equal_than(value)` Check if the object is greater than or equal to the specified value.\ +`less_or_equal_than(value)` Check if the object is less than or equal to the specified value.\ +`min(value)` Check if the object is greater than or equal to the specified minimum value.\ +`max(value)` Check if the object is less than or equal to the specified maximum value.\ +`between(min, max)` Check if the object is within the specified range.\ +`is_true()` Check if the object is a boolean and has a value of True.\ +`is_false()` Check if the object is a boolean and has a value of False.\ +`contains_at_least(num_of_min_elements)` Check if the object (assumed to be iterable) contains at least the specified number of elements.\ +`contains_at_most(num_of_max_elements)` Check if the object (assumed to be iterable) contains at most the specified number of elements.\ +`contains_exactly(num_of_elements)` Check if the object (assumed to be iterable) contains exactly the specified number of elements.\ +`is_none()` Check if the object is None.\ `has_unique_values()` Check if the object (assumed to be iterable) contains unique values. -Note: This function assumes that the object's elements are hashable. - - -`is_instance()` Check if the object is an instance of one or more specified types. - - -`is_callable()` Check if the object is callable (e.g., a function or method). - - -`is_iterable()` Check if the object is iterable. - - -`is_string()` Check if the object is a string. - - -`is_number()` Check if the object is a number (int or float). - - +Note: This function assumes that the object's elements are hashable.\ +`is_instance()` Check if the object is an instance of one or more specified types.\ +`is_callable()` Check if the object is callable (e.g., a function or method).\ +`is_iterable()` Check if the object is iterable.\ +`is_string()` Check if the object is a string.\ +`is_number()` Check if the object is a number (int or float).\ `is_bool()` Check if the object is a boolean. ## License diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index c69535a..896a515 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -92,7 +92,7 @@ def main(): validators_dir = os.path.join(project_dir, "fluent_validator", "validators") output_file = os.path.join(project_dir, "README.md") - validation_list = "\n\n\n".join( + validation_list = "\\\n".join( validator_doc.strip() for file in glob.glob(os.path.join(validators_dir, "*.py")) for validator_doc in extract_validators_docs(file) From a9d9ce069ea8bb909d4ced7fc18bfa49b83f656a Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:49:43 -0300 Subject: [PATCH 08/13] Use table --- README.md | 48 ++++++++++++++++++++-------------------- scripts/generate_docs.py | 8 ++++--- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0f5179f..b6d63d7 100644 --- a/README.md +++ b/README.md @@ -51,30 +51,30 @@ For example, the negative of `is_none()` is `not_is_none()`. ### Check out the full list of available above. -`equal(value)` Check if the object is equal to the specified value.\ -`is_in()` Check if the object is in a collection of values.\ -`greater_than(value)` Check if the object is greater than the specified value.\ -`less_than(value)` Check if the object is less than the specified value.\ -`greater_or_equal_than(value)` Check if the object is greater than or equal to the specified value.\ -`less_or_equal_than(value)` Check if the object is less than or equal to the specified value.\ -`min(value)` Check if the object is greater than or equal to the specified minimum value.\ -`max(value)` Check if the object is less than or equal to the specified maximum value.\ -`between(min, max)` Check if the object is within the specified range.\ -`is_true()` Check if the object is a boolean and has a value of True.\ -`is_false()` Check if the object is a boolean and has a value of False.\ -`contains_at_least(num_of_min_elements)` Check if the object (assumed to be iterable) contains at least the specified number of elements.\ -`contains_at_most(num_of_max_elements)` Check if the object (assumed to be iterable) contains at most the specified number of elements.\ -`contains_exactly(num_of_elements)` Check if the object (assumed to be iterable) contains exactly the specified number of elements.\ -`is_none()` Check if the object is None.\ -`has_unique_values()` Check if the object (assumed to be iterable) contains unique values. - -Note: This function assumes that the object's elements are hashable.\ -`is_instance()` Check if the object is an instance of one or more specified types.\ -`is_callable()` Check if the object is callable (e.g., a function or method).\ -`is_iterable()` Check if the object is iterable.\ -`is_string()` Check if the object is a string.\ -`is_number()` Check if the object is a number (int or float).\ -`is_bool()` Check if the object is a boolean. +| Validation | Description | +| --- | --- | +| `equal(value)` | Check if the object is equal to the specified value. | +| `is_in()` | Check if the object is in a collection of values. | +| `greater_than(value)` | Check if the object is greater than the specified value. | +| `less_than(value)` | Check if the object is less than the specified value. | +| `greater_or_equal_than(value)` | Check if the object is greater than or equal to the specified value. | +| `less_or_equal_than(value)` | Check if the object is less than or equal to the specified value. | +| `min(value)` | Check if the object is greater than or equal to the specified minimum value. | +| `max(value)` | Check if the object is less than or equal to the specified maximum value. | +| `between(min, max)` | Check if the object is within the specified range. | +| `is_true()` | Check if the object is a boolean and has a value of True. | +| `is_false()` | Check if the object is a boolean and has a value of False. | +| `contains_at_least(num_of_min_elements)` | Check if the object (assumed to be iterable) contains at least the specified number of elements. | +| `contains_at_most(num_of_max_elements)` | Check if the object (assumed to be iterable) contains at most the specified number of elements. | +| `contains_exactly(num_of_elements)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | +| `is_none()` | Check if the object is None. | +| `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | +| `is_instance()` | Check if the object is an instance of one or more specified types. | +| `is_callable()` | Check if the object is callable (e.g., a function or method). | +| `is_iterable()` | Check if the object is iterable. | +| `is_string()` | Check if the object is a string. | +| `is_number()` | Check if the object is a number (int or float). | +| `is_bool()` | Check if the object is a boolean. | ## License diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 896a515..d168f6f 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -55,6 +55,8 @@ ### Check out the full list of available above. +| Validation | Description | +| --- | --- | {{ validation_list }} ## License @@ -80,11 +82,11 @@ def extract_validators_docs(filename): docstring = [ line.strip() for line in docstring.split("\n") if line.strip() != "" ] - docstring = "\n\n".join(docstring) + docstring = " ".join(docstring) method_name = node.name.strip("_") args = [arg.arg for arg in node.args.args if arg.arg != "self"] - yield f"`{method_name}({', '.join(args)})` {docstring}" + yield f"| `{method_name}({', '.join(args)})` | {docstring} |" def main(): @@ -92,7 +94,7 @@ def main(): validators_dir = os.path.join(project_dir, "fluent_validator", "validators") output_file = os.path.join(project_dir, "README.md") - validation_list = "\\\n".join( + validation_list = "\n".join( validator_doc.strip() for file in glob.glob(os.path.join(validators_dir, "*.py")) for validator_doc in extract_validators_docs(file) From b59e23fce469b8b7f8bd2218743e1cb52b5231ab Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:55:12 -0300 Subject: [PATCH 09/13] Add generate docs to pre-commit --- .pre-commit-config.yaml | 8 ++++++++ README.md | 8 ++++---- fluent_validator/validators/value_validator.py | 16 ++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 98c8314..2106b2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,3 +22,11 @@ repos: hooks: - id: isort args: [--profile=black] + +- repo: local + hooks: + - id: generate_docs + name: Generate Docs (README.md) + entry: python scripts/generate_docs.py + language: python + pass_filenames: false diff --git a/README.md b/README.md index b6d63d7..568952f 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,12 @@ For example, the negative of `is_none()` is `not_is_none()`. | `less_or_equal_than(value)` | Check if the object is less than or equal to the specified value. | | `min(value)` | Check if the object is greater than or equal to the specified minimum value. | | `max(value)` | Check if the object is less than or equal to the specified maximum value. | -| `between(min, max)` | Check if the object is within the specified range. | +| `between(min_value, max_value)` | Check if the object is within the specified range. | | `is_true()` | Check if the object is a boolean and has a value of True. | | `is_false()` | Check if the object is a boolean and has a value of False. | -| `contains_at_least(num_of_min_elements)` | Check if the object (assumed to be iterable) contains at least the specified number of elements. | -| `contains_at_most(num_of_max_elements)` | Check if the object (assumed to be iterable) contains at most the specified number of elements. | -| `contains_exactly(num_of_elements)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | +| `contains_at_least(value)` | Check if the object (assumed to be iterable) contains at least the specified number of elements. | +| `contains_at_most(value)` | Check if the object (assumed to be iterable) contains at most the specified number of elements. | +| `contains_exactly(value)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | | `is_none()` | Check if the object is None. | | `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | | `is_instance()` | Check if the object is an instance of one or more specified types. | diff --git a/fluent_validator/validators/value_validator.py b/fluent_validator/validators/value_validator.py index 76389e0..d22b057 100644 --- a/fluent_validator/validators/value_validator.py +++ b/fluent_validator/validators/value_validator.py @@ -50,11 +50,11 @@ def _max(self, value): """ return self._less_or_equal_than(value) - def _between(self, min, max): + def _between(self, min_value, max_value): """ Check if the object is within the specified range. """ - return self._min(min) and self._max(max) + return self._min(min_value) and self._max(max_value) def _is_true(self): """ @@ -68,23 +68,23 @@ def _is_false(self): """ return self._is_bool() and self.obj is False - def _contains_at_least(self, num_of_min_elements): + def _contains_at_least(self, value): """ Check if the object (assumed to be iterable) contains at least the specified number of elements. """ - return len(self.obj) >= num_of_min_elements + return len(self.obj) >= value - def _contains_at_most(self, num_of_max_elements): + def _contains_at_most(self, value): """ Check if the object (assumed to be iterable) contains at most the specified number of elements. """ - return len(self.obj) <= num_of_max_elements + return len(self.obj) <= value - def _contains_exactly(self, num_of_elements): + def _contains_exactly(self, value): """ Check if the object (assumed to be iterable) contains exactly the specified number of elements. """ - return len(self.obj) == num_of_elements + return len(self.obj) == value def _is_none(self): """ From 8299d1a9739a699a0e19d2bac5a8bd76549417f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Aug 2023 01:55:22 +0000 Subject: [PATCH 10/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 568952f..255b2a0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,12 @@ For example, the negative of `is_none()` is `not_is_none()`. | Validation | Description | | --- | --- | +| `is_instance()` | Check if the object is an instance of one or more specified types. | +| `is_callable()` | Check if the object is callable (e.g., a function or method). | +| `is_iterable()` | Check if the object is iterable. | +| `is_string()` | Check if the object is a string. | +| `is_number()` | Check if the object is a number (int or float). | +| `is_bool()` | Check if the object is a boolean. | | `equal(value)` | Check if the object is equal to the specified value. | | `is_in()` | Check if the object is in a collection of values. | | `greater_than(value)` | Check if the object is greater than the specified value. | @@ -69,12 +75,6 @@ For example, the negative of `is_none()` is `not_is_none()`. | `contains_exactly(value)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | | `is_none()` | Check if the object is None. | | `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | -| `is_instance()` | Check if the object is an instance of one or more specified types. | -| `is_callable()` | Check if the object is callable (e.g., a function or method). | -| `is_iterable()` | Check if the object is iterable. | -| `is_string()` | Check if the object is a string. | -| `is_number()` | Check if the object is a number (int or float). | -| `is_bool()` | Check if the object is a boolean. | ## License From ec9342f10072b403b090119eb0531eef0ccdf27a Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 22:58:19 -0300 Subject: [PATCH 11/13] simplify annotation --- README.md | 14 +++++++------- fluent_validator/validators/value_validator.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 255b2a0..a7d7fa1 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,6 @@ For example, the negative of `is_none()` is `not_is_none()`. | Validation | Description | | --- | --- | -| `is_instance()` | Check if the object is an instance of one or more specified types. | -| `is_callable()` | Check if the object is callable (e.g., a function or method). | -| `is_iterable()` | Check if the object is iterable. | -| `is_string()` | Check if the object is a string. | -| `is_number()` | Check if the object is a number (int or float). | -| `is_bool()` | Check if the object is a boolean. | | `equal(value)` | Check if the object is equal to the specified value. | | `is_in()` | Check if the object is in a collection of values. | | `greater_than(value)` | Check if the object is greater than the specified value. | @@ -67,7 +61,7 @@ For example, the negative of `is_none()` is `not_is_none()`. | `less_or_equal_than(value)` | Check if the object is less than or equal to the specified value. | | `min(value)` | Check if the object is greater than or equal to the specified minimum value. | | `max(value)` | Check if the object is less than or equal to the specified maximum value. | -| `between(min_value, max_value)` | Check if the object is within the specified range. | +| `between(min_vl, max_vl)` | Check if the object is within the specified range. | | `is_true()` | Check if the object is a boolean and has a value of True. | | `is_false()` | Check if the object is a boolean and has a value of False. | | `contains_at_least(value)` | Check if the object (assumed to be iterable) contains at least the specified number of elements. | @@ -75,6 +69,12 @@ For example, the negative of `is_none()` is `not_is_none()`. | `contains_exactly(value)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | | `is_none()` | Check if the object is None. | | `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | +| `is_instance()` | Check if the object is an instance of one or more specified types. | +| `is_callable()` | Check if the object is callable (e.g., a function or method). | +| `is_iterable()` | Check if the object is iterable. | +| `is_string()` | Check if the object is a string. | +| `is_number()` | Check if the object is a number (int or float). | +| `is_bool()` | Check if the object is a boolean. | ## License diff --git a/fluent_validator/validators/value_validator.py b/fluent_validator/validators/value_validator.py index d22b057..0c24338 100644 --- a/fluent_validator/validators/value_validator.py +++ b/fluent_validator/validators/value_validator.py @@ -50,11 +50,11 @@ def _max(self, value): """ return self._less_or_equal_than(value) - def _between(self, min_value, max_value): + def _between(self, min_vl, max_vl): """ Check if the object is within the specified range. """ - return self._min(min_value) and self._max(max_value) + return self._min(min_vl) and self._max(max_vl) def _is_true(self): """ From 0ca98f7b989200003a523840a074ea63e7225930 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Aug 2023 01:58:34 +0000 Subject: [PATCH 12/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7d7fa1..86434e1 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,12 @@ For example, the negative of `is_none()` is `not_is_none()`. | Validation | Description | | --- | --- | +| `is_instance()` | Check if the object is an instance of one or more specified types. | +| `is_callable()` | Check if the object is callable (e.g., a function or method). | +| `is_iterable()` | Check if the object is iterable. | +| `is_string()` | Check if the object is a string. | +| `is_number()` | Check if the object is a number (int or float). | +| `is_bool()` | Check if the object is a boolean. | | `equal(value)` | Check if the object is equal to the specified value. | | `is_in()` | Check if the object is in a collection of values. | | `greater_than(value)` | Check if the object is greater than the specified value. | @@ -69,12 +75,6 @@ For example, the negative of `is_none()` is `not_is_none()`. | `contains_exactly(value)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | | `is_none()` | Check if the object is None. | | `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | -| `is_instance()` | Check if the object is an instance of one or more specified types. | -| `is_callable()` | Check if the object is callable (e.g., a function or method). | -| `is_iterable()` | Check if the object is iterable. | -| `is_string()` | Check if the object is a string. | -| `is_number()` | Check if the object is a number (int or float). | -| `is_bool()` | Check if the object is a boolean. | ## License From f3baa0d8652c2012a0610e259d4a335ec48d7f9f Mon Sep 17 00:00:00 2001 From: Mario Taddeucci Date: Sat, 26 Aug 2023 23:01:36 -0300 Subject: [PATCH 13/13] sort validations --- README.md | 28 ++++++++++++++-------------- scripts/generate_docs.py | 8 ++++++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a7d7fa1..cba0874 100644 --- a/README.md +++ b/README.md @@ -53,28 +53,28 @@ For example, the negative of `is_none()` is `not_is_none()`. | Validation | Description | | --- | --- | -| `equal(value)` | Check if the object is equal to the specified value. | -| `is_in()` | Check if the object is in a collection of values. | -| `greater_than(value)` | Check if the object is greater than the specified value. | -| `less_than(value)` | Check if the object is less than the specified value. | -| `greater_or_equal_than(value)` | Check if the object is greater than or equal to the specified value. | -| `less_or_equal_than(value)` | Check if the object is less than or equal to the specified value. | -| `min(value)` | Check if the object is greater than or equal to the specified minimum value. | -| `max(value)` | Check if the object is less than or equal to the specified maximum value. | | `between(min_vl, max_vl)` | Check if the object is within the specified range. | -| `is_true()` | Check if the object is a boolean and has a value of True. | -| `is_false()` | Check if the object is a boolean and has a value of False. | | `contains_at_least(value)` | Check if the object (assumed to be iterable) contains at least the specified number of elements. | | `contains_at_most(value)` | Check if the object (assumed to be iterable) contains at most the specified number of elements. | | `contains_exactly(value)` | Check if the object (assumed to be iterable) contains exactly the specified number of elements. | -| `is_none()` | Check if the object is None. | +| `equal(value)` | Check if the object is equal to the specified value. | +| `greater_or_equal_than(value)` | Check if the object is greater than or equal to the specified value. | +| `greater_than(value)` | Check if the object is greater than the specified value. | | `has_unique_values()` | Check if the object (assumed to be iterable) contains unique values. Note: This function assumes that the object's elements are hashable. | -| `is_instance()` | Check if the object is an instance of one or more specified types. | +| `is_bool()` | Check if the object is a boolean. | | `is_callable()` | Check if the object is callable (e.g., a function or method). | +| `is_false()` | Check if the object is a boolean and has a value of False. | +| `is_in()` | Check if the object is in a collection of values. | +| `is_instance()` | Check if the object is an instance of one or more specified types. | | `is_iterable()` | Check if the object is iterable. | -| `is_string()` | Check if the object is a string. | +| `is_none()` | Check if the object is None. | | `is_number()` | Check if the object is a number (int or float). | -| `is_bool()` | Check if the object is a boolean. | +| `is_string()` | Check if the object is a string. | +| `is_true()` | Check if the object is a boolean and has a value of True. | +| `less_or_equal_than(value)` | Check if the object is less than or equal to the specified value. | +| `less_than(value)` | Check if the object is less than the specified value. | +| `max(value)` | Check if the object is less than or equal to the specified maximum value. | +| `min(value)` | Check if the object is greater than or equal to the specified minimum value. | ## License diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index d168f6f..082d252 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -94,14 +94,18 @@ def main(): validators_dir = os.path.join(project_dir, "fluent_validator", "validators") output_file = os.path.join(project_dir, "README.md") - validation_list = "\n".join( + validations_list = [ validator_doc.strip() for file in glob.glob(os.path.join(validators_dir, "*.py")) for validator_doc in extract_validators_docs(file) + ] + + content = TEMPLATE.replace( + "{{ validation_list }}", "\n".join(sorted(validations_list)) ) with open(output_file, "w", encoding="utf-8") as file: - file.write(TEMPLATE.replace("{{ validation_list }}", validation_list)) + file.write(content) if __name__ == "__main__":