You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/errors/contract-violations.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,17 @@ Each message consists of:
73
73
74
74
Below is a comprehensive list of all possible error messages emitted by ImportSpy:
75
75
76
-
--8<-- "errors/error_table.md"
76
+
| Category | Context | Error Message |
77
+
|------------|---------------|---------------|
78
+
|`missing`|`runtime`| The runtime `CPython 3.12` is declared but missing. Ensure it is properly defined and implemented. |
79
+
||`environment`| The environment variable `DEBUG` is declared but missing. Ensure it is properly defined and implemented. |
80
+
||`module`| The variable `plugin_name` in module `extension.py` is declared but missing. Ensure it is properly defined and implemented. |
81
+
||`class`| The method `run` in class `Plugin` is declared but missing. Ensure it is properly defined and implemented. |
82
+
|`mismatch`|`runtime`| The runtime `CPython 3.12` does not match the expected value. Expected: `CPython 3.11`, Found: `CPython 3.12`. Check the value and update the contract or implementation accordingly. |
83
+
||`environment`| The environment variable `LOG_LEVEL` does not match the expected value. Expected: `'INFO'`, Found: `'DEBUG'`. Check the value and update the contract or implementation accordingly. |
84
+
||`class`| The class attribute `engine` in class `Extension` does not match the expected value. Expected: `'docker'`, Found: `'podman'`. Check the value and update the contract or implementation accordingly. |
85
+
|`invalid`|`class`| The argument `msg` of method `send` has an invalid value. Allowed values: `[str, None]`, Found: `42`. Update the value to one of the allowed options. |
**Context-aware import validation for Python modules**
3
+
**Context‑aware import validation for Python modules**
4
4
5
-
ImportSpy is an open-source Python library that introduces a robust mechanism to control and validate how and when modules are imported. At its core, it relies on versioned, declarative **import contracts** — written in YAML — which describe what a module expects from its execution context and its importer.
5
+
ImportSpy is an open‑source Python library that brings structural and environmental awareness to Python’s import system.
6
+
It introduces a new concept: the **import contract** — a versioned, declarative `.yml` file that describes exactly how and where a module is allowed to be imported.
6
7
7
-
It brings **modularity**, **predictability**, and **security** to Python ecosystems.
8
+
This enables predictable, secure, and modular Python codebases, especially in complex or regulated environments.
8
9
9
10
---
10
11
11
12
## What is an Import Contract?
12
13
13
-
An import contract is a `.yml` file that defines:
14
+
An import contract defines what a module expects from:
14
15
15
-
- The expected **structure** of a module: functions, classes, arguments, annotations, variables
- Optional runtime conditions: environment variables, base classes, or structural patterns
18
19
19
-
If these conditions are not met, ImportSpy can stop the import and raise a detailed, structured error — before any runtime failure can occur.
20
+
If the context does not meet the declared conditions, ImportSpy blocks the import and raises a structured, human-readable error — before any runtime logic is executed.
20
21
21
22
---
22
23
23
24
## Key Features
24
25
25
-
- YAML-based **import contracts**
26
-
- Embedded and CLI-based **validation**
27
-
- Structural validation of **variables**, **functions**, **classes**
28
-
- Runtime checks for **OS**, **architecture**, **Python version**, **interpreter**
29
-
- Contract-driven plugin validation for **secure extensibility**
30
-
-Clear, explainable **error reporting** on mismatch, missing, or invalid usage
@@ -115,25 +109,26 @@ ImportSpy is built around 3 key components:
115
109
116
110
## Why ImportSpy?
117
111
118
-
Python’s import system is powerful, but not context-aware. ImportSpy solves this by adding a **layer of structural governance** and **runtime filtering**.
112
+
Python’s import mechanism is flexible, but not context-aware.
113
+
ImportSpy adds a layer of governance and runtime validation, making your code more robust and secure.
119
114
120
-
This makes it ideal for:
115
+
It’s ideal for:
121
116
122
-
-Plugin systems
123
-
-Isolated runtimes
124
-
-Package compliance
125
-
-Security-aware applications
126
-
-CI enforcement of expected module interfaces
117
+
-Securing plugin boundaries
118
+
-Enforcing internal interfaces
119
+
-Preventing unsupported imports
120
+
-CI/CD enforcement of import assumptions
121
+
-Runtime compatibility in multi-environment systems
127
122
128
123
---
129
124
130
-
## Sponsorship & Community
125
+
## Support and Community
131
126
132
-
If ImportSpy is useful in your infrastructure, help us grow by:
127
+
If ImportSpy is useful in your infrastructure, consider:
133
128
134
-
-[Starring the project on GitHub](https://github.com/your-org/importspy)
135
-
-[Becoming a GitHub Sponsor](https://github.com/sponsors/your-org)
129
+
-[Starring the project on GitHub](https://github.com/atellaluca/ImportSpy)
130
+
-[Becoming a GitHub Sponsor](https://github.com/sponsors/atellaluca)
136
131
137
132
---
138
133
139
-
> ImportSpy is more than a validator — it's a contract of trust between Python modules.
134
+
> ImportSpy is more than a validator — it’s a contract of trust between Python modules.
0 commit comments