|
oct
|
Functions | |
| list[str] | _scan_content_for_secrets (str content, str rel_path) |
| list[str] | _get_cached_secret_warnings (str abs_path, str content, str rel_path) |
| dict | load_exporter_config (Path root) |
| bool | should_skip_dirname (str dirname, dict cfg) |
| bool | _is_never_export_file (str filename) |
| List[Path] | collect_recursive_files (Path folder, dict cfg) |
| Tuple[int, int, int] | get_file_stats (Path path) |
| Iterator[Path] | walk_included_dirs (Path start, dict cfg) |
| Tuple[int, List[Path]] | clean_matching_dirs (Path root, str kind, Callable[[str], bool] matches, bool dry_run=False) |
| Tuple[int, List[Path]] | clean_source_dirs (Path root, bool dry_run=False) |
| Tuple[int, List[Path]] | clean_pycache_dirs (Path root, bool dry_run=False) |
| Path | _make_safe_output_path (Path out_dir, str dotpath, dict cfg, str prefix="_source") |
| Tuple[int, int, int, int, list] | write_source_file_for_dir (Path folder, Path output_path, Path root, dict cfg, bool warn_secrets=False, bool block_secrets=False, set[Path]|None diff_filter=None) |
| None | run_exporter (Path root, list[str] args) |
Variables | |
| _SECRET_ASSIGN_RE | |
| dict | _secret_scan_cache = {} |
| set | _scanned_secret_paths = set() |
| dict | _EXTENSION_PROFILES |
| list | INCLUDE_EXTENSIONS = [ext for exts in _EXTENSION_PROFILES.values() for ext in exts] |
| tuple | HEADER_TEXT |
| str | SEPARATOR_FILE = "##### File name {num:02d}: {path}\n" |
| str | SEPARATOR_SUBDIR = "####### Subdirectory name {num:02d}: {dirname}\n" |
| str | ROOT_HEADER = "####### Root directory: .\n\n" |
| int | _MAX_SAFE_PATH_LEN = 240 |
| str | _CONFIG_FILENAME = "_oct_exporter_config.json" |
Purpose
-------
Provide a unified, Option C‑compliant source‑exporting tool that collects,
combines, and consolidates all source‑code files in a project into structured
inspection files. This enables fast review, debugging, auditing, and
cross‑project comparison.
Responsibilities
----------------
- Walk a project directory tree while respecting exclusion rules.
- Collect all source files with supported extensions.
- Generate per‑directory `_source.<path>.txt` files.
- Generate a root‑level `_full_source.<root>.txt` file.
- Support `--clean` to remove all `_source_code-*` directories.
- Remove export and cache directories for real: clear the read-only
attribute on anything that refuses, count only what is gone, and name
what could not be removed (2026-09-07; `oct clean` used to report
"Removed N" while every read-only directory survived).
- Support `--verbose` to print per‑file statistics.
- Integrate cleanly with the OCT CLI as `oct export-source`.
- Handle I/O errors (including Windows MAX_PATH) gracefully: warn and continue.
Diagnostics
-----------
Domain: OCT-EXPORTER
Levels:
L2 - lifecycle
L3 - semantic details
L4 - deep tracing
Contracts
---------
- Must not modify project files except inside `_source_code-*` directories.
- Must accept any directory as a valid export root.
- Must remain deterministic and safe for large projects.
- Must not require external dependencies beyond the standard library.
- Must never crash on a recoverable I/O error; warn and continue instead.
Dependencies
------------
- oct.core.exclusions (the shared exclusion rules)
- fnmatch (stdlib glob matching for exclusion patterns)
- hashlib (stdlib digest for the MAX_PATH-safe output names)
- json (stdlib config parsing)
- os (stdlib directory walk)
- re (stdlib shallow secret guard)
- sys (stdlib interpreter version and streams)
- datetime (stdlib export timestamp)
- pathlib (stdlib paths)
- oct.core.diagnostics (_dbg structured logger)
- oct.tools.fs_remove (remove_tree_force for read-only-safe directory removal; re-exported)
- oct.core.git (lazy; git_diff_name_only for the --diff filter)
- oct.tools.secret_scanner (lazy; the shared secret-name heuristics for the content guard)
|
protected |
Return (cached or computed) secret warnings for ``abs_path``.
Definition at line 120 of file source_exporter.py.
|
protected |
Check if a file matches NEVER_EXPORT_FILE_PATTERNS (§6b Secret Hygiene).
Definition at line 277 of file source_exporter.py.
|
protected |
Build the output file path, truncating the dotpath if the full path would exceed the Windows MAX_PATH limit (~260 chars). A short MD5 hash suffix is appended when truncation is applied to ensure uniqueness.
Definition at line 374 of file source_exporter.py.
|
protected |
Scan ``content`` for likely hardcoded secrets. Returns warning strings. Uses the same name-heuristics as the linter (``_SECRET_NAME_PATTERNS``). Empty list means no warnings. The ``rel_path`` is embedded in each warning for user attribution.
Definition at line 86 of file source_exporter.py.
| Tuple[int, List[Path]] source_exporter.clean_matching_dirs | ( | Path | root, |
| str | kind, | ||
| Callable[[str], bool] | matches, | ||
| bool | dry_run = False ) |
Remove every directory under *root* whose name satisfies *matches*. Returns ``(removed, failed)``: *removed* counts directories that are gone (or would be, under *dry_run*), *failed* lists the ones still present afterwards. Both are printed; a failure is never silent.
Definition at line 327 of file source_exporter.py.
| Tuple[int, List[Path]] source_exporter.clean_pycache_dirs | ( | Path | root, |
| bool | dry_run = False ) |
Remove all ``__pycache__`` directories under *root*; see :func:`clean_matching_dirs`.
Definition at line 369 of file source_exporter.py.
| Tuple[int, List[Path]] source_exporter.clean_source_dirs | ( | Path | root, |
| bool | dry_run = False ) |
Remove all ``_source_code-*`` directories under *root*; see :func:`clean_matching_dirs`.
Definition at line 362 of file source_exporter.py.
| List[Path] source_exporter.collect_recursive_files | ( | Path | folder, |
| dict | cfg ) |
Definition at line 286 of file source_exporter.py.
| Tuple[int, int, int] source_exporter.get_file_stats | ( | Path | path | ) |
| dict source_exporter.load_exporter_config | ( | Path | root | ) |
Load optional per-project config, merging with module-level defaults.
Definition at line 177 of file source_exporter.py.
| None source_exporter.run_exporter | ( | Path | root, |
| list[str] | args ) |
Execute the source exporter with the given root directory and arguments.
Definition at line 470 of file source_exporter.py.
| bool source_exporter.should_skip_dirname | ( | str | dirname, |
| dict | cfg ) |
| Iterator[Path] source_exporter.walk_included_dirs | ( | Path | start, |
| dict | cfg ) |
Definition at line 317 of file source_exporter.py.
| Tuple[int, int, int, int, list] source_exporter.write_source_file_for_dir | ( | Path | folder, |
| Path | output_path, | ||
| Path | root, | ||
| dict | cfg, | ||
| bool | warn_secrets = False, | ||
| bool | block_secrets = False, | ||
| set[Path] | None | diff_filter = None ) |
Definition at line 397 of file source_exporter.py.
|
protected |
Definition at line 170 of file source_exporter.py.
|
protected |
Definition at line 131 of file source_exporter.py.
|
protected |
Definition at line 168 of file source_exporter.py.
|
protected |
Definition at line 117 of file source_exporter.py.
|
protected |
Definition at line 79 of file source_exporter.py.
|
protected |
Definition at line 115 of file source_exporter.py.
| tuple source_exporter.HEADER_TEXT |
Definition at line 153 of file source_exporter.py.
| list source_exporter.INCLUDE_EXTENSIONS = [ext for exts in _EXTENSION_PROFILES.values() for ext in exts] |
Definition at line 142 of file source_exporter.py.
| str source_exporter.ROOT_HEADER = "####### Root directory: .\n\n" |
Definition at line 165 of file source_exporter.py.
| str source_exporter.SEPARATOR_FILE = "##### File name {num:02d}: {path}\n" |
Definition at line 163 of file source_exporter.py.
| str source_exporter.SEPARATOR_SUBDIR = "####### Subdirectory name {num:02d}: {dirname}\n" |
Definition at line 164 of file source_exporter.py.