codexray-analyser 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. codexray_analyser-0.1.0/.github/CODEOWNERS +2 -0
  2. codexray_analyser-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +29 -0
  3. codexray_analyser-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +19 -0
  4. codexray_analyser-0.1.0/.github/pull_request_template.md +13 -0
  5. codexray_analyser-0.1.0/.github/workflows/ci.yml +52 -0
  6. codexray_analyser-0.1.0/.github/workflows/publish.yml +36 -0
  7. codexray_analyser-0.1.0/.gitignore +8 -0
  8. codexray_analyser-0.1.0/CODE_OF_CONDUCT.md +27 -0
  9. codexray_analyser-0.1.0/CONTRIBUTING.md +36 -0
  10. codexray_analyser-0.1.0/LICENSE +21 -0
  11. codexray_analyser-0.1.0/PKG-INFO +177 -0
  12. codexray_analyser-0.1.0/README.md +155 -0
  13. codexray_analyser-0.1.0/RELEASING.md +38 -0
  14. codexray_analyser-0.1.0/SECURITY.md +26 -0
  15. codexray_analyser-0.1.0/pyproject.toml +59 -0
  16. codexray_analyser-0.1.0/src/codexray/__init__.py +15 -0
  17. codexray_analyser-0.1.0/src/codexray/analyser.py +125 -0
  18. codexray_analyser-0.1.0/src/codexray/cli.py +71 -0
  19. codexray_analyser-0.1.0/src/codexray/config.py +13 -0
  20. codexray_analyser-0.1.0/src/codexray/graph.py +101 -0
  21. codexray_analyser-0.1.0/src/codexray/limits.py +25 -0
  22. codexray_analyser-0.1.0/src/codexray/models.py +42 -0
  23. codexray_analyser-0.1.0/src/codexray/offline.py +12 -0
  24. codexray_analyser-0.1.0/src/codexray/parsers.py +94 -0
  25. codexray_analyser-0.1.0/src/codexray/rules.py +127 -0
  26. codexray_analyser-0.1.0/tests/conftest.py +9 -0
  27. codexray_analyser-0.1.0/tests/test_analyser.py +60 -0
  28. codexray_analyser-0.1.0/tests/test_graph.py +12 -0
  29. codexray_analyser-0.1.0/tests/test_requirements.py +21 -0
@@ -0,0 +1,2 @@
1
+ # Require maintainer review for all files.
2
+ * @Merlins-Sanctum
@@ -0,0 +1,29 @@
1
+ name: Bug report
2
+ description: Report a bug in codexray-analyser
3
+ title: "[Bug]: "
4
+ labels: [bug]
5
+ body:
6
+ - type: textarea
7
+ id: what_happened
8
+ attributes:
9
+ label: What happened?
10
+ description: What did you expect and what happened instead?
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: repro
15
+ attributes:
16
+ label: Steps to reproduce
17
+ placeholder: |
18
+ 1. Run ...
19
+ 2. Analyse ...
20
+ 3. Observe ...
21
+ validations:
22
+ required: true
23
+ - type: input
24
+ id: version
25
+ attributes:
26
+ label: Package version
27
+ placeholder: 0.1.0
28
+ validations:
29
+ required: true
@@ -0,0 +1,19 @@
1
+ name: Feature request
2
+ description: Suggest a new feature
3
+ title: "[Feature]: "
4
+ labels: [enhancement]
5
+ body:
6
+ - type: textarea
7
+ id: problem
8
+ attributes:
9
+ label: Problem statement
10
+ description: What user problem are you trying to solve?
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: proposal
15
+ attributes:
16
+ label: Proposed solution
17
+ description: Describe your proposed approach.
18
+ validations:
19
+ required: true
@@ -0,0 +1,13 @@
1
+ ## What changed
2
+
3
+ -
4
+
5
+ ## Why
6
+
7
+ -
8
+
9
+ ## Validation
10
+
11
+ - [ ] `python -m ruff check .`
12
+ - [ ] `python -m pytest`
13
+ - [ ] `python -m bandit -q -r src`
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ test-and-security:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.11", "3.12"]
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Setup Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ python -m pip install -e .
27
+ python -m pip install pytest ruff bandit pip-audit
28
+
29
+ - name: Lint
30
+ run: ruff check .
31
+
32
+ - name: Unit tests
33
+ run: pytest
34
+
35
+ - name: Static security scan
36
+ run: bandit -q -r src
37
+
38
+ - name: Dependency vulnerability scan
39
+ run: |
40
+ python - <<'PY'
41
+ import pathlib
42
+ import tomllib
43
+
44
+ pyproject = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))
45
+ deps = pyproject.get("project", {}).get("dependencies", [])
46
+ pathlib.Path("runtime-requirements.txt").write_text(
47
+ "\n".join(deps),
48
+ encoding="utf-8",
49
+ )
50
+ print(f"Runtime dependencies found: {len(deps)}")
51
+ PY
52
+ if [ -s runtime-requirements.txt ]; then pip-audit -r runtime-requirements.txt --strict; else echo "No runtime dependencies to audit."; fi
@@ -0,0 +1,36 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ id-token: write
11
+ contents: read
12
+
13
+ jobs:
14
+ build-and-publish:
15
+ runs-on: ubuntu-latest
16
+ environment:
17
+ name: pypi
18
+ url: https://pypi.org/p/codexray-analyser
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Setup Python
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: "3.12"
27
+
28
+ - name: Build package
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ python -m pip install build twine
32
+ python -m build
33
+ twine check dist/*
34
+
35
+ - name: Publish to PyPI
36
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
@@ -0,0 +1,27 @@
1
+ # Code of Conduct
2
+
3
+ ## Our pledge
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone.
6
+
7
+ ## Our standards
8
+
9
+ Examples of behavior that contributes to a positive environment include:
10
+
11
+ - Being respectful and constructive.
12
+ - Accepting feedback gracefully.
13
+ - Focusing on what is best for the community.
14
+
15
+ Examples of unacceptable behavior include:
16
+
17
+ - Harassment, threats, or discriminatory language.
18
+ - Personal attacks or insulting comments.
19
+ - Publishing private information without consent.
20
+
21
+ ## Enforcement
22
+
23
+ Project maintainers are responsible for clarifying and enforcing these standards.
24
+
25
+ ## Reporting
26
+
27
+ Report abusive behavior to the maintainers through private channels listed in `SECURITY.md`.
@@ -0,0 +1,36 @@
1
+ # Contributing
2
+
3
+ Thanks for contributing to `codexray-analyser`.
4
+
5
+ ## Local setup
6
+
7
+ 1. Fork and clone the repo.
8
+ 2. Install development tools:
9
+
10
+ ```bash
11
+ python -m pip install -e .
12
+ python -m pip install pytest ruff bandit pip-audit build twine
13
+ ```
14
+
15
+ ## Before opening a PR
16
+
17
+ Run all checks locally:
18
+
19
+ ```bash
20
+ python -m ruff check .
21
+ python -m pytest
22
+ python -m bandit -q -r src
23
+ ```
24
+
25
+ ## Development guidelines
26
+
27
+ - Keep offline-first behavior as the default.
28
+ - Avoid adding network dependencies in default analysis flow.
29
+ - Add tests for new rules and parser behavior.
30
+ - Keep dependencies minimal and justified.
31
+
32
+ ## Pull requests
33
+
34
+ - Use clear titles and explain why the change is needed.
35
+ - Include tests for bug fixes and new features.
36
+ - Keep changes focused and small when possible.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohammad Hamad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: codexray-analyser
3
+ Version: 0.1.0
4
+ Summary: Offline-first static analyser for Python files and notebooks.
5
+ Project-URL: Homepage, https://github.com/Merlins-Sanctum/codexray-analyser
6
+ Project-URL: Repository, https://github.com/Merlins-Sanctum/codexray-analyser
7
+ Project-URL: Issues, https://github.com/Merlins-Sanctum/codexray-analyser/issues
8
+ Author: Mohammad Hamad
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: notebook,offline,python,security,static-analysis
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Security
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Codexray
24
+
25
+ Codexray is an offline-first Python static analyser for `.py` and `.ipynb` files.
26
+ It helps teams inspect security risks, code quality problems, and dependency patterns
27
+ without sending source code outside the local machine.
28
+
29
+ ## What Codexray does
30
+
31
+ - Scans Python files and notebooks.
32
+ - Supports project-level scans, full file scans, and targeted line-range checks.
33
+ - Produces a structured JSON report.
34
+ - Builds a dependency graph view with nodes and edges.
35
+ - Flags common security risks such as shell execution and dangerous builtins.
36
+
37
+ ## Privacy and security behavior
38
+
39
+ - No telemetry.
40
+ - No source upload.
41
+ - Network features are disabled by default.
42
+ - Strict input limits for file size, notebook size, snippet length, and AST depth.
43
+
44
+ This tool is designed for local analysis workflows where proprietary code must stay on the client system.
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install codexray-analyser
50
+ ```
51
+
52
+ ## Quick start with CLI
53
+
54
+ Analyse a folder:
55
+
56
+ ```bash
57
+ codexray ./my_project
58
+ ```
59
+
60
+ Analyse a single file:
61
+
62
+ ```bash
63
+ codexray ./my_project/app.py
64
+ ```
65
+
66
+ Analyse a code snippet:
67
+
68
+ ```bash
69
+ codexray --snippet "import os; os.system('whoami')"
70
+ ```
71
+
72
+ Analyse only specific lines from one file:
73
+
74
+ ```bash
75
+ codexray ./my_project/app.py --start-line 40 --end-line 80
76
+ ```
77
+
78
+ Save output to JSON:
79
+
80
+ ```bash
81
+ codexray ./my_project --output codexray-report.json
82
+ ```
83
+
84
+ ## Python API usage
85
+
86
+ ```python
87
+ from codexray import analyse_file_snippet, analyse_path, analyse_snippet
88
+
89
+ project_result = analyse_path("./my_project")
90
+ snippet_result = analyse_snippet("import os\nos.system('whoami')")
91
+ range_result = analyse_file_snippet("./my_project/app.py", 20, 50)
92
+ ```
93
+
94
+ ## Understanding the report
95
+
96
+ Each result returns:
97
+
98
+ - `findings`: list of detected issues.
99
+ - `graph`: nodes and edges representing imports, files, and function relationships.
100
+ - `metadata`: run information such as analysed path and offline mode state.
101
+
102
+ Example finding shape:
103
+
104
+ ```json
105
+ {
106
+ "rule_id": "SEC002",
107
+ "title": "Dangerous builtin eval",
108
+ "severity": "critical",
109
+ "message": "Avoid eval on untrusted content.",
110
+ "file_path": "src/app.py",
111
+ "line": 18,
112
+ "column": 4
113
+ }
114
+ ```
115
+
116
+ ## Reading graph output
117
+
118
+ Graph output contains:
119
+
120
+ - `nodes`: entities such as files, imports, and functions
121
+ - `edges`: relationships such as `imports`, `contains`, and `calls`
122
+
123
+ Typical use:
124
+
125
+ 1. Run Codexray and save JSON output.
126
+ 2. Load `graph.nodes` and `graph.edges` into your graph viewer.
127
+ 3. Track dependency hotspots and risky call paths.
128
+
129
+ ## How to use findings to make code changes
130
+
131
+ Recommended workflow:
132
+
133
+ 1. Sort findings by `severity`.
134
+ 2. Fix `critical` and `high` findings first.
135
+ 3. Re-run Codexray after each fix batch.
136
+ 4. Keep evidence by committing report diffs in your internal workflow.
137
+
138
+ Examples:
139
+
140
+ - `SEC001` shell execution:
141
+ - Replace dynamic shell calls with safe Python APIs.
142
+ - Avoid passing untrusted input to command execution.
143
+ - `SEC002` dangerous builtin:
144
+ - Replace `eval` or `exec` with safe parsing and strict allow-lists.
145
+ - `DEP001` unpinned dependency:
146
+ - Pin versions in requirements files with `==` where practical.
147
+
148
+ ## Troubleshooting
149
+
150
+ - `File parsing failed`:
151
+ - Check syntax errors or unsupported file encoding.
152
+ - `exceeds ... bytes/chars`:
153
+ - Increase limits in config for controlled internal usage.
154
+ - Empty findings:
155
+ - Confirm the target path includes `.py` or `.ipynb` sources.
156
+
157
+ ## Local development
158
+
159
+ ```bash
160
+ python -m pip install -e .
161
+ python -m pip install pytest ruff bandit pip-audit build twine
162
+ python -m ruff check .
163
+ python -m pytest
164
+ python -m bandit -q -r src
165
+ python -m pip-audit
166
+ python -m build
167
+ python -m twine check dist/*
168
+ ```
169
+
170
+ ## Contributing
171
+
172
+ Read `CONTRIBUTING.md` before opening a pull request.
173
+ Security reports should follow `SECURITY.md`.
174
+
175
+ ## License
176
+
177
+ MIT. See `LICENSE`.
@@ -0,0 +1,155 @@
1
+ # Codexray
2
+
3
+ Codexray is an offline-first Python static analyser for `.py` and `.ipynb` files.
4
+ It helps teams inspect security risks, code quality problems, and dependency patterns
5
+ without sending source code outside the local machine.
6
+
7
+ ## What Codexray does
8
+
9
+ - Scans Python files and notebooks.
10
+ - Supports project-level scans, full file scans, and targeted line-range checks.
11
+ - Produces a structured JSON report.
12
+ - Builds a dependency graph view with nodes and edges.
13
+ - Flags common security risks such as shell execution and dangerous builtins.
14
+
15
+ ## Privacy and security behavior
16
+
17
+ - No telemetry.
18
+ - No source upload.
19
+ - Network features are disabled by default.
20
+ - Strict input limits for file size, notebook size, snippet length, and AST depth.
21
+
22
+ This tool is designed for local analysis workflows where proprietary code must stay on the client system.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install codexray-analyser
28
+ ```
29
+
30
+ ## Quick start with CLI
31
+
32
+ Analyse a folder:
33
+
34
+ ```bash
35
+ codexray ./my_project
36
+ ```
37
+
38
+ Analyse a single file:
39
+
40
+ ```bash
41
+ codexray ./my_project/app.py
42
+ ```
43
+
44
+ Analyse a code snippet:
45
+
46
+ ```bash
47
+ codexray --snippet "import os; os.system('whoami')"
48
+ ```
49
+
50
+ Analyse only specific lines from one file:
51
+
52
+ ```bash
53
+ codexray ./my_project/app.py --start-line 40 --end-line 80
54
+ ```
55
+
56
+ Save output to JSON:
57
+
58
+ ```bash
59
+ codexray ./my_project --output codexray-report.json
60
+ ```
61
+
62
+ ## Python API usage
63
+
64
+ ```python
65
+ from codexray import analyse_file_snippet, analyse_path, analyse_snippet
66
+
67
+ project_result = analyse_path("./my_project")
68
+ snippet_result = analyse_snippet("import os\nos.system('whoami')")
69
+ range_result = analyse_file_snippet("./my_project/app.py", 20, 50)
70
+ ```
71
+
72
+ ## Understanding the report
73
+
74
+ Each result returns:
75
+
76
+ - `findings`: list of detected issues.
77
+ - `graph`: nodes and edges representing imports, files, and function relationships.
78
+ - `metadata`: run information such as analysed path and offline mode state.
79
+
80
+ Example finding shape:
81
+
82
+ ```json
83
+ {
84
+ "rule_id": "SEC002",
85
+ "title": "Dangerous builtin eval",
86
+ "severity": "critical",
87
+ "message": "Avoid eval on untrusted content.",
88
+ "file_path": "src/app.py",
89
+ "line": 18,
90
+ "column": 4
91
+ }
92
+ ```
93
+
94
+ ## Reading graph output
95
+
96
+ Graph output contains:
97
+
98
+ - `nodes`: entities such as files, imports, and functions
99
+ - `edges`: relationships such as `imports`, `contains`, and `calls`
100
+
101
+ Typical use:
102
+
103
+ 1. Run Codexray and save JSON output.
104
+ 2. Load `graph.nodes` and `graph.edges` into your graph viewer.
105
+ 3. Track dependency hotspots and risky call paths.
106
+
107
+ ## How to use findings to make code changes
108
+
109
+ Recommended workflow:
110
+
111
+ 1. Sort findings by `severity`.
112
+ 2. Fix `critical` and `high` findings first.
113
+ 3. Re-run Codexray after each fix batch.
114
+ 4. Keep evidence by committing report diffs in your internal workflow.
115
+
116
+ Examples:
117
+
118
+ - `SEC001` shell execution:
119
+ - Replace dynamic shell calls with safe Python APIs.
120
+ - Avoid passing untrusted input to command execution.
121
+ - `SEC002` dangerous builtin:
122
+ - Replace `eval` or `exec` with safe parsing and strict allow-lists.
123
+ - `DEP001` unpinned dependency:
124
+ - Pin versions in requirements files with `==` where practical.
125
+
126
+ ## Troubleshooting
127
+
128
+ - `File parsing failed`:
129
+ - Check syntax errors or unsupported file encoding.
130
+ - `exceeds ... bytes/chars`:
131
+ - Increase limits in config for controlled internal usage.
132
+ - Empty findings:
133
+ - Confirm the target path includes `.py` or `.ipynb` sources.
134
+
135
+ ## Local development
136
+
137
+ ```bash
138
+ python -m pip install -e .
139
+ python -m pip install pytest ruff bandit pip-audit build twine
140
+ python -m ruff check .
141
+ python -m pytest
142
+ python -m bandit -q -r src
143
+ python -m pip-audit
144
+ python -m build
145
+ python -m twine check dist/*
146
+ ```
147
+
148
+ ## Contributing
149
+
150
+ Read `CONTRIBUTING.md` before opening a pull request.
151
+ Security reports should follow `SECURITY.md`.
152
+
153
+ ## License
154
+
155
+ MIT. See `LICENSE`.
@@ -0,0 +1,38 @@
1
+ # Releasing to PyPI
2
+
3
+ This project uses GitHub Actions trusted publishing for PyPI.
4
+
5
+ ## One-time setup
6
+
7
+ 1. Create a GitHub repository named `codexray-analyser`.
8
+ 2. Push this code to the default branch (`main`).
9
+ 3. Create the PyPI project once with the exact package name:
10
+ - `codexray-analyser`
11
+ 4. In PyPI project settings, add a trusted publisher:
12
+ - Owner: your GitHub user/org
13
+ - Repository: `codexray-analyser`
14
+ - Workflow: `.github/workflows/publish.yml`
15
+ - Environment: `pypi`
16
+ 5. In GitHub repository settings, create environment `pypi`.
17
+
18
+ ## Release flow
19
+
20
+ 1. Update version in `pyproject.toml`.
21
+ 2. Commit and push to `main`.
22
+ 3. Create and push a tag:
23
+
24
+ ```bash
25
+ git tag v0.1.0
26
+ git push origin v0.1.0
27
+ ```
28
+
29
+ 4. GitHub Actions runs `.github/workflows/publish.yml`.
30
+ 5. On success, package is available on PyPI.
31
+
32
+ ## Local validation before tagging
33
+
34
+ ```bash
35
+ python -m pip install --upgrade pip build twine
36
+ python -m build
37
+ python -m twine check dist/*
38
+ ```
@@ -0,0 +1,26 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are provided for the latest release and the previous minor release.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Please do not open public issues for security vulnerabilities.
10
+
11
+ Report privately by contacting the maintainer with:
12
+
13
+ - A clear description of the issue
14
+ - Steps to reproduce
15
+ - Impact assessment
16
+ - Suggested remediation (if available)
17
+
18
+ You will receive an acknowledgement within 72 hours.
19
+
20
+ ## Security principles for this project
21
+
22
+ - Offline-first by default
23
+ - No telemetry
24
+ - No source upload in default flow
25
+ - Minimal dependency footprint
26
+ - CI security checks (Bandit + dependency audit)