diff --git a/README.md b/README.md index bc4cc6c..5a1f4b6 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ - [Documentation](#-documentation) - [Contributing](#-contributing) - [License](#-license) -- [Contact](#Contact) +- [Contact](#contact) ## 📖 About The Project @@ -105,10 +105,10 @@ minimal complexity. **1. For Users (from PyPI):** -Install the package with one command. This will make the `validate-code` command-line tool available. +Use Python 3.11 or later. Install the package in your active environment to make the `validate-code` command available. ```bash -pip install python-code-validator +python -m pip install python-code-validator ``` **2. For Users (from source):** @@ -118,7 +118,7 @@ If you want to install directly from the repository: ```bash git clone https://github.com/Qu1nel/PythonCodeValidator.git cd PythonCodeValidator -pip install . +python -m pip install . ``` **3. For Developers:** @@ -163,12 +163,31 @@ def main(): } ``` -**Running the validator:** +**`solution_valid.py`:** + +```python +def solve(): + return 42 +``` + +Run the same rule against both files. The file with `solve` passes (exit code `0`). + +```bash +validate-code solution_valid.py rules_simple.json +``` + +```text +Validation successful. +``` + +The file without `solve` fails (exit code `1`). ```bash -$ validate-code solution_simple.py rules_simple.json -Starting validation for: solution_simple.py -Required function 'solve' is missing. +validate-code solution_simple.py rules_simple.json +``` + +```text +1. Required function 'solve' is missing. Validation failed. ``` @@ -214,19 +233,21 @@ class MyGame(arcade.Window): } ``` -**Running the validator:** +**Running the validator:** Arcade does not need to be installed because the validator reads the source without executing it. ```bash -$ validate-code game.py rules_advanced.json -Starting validation for: game.py -Do not use 'print' inside the 'update' method. +validate-code game.py rules_advanced.json +``` + +```text +1. Do not use 'print' inside the 'update' method. Validation failed. ``` ## 📚 Documentation - **Full User Guide & JSON Specification**: Our complete documentation is hosted on - **[Read the Docs](https://[your-project].readthedocs.io)**. + **[Read the Docs](https://pythoncodevalidator.readthedocs.io/en/latest/)**. - **Developer's Guide**: For a deep dive into the architecture, see the **[How It Works guide](./docs/how_it_works/index.md)**. - **Interactive AI-Powered Docs**: **[DeepWiki](https://deepwiki.com/Qu1nel/PythonCodeValidator)**. diff --git a/docs/source/conf.py b/docs/source/conf.py index 69dafcf..1443ad1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,5 +1,6 @@ -import os import sys +import tomllib +from pathlib import Path # Configuration file for the Sphinx documentation builder. # @@ -14,7 +15,9 @@ # noinspection PyShadowingBuiltins copyright = '2025, Ivan Kovach (@Qu1nel)' author = 'Ivan Kovach (@Qu1nel)' -release = '0.1.1' +repository_root = Path(__file__).resolve().parents[2] +with (repository_root / 'pyproject.toml').open('rb') as metadata: + release = tomllib.load(metadata)['project']['version'] # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration @@ -39,5 +42,4 @@ # -- Path setup -------------------------------------------------------------- -# noinspection PyTypeChecker -sys.path.insert(0, os.path.abspath('../../src')) +sys.path.insert(0, str(repository_root / 'src')) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 242c0ce..56f7213 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -3,6 +3,7 @@ Installation ************ This page provides instructions for installing the ``python-code-validator`` package. +It requires Python 3.11 or later. .. grid:: 1 2 2 1 :gutter: 2 @@ -12,18 +13,18 @@ This page provides instructions for installing the ``python-code-validator`` pac The recommended way to install the package for regular use is from the Python Package Index (PyPI) using ``pip`` or any compatible package manager. - This will install the latest stable version and make the ``validate-code`` + This will install the latest available release and make the ``validate-code`` command-line tool available in your environment. .. code-block:: bash - pip install python-code-validator + python -m pip install python-code-validator To upgrade to a new version, use: .. code-block:: bash - pip install --upgrade python-code-validator + python -m pip install --upgrade python-code-validator .. grid-item-card:: For Developers :shadow: md @@ -47,7 +48,7 @@ This page provides instructions for installing the ``python-code-validator`` pac This command automates the creation of a virtual environment and the installation of all required packages. For more details on contributing, - please see the :doc:`../contributing` guide. + please see the :doc:`contributing` guide. Verifying the Installation ========================== @@ -63,4 +64,4 @@ This should print the installed version of the package, for example: .. code-block:: text - validate-code 0.1.1 \ No newline at end of file + validate-code 0.4.0 diff --git a/docs/source/user_guide/quickstart.rst b/docs/source/user_guide/quickstart.rst index da5ff9c..8274ffa 100644 --- a/docs/source/user_guide/quickstart.rst +++ b/docs/source/user_guide/quickstart.rst @@ -10,8 +10,8 @@ This guide provides a complete, step-by-step example of how to use the The Goal ======== -Our goal is to verify that a student's submission file (`solution.py`) contains a -required function named ``solve``, and that it does not use the forbidden `os` module. +Our goal is to verify that a student's submission file (``solution.py``) contains a +required function named ``solve``, and that it does not use the forbidden ``os`` module. Step 1: The Python Code to Validate ==================================== @@ -76,8 +76,9 @@ Next, we define our validation requirements in a JSON file. Let's call it } This file defines two rules: -1. **Rule 101**: Checks that a function named ``solve`` **is required**. We've marked it as critical. -2. **Rule 102**: Checks that the ``os`` module **is forbidden**. + +1. **Rule 101** checks that a function named ``solve`` **is required**. We've marked it as critical. +2. **Rule 102** checks that the ``os`` module **is forbidden**. Step 3: Running the Validator ============================= @@ -99,9 +100,7 @@ finding the first error. .. code-block:: text :caption: Console Output - Starting validation for: solution.py - Required function 'solve' is missing. - Critical rule failed. Halting validation. + 1. Required function 'solve' is missing. Validation failed. The output clearly indicates that the first critical rule failed, and the @@ -109,4 +108,4 @@ process was halted. If we remove ``"is_critical": true``, the validator would report both errors. This simple example demonstrates the core workflow. To see more advanced examples -and learn how to write rules for scenarios, head to the :doc:`cookbook`. \ No newline at end of file +and learn how to write rules for scenarios, head to the :doc:`cookbook`. diff --git a/src/code_validator/__init__.py b/src/code_validator/__init__.py index b16e2a7..6b10f24 100644 --- a/src/code_validator/__init__.py +++ b/src/code_validator/__init__.py @@ -24,8 +24,8 @@ solution_path=Path("path/to/solution.py"), rules_path=Path("path/to/rules.json"), log_level=LogLevel.INFO, - is_silent=False, - stop_on_first_fail=False + is_quiet=False, + exit_on_first_error=False, ) # Run validation diff --git a/src/code_validator/core.py b/src/code_validator/core.py index 3797697..21b4252 100644 --- a/src/code_validator/core.py +++ b/src/code_validator/core.py @@ -25,8 +25,8 @@ solution_path=Path("path/to/solution.py"), rules_path=Path("path/to/rules.json"), log_level=LogLevel.INFO, - is_silent=False, - stop_on_first_fail=False + is_quiet=False, + exit_on_first_error=False, ) validator = StaticValidator(config, console) diff --git a/src/code_validator/rules_library/constraint_logic.py b/src/code_validator/rules_library/constraint_logic.py index 6556427..855a68e 100644 --- a/src/code_validator/rules_library/constraint_logic.py +++ b/src/code_validator/rules_library/constraint_logic.py @@ -333,11 +333,12 @@ class MustHaveArgsConstraint(Constraint): This constraint can check for an exact number of arguments or for an exact sequence of argument names, ignoring `self` or `cls` in methods. - JSON Params: - count (int, optional): The exact number of arguments required. - names (list[str], optional): The exact list of argument names in order. - exact_match (bool, optional): Used with `names`. If False, only checks - for presence, not for exact list match. Defaults to True. + JSON parameters: + + - ``count`` (int, optional): The exact number of arguments required. + - ``names`` (list of str, optional): The exact list of argument names in order. + - ``exact_match`` (bool, optional): Defaults to True. If False, only checks + for presence of the given argument names. """ @log_initialization(level=LogLevel.TRACE)