Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#-license)
- [Contact](#Contact)
- [Contact](#contact)

## 📖 About The Project

Expand Down Expand Up @@ -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):**
Expand All @@ -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:**
Expand Down Expand Up @@ -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.
```

Expand Down Expand Up @@ -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)**.
Expand Down
10 changes: 6 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import tomllib
from pathlib import Path

# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -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
Expand All @@ -39,5 +42,4 @@
# -- Path setup --------------------------------------------------------------


# noinspection PyTypeChecker
sys.path.insert(0, os.path.abspath('../../src'))
sys.path.insert(0, str(repository_root / 'src'))
11 changes: 6 additions & 5 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
==========================
Expand All @@ -63,4 +64,4 @@ This should print the installed version of the package, for example:

.. code-block:: text

validate-code 0.1.1
validate-code 0.4.0
15 changes: 7 additions & 8 deletions docs/source/user_guide/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
====================================
Expand Down Expand Up @@ -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
=============================
Expand All @@ -99,14 +100,12 @@ 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
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`.
and learn how to write rules for scenarios, head to the :doc:`cookbook`.
4 changes: 2 additions & 2 deletions src/code_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/code_validator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/code_validator/rules_library/constraint_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading