File size: 25,800 Bytes
2db20ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | """
Repository Tech-Stack Scanner
===============================
Scans a repository and produces a Markdown table of file types with counts
and total sizes in KB. Supports every file extension in existence.
Usage:
python scan_techstack.py [path] [--output FILE] [--ignore PATTERN ...]
[--exclude-ext EXT ...] [--sort count|size|ext]
Output:
A Markdown file containing the tech-stack audit table.
"""
import os
import sys
import argparse
from pathlib import Path
from collections import defaultdict
# ---------------------------------------------------------------------------
# Comprehensive file-extension β human-readable label mapping
# Covers programming, data, document, media, archive, config, and more.
# Any extension NOT in this dict will be auto-labelled from the extension.
# ---------------------------------------------------------------------------
EXT_LABELS: dict[str, str] = {
# ββ Programming Languages ββββββββββββββββββββββββββββββββββββββββββ
".py": "Python",
".pyw": "Python (windowed)",
".pyx": "Cython",
".pxd": "Cython Definition",
".pyi": "Python Stub",
".pyc": "Python Compiled",
".pyo": "Python Optimized",
".js": "JavaScript",
".mjs": "ES Module JavaScript",
".cjs": "CommonJS JavaScript",
".jsx": "JSX (React)",
".ts": "TypeScript",
".tsx": "TSX (React)",
".java": "Java",
".class": "Java Class",
".jar": "Java Archive",
".kt": "Kotlin",
".kts": "Kotlin Script",
".scala": "Scala",
".groovy": "Groovy",
".c": "C",
".h": "C Header",
".cpp": "C++",
".cxx": "C++",
".cc": "C++",
".c++": "C++",
".hpp": "C++ Header",
".hxx": "C++ Header",
".hh": "C++ Header",
".h++": "C++ Header",
".cs": "C#",
".csx": "C# Script",
".fs": "F#",
".fsx": "F# Script",
".fsi": "F# Signature",
".vb": "Visual Basic",
".vbs": "VBScript",
".go": "Go",
".rs": "Rust",
".rb": "Ruby",
".erb": "Embedded Ruby",
".php": "PHP",
".pl": "Perl",
".pm": "Perl Module",
".lua": "Lua",
".r": "R",
".rmd": "R Markdown",
".swift": "Swift",
".m": "Objective-C / MATLAB",
".mm": "Objective-C++",
".d": "D",
".dart": "Dart",
".ex": "Elixir",
".exs": "Elixir Script",
".erl": "Erlang",
".hrl": "Erlang Header",
".hs": "Haskell",
".lhs": "Literate Haskell",
".ml": "OCaml",
".mli": "OCaml Interface",
".clj": "Clojure",
".cljs": "ClojureScript",
".cljc": "Clojure Common",
".edn": "EDN (Clojure)",
".lisp": "Common Lisp",
".cl": "Common Lisp",
".el": "Emacs Lisp",
".scm": "Scheme",
".rkt": "Racket",
".nim": "Nim",
".zig": "Zig",
".v": "V / Verilog",
".vhd": "VHDL",
".vhdl": "VHDL",
".sv": "SystemVerilog",
".asm": "Assembly",
".s": "Assembly",
".f": "Fortran",
".f90": "Fortran 90",
".f95": "Fortran 95",
".f03": "Fortran 2003",
".f08": "Fortran 2008",
".for": "Fortran",
".cob": "COBOL",
".cbl": "COBOL",
".pas": "Pascal",
".pp": "Pascal",
".ada": "Ada",
".adb": "Ada Body",
".ads": "Ada Spec",
".tcl": "Tcl",
".tk": "Tcl/Tk",
".awk": "AWK",
".sed": "sed",
".jl": "Julia",
".cr": "Crystal",
".hack": "Hack",
".hx": "Haxe",
".hxml": "Haxe XML",
".purs": "PureScript",
".idr": "Idris",
".agda": "Agda",
".lean": "Lean",
".coq": "Coq",
".thy": "Isabelle",
".pro": "Prolog",
".sml": "Standard ML",
".fig": "MATLAB Figure",
".mat": "MATLAB Data",
# ββ Shell / Scripting ββββββββββββββββββββββββββββββββββββββββββββββ
".sh": "Shell Script",
".bash": "Bash Script",
".zsh": "Zsh Script",
".fish": "Fish Script",
".bat": "Batch File",
".cmd": "Windows Command",
".ps1": "PowerShell",
".psm1": "PowerShell Module",
".psd1": "PowerShell Data",
# ββ Web / Markup / Templating ββββββββββββββββββββββββββββββββββββββ
".html": "HTML",
".htm": "HTML",
".xhtml": "XHTML",
".css": "CSS",
".scss": "SCSS",
".sass": "Sass",
".less": "Less",
".styl": "Stylus",
".vue": "Vue",
".svelte": "Svelte",
".astro": "Astro",
".ejs": "EJS Template",
".pug": "Pug Template",
".jade": "Jade Template",
".hbs": "Handlebars",
".mustache": "Mustache",
".twig": "Twig Template",
".jinja": "Jinja Template",
".jinja2": "Jinja2 Template",
".j2": "Jinja2 Template",
".njk": "Nunjucks Template",
".liquid": "Liquid Template",
".haml": "HAML",
".slim": "Slim Template",
".blade.php":"Blade Template",
".jsp": "JavaServer Pages",
".asp": "ASP",
".aspx": "ASP.NET",
".cshtml": "Razor (C#)",
".razor": "Razor",
".wasm": "WebAssembly",
# ββ Data / Config / Serialisation ββββββββββββββββββββββββββββββββββ
".json": "JSON",
".jsonl": "JSON Lines",
".json5": "JSON5",
".geojson": "GeoJSON",
".xml": "XML",
".xsl": "XSLT",
".xslt": "XSLT",
".xsd": "XML Schema",
".dtd": "Document Type Definition",
".yaml": "YAML",
".yml": "YAML",
".toml": "TOML",
".ini": "INI Config",
".cfg": "Config",
".conf": "Config",
".env": "Environment File",
".properties": "Properties File",
".csv": "CSV",
".tsv": "TSV",
".parquet": "Apache Parquet",
".avro": "Apache Avro",
".orc": "Apache ORC",
".feather": "Feather (Arrow)",
".arrow": "Apache Arrow",
".msgpack": "MessagePack",
".bson": "BSON",
".cbor": "CBOR",
".protobuf": "Protocol Buffer",
".proto": "Protocol Buffer Schema",
".thrift": "Apache Thrift",
".hcl": "HCL (Terraform)",
".tf": "Terraform",
".tfvars": "Terraform Variables",
".pkl": "Pickle",
".pickle": "Pickle",
".npy": "NumPy Array",
".npz": "NumPy Archive",
".h5": "HDF5",
".hdf5": "HDF5",
".nc": "NetCDF",
".sqlite": "SQLite Database",
".sqlite3": "SQLite Database",
".db": "Database",
".dbf": "dBASE",
".mdb": "Access Database",
".accdb": "Access Database",
".lmdb": "LMDB",
".leveldb": "LevelDB",
# ββ Documents & Office βββββββββββββββββββββββββββββββββββββββββββββ
".md": "Markdown",
".mdx": "MDX",
".txt": "Plain Text",
".text": "Plain Text",
".log": "Log File",
".rst": "reStructuredText",
".adoc": "AsciiDoc",
".org": "Org Mode",
".tex": "LaTeX",
".latex": "LaTeX",
".bib": "BibTeX",
".rtf": "Rich Text Format",
".doc": "Microsoft Word",
".docx": "Microsoft Word (OOXML)",
".odt": "OpenDocument Text",
".pdf": "PDF",
".xls": "Microsoft Excel",
".xlsx": "Microsoft Excel (OOXML)",
".xlsm": "Excel Macro-Enabled",
".xlsb": "Excel Binary",
".ods": "OpenDocument Spreadsheet",
".ppt": "Microsoft PowerPoint",
".pptx": "Microsoft PowerPoint (OOXML)",
".odp": "OpenDocument Presentation",
".pages": "Apple Pages",
".numbers": "Apple Numbers",
".key": "Apple Keynote",
".epub": "EPUB",
".mobi": "Mobipocket",
".djvu": "DjVu",
".chm": "Compiled HTML Help",
".man": "Man Page",
".info": "GNU Info",
# ββ Notebooks & Data Science βββββββββββββββββββββββββββββββββββββββ
".ipynb": "Jupyter Notebook",
".rmd": "R Markdown",
".qmd": "Quarto Document",
".dvc": "DVC File",
".onnx": "ONNX Model",
".pt": "PyTorch Model",
".pth": "PyTorch Checkpoint",
".safetensors": "SafeTensors Model",
".gguf": "GGUF Model",
".bin": "Binary File",
# ββ Images βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
".png": "PNG Image",
".jpg": "JPEG Image",
".jpeg": "JPEG Image",
".gif": "GIF Image",
".bmp": "Bitmap Image",
".tiff": "TIFF Image",
".tif": "TIFF Image",
".webp": "WebP Image",
".avif": "AVIF Image",
".heic": "HEIC Image",
".heif": "HEIF Image",
".svg": "SVG Image",
".ico": "Icon",
".icns": "Apple Icon",
".cur": "Cursor",
".psd": "Photoshop",
".ai": "Adobe Illustrator",
".sketch": "Sketch",
".fig": "Figma",
".xd": "Adobe XD",
".eps": "EPS Vector",
".raw": "RAW Image",
".cr2": "Canon RAW",
".nef": "Nikon RAW",
".arw": "Sony RAW",
".dng": "DNG RAW",
".exr": "OpenEXR",
".hdr": "HDR Image",
".pbm": "PBM Image",
".pgm": "PGM Image",
".ppm": "PPM Image",
".pcx": "PCX Image",
".tga": "TGA Image",
# ββ Audio ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
".mp3": "MP3 Audio",
".wav": "WAV Audio",
".flac": "FLAC Audio",
".aac": "AAC Audio",
".ogg": "Ogg Audio",
".wma": "WMA Audio",
".m4a": "M4A Audio",
".opus": "Opus Audio",
".aiff": "AIFF Audio",
".mid": "MIDI",
".midi": "MIDI",
".amr": "AMR Audio",
".ape": "APE Audio",
".alac": "ALAC Audio",
# ββ Video ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
".mp4": "MP4 Video",
".mkv": "MKV Video",
".avi": "AVI Video",
".mov": "QuickTime Video",
".wmv": "WMV Video",
".flv": "Flash Video",
".webm": "WebM Video",
".m4v": "M4V Video",
".mpg": "MPEG Video",
".mpeg": "MPEG Video",
".3gp": "3GP Video",
".ogv": "Ogg Video",
".ts": "MPEG-TS",
".vob": "DVD Video",
".rm": "RealMedia",
# ββ Fonts ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
".ttf": "TrueType Font",
".otf": "OpenType Font",
".woff": "WOFF Font",
".woff2": "WOFF2 Font",
".eot": "EOT Font",
".fon": "Bitmap Font",
# ββ Archives / Compression βββββββββββββββββββββββββββββββββββββββββ
".zip": "ZIP Archive",
".gz": "Gzip Archive",
".gzip": "Gzip Archive",
".bz2": "Bzip2 Archive",
".xz": "XZ Archive",
".lz": "Lzip Archive",
".lzma": "LZMA Archive",
".zst": "Zstandard Archive",
".tar": "Tar Archive",
".tgz": "Tar+Gzip Archive",
".tbz2": "Tar+Bzip2 Archive",
".txz": "Tar+XZ Archive",
".rar": "RAR Archive",
".7z": "7-Zip Archive",
".cab": "Cabinet Archive",
".iso": "ISO Disk Image",
".dmg": "macOS Disk Image",
".img": "Disk Image",
".vhd": "Virtual Hard Disk",
".vhdx": "Virtual Hard Disk (VHDX)",
".vmdk": "VMware Disk",
".qcow2": "QEMU Disk",
".deb": "Debian Package",
".rpm": "RPM Package",
".apk": "Android Package",
".ipa": "iOS App",
".snap": "Snap Package",
".flatpak": "Flatpak Package",
".appimage": "AppImage",
".msi": "MSI Installer",
".exe": "Windows Executable",
".dll": "DLL Library",
".so": "Shared Object",
".dylib": "macOS Dynamic Library",
".a": "Static Library",
".lib": "Library",
".o": "Object File",
".obj": "Object File",
".sys": "System File",
".drv": "Driver",
# ββ DevOps / CI / Containerisation βββββββββββββββββββββββββββββββββ
".dockerfile":"Dockerfile",
".vagrantfile":"Vagrantfile",
".jenkinsfile":"Jenkinsfile",
# ββ Trading / Domain-specific ββββββββββββββββββββββββββββββββββββββ
".mq5": "MQL5 Source",
".mq4": "MQL4 Source",
".mqh": "MQL Header",
".ex5": "MQL5 Compiled",
".ex4": "MQL4 Compiled",
".set": "MT Parameter Set",
".pine": "Pine Script",
".tpl": "MT Template",
".chr": "MT Chart",
".mql": "MQL Source",
# ββ Misc / Build / Project βββββββββββββββββββββββββββββββββββββββββ
".makefile": "Makefile",
".cmake": "CMake",
".gradle": "Gradle",
".sbt": "SBT Build",
".gemspec": "Ruby Gem Spec",
".podspec": "CocoaPods Spec",
".cabal": "Cabal (Haskell)",
".csproj": "C# Project",
".fsproj": "F# Project",
".vbproj": "VB.NET Project",
".sln": "Visual Studio Solution",
".xcodeproj":"Xcode Project",
".pbxproj": "Xcode Project (PBX)",
".xcworkspace":"Xcode Workspace",
".plist": "Property List",
".lnk": "Windows Shortcut",
".url": "URL Shortcut",
".desktop": "Desktop Entry",
".reg": "Windows Registry",
".service": "Systemd Service",
".timer": "Systemd Timer",
".socket": "Systemd Socket",
".lock": "Lock File",
".patch": "Patch File",
".diff": "Diff File",
".map": "Source Map",
".whl": "Python Wheel",
".egg": "Python Egg",
".gem": "Ruby Gem",
".nupkg": "NuGet Package",
".crate": "Rust Crate",
# ββ SQL / Database βββββββββββββββββββββββββββββββββββββββββββββββββ
".sql": "SQL",
".mysql": "MySQL",
".pgsql": "PostgreSQL",
".plsql": "PL/SQL",
# ββ GraphQL / API ββββββββββββββββββββββββββββββββββββββββββββββββββ
".graphql": "GraphQL",
".gql": "GraphQL",
".swagger": "Swagger",
".openapi": "OpenAPI Spec",
# ββ 3D / CAD / GIS βββββββββββββββββββββββββββββββββββββββββββββββββ
".stl": "STL 3D Model",
".obj": "Wavefront OBJ",
".fbx": "FBX 3D Model",
".gltf": "glTF 3D Model",
".glb": "glTF Binary",
".blend": "Blender File",
".3ds": "3DS Model",
".dae": "Collada",
".usd": "USD Scene",
".usda": "USD ASCII",
".usdc": "USD Binary",
".step": "STEP CAD",
".stp": "STEP CAD",
".iges": "IGES CAD",
".igs": "IGES CAD",
".dwg": "AutoCAD Drawing",
".dxf": "AutoCAD Exchange",
".shp": "Shapefile",
".kml": "KML",
".kmz": "KMZ",
".gpx": "GPX Track",
# ββ Certificates / Security ββββββββββββββββββββββββββββββββββββββββ
".pem": "PEM Certificate",
".crt": "Certificate",
".cer": "Certificate",
".csr": "Certificate Request",
".p12": "PKCS#12",
".pfx": "PKCS#12",
".asc": "PGP/GPG",
".gpg": "GPG Encrypted",
".sig": "Signature",
".pub": "Public Key",
# ββ Git-related ββββββββββββββββββββββββββββββββββββββββββββββββββββ
".gitignore": "Git Ignore",
".gitattributes": "Git Attributes",
".gitmodules": "Git Submodules",
# ββ Editor / IDE Config ββββββββββββββββββββββββββββββββββββββββββββ
".editorconfig": "EditorConfig",
".prettierrc": "Prettier Config",
".eslintrc": "ESLint Config",
".stylelintrc": "Stylelint Config",
".babelrc": "Babel Config",
".swcrc": "SWC Config",
".nvmrc": "NVM Config",
".npmrc": "NPM Config",
".yarnrc": "Yarn Config",
# ββ Misc βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
".mw5": "MQL5 Variant",
".webmanifest": "Web App Manifest",
}
# ---------------------------------------------------------------------------
# Default ignore patterns (common non-source dirs / files)
# ---------------------------------------------------------------------------
DEFAULT_IGNORE = {
".git",
"__pycache__",
".venv",
"venv",
"env",
"node_modules",
".ipynb_checkpoints",
".mypy_cache",
".pytest_cache",
".tox",
".eggs",
"*.egg-info",
".DS_Store",
"Thumbs.db",
"desktop.ini",
}
def should_ignore(name: str, ignore_set: set) -> bool:
"""Return True if *name* matches any pattern in the ignore set."""
if name in ignore_set:
return True
for pattern in ignore_set:
if pattern.startswith("*") and name.endswith(pattern[1:]):
return True
return False
def get_label(ext: str) -> str:
"""Return the human-readable label for an extension."""
if ext in EXT_LABELS:
return EXT_LABELS[ext]
# Fallback: capitalise the extension name
return ext.upper().lstrip(".")
def scan_files(root_path: str, ignore_set: set, exclude_exts: set) -> dict:
"""
Walk *root_path* and collect per-extension statistics.
Returns a dict keyed by normalised extension string, e.g. ".py",
with values ``{"count": int, "size_bytes": int, "label": str}``.
Files without an extension are grouped under "(no extension)".
"""
stats: dict = defaultdict(lambda: {"count": 0, "size_bytes": 0, "label": ""})
for dirpath, dirnames, filenames in os.walk(root_path):
# Prune ignored directories in-place so os.walk skips them
dirnames[:] = [
d for d in dirnames if not should_ignore(d, ignore_set)
]
for fname in filenames:
if should_ignore(fname, ignore_set):
continue
filepath = os.path.join(dirpath, fname)
# Determine extension
_, ext = os.path.splitext(fname)
ext = ext.lower() # normalise
if ext and ext.lstrip(".") in exclude_exts:
continue
# Label
if ext:
label = f"{get_label(ext)} ({ext})"
else:
ext = "(none)"
label = "(no extension)"
try:
size = os.path.getsize(filepath)
except (OSError, PermissionError):
size = 0
stats[ext]["count"] += 1
stats[ext]["size_bytes"] += size
stats[ext]["label"] = label
return dict(stats)
def format_size_kb(size_bytes: int) -> str:
"""Return exact size in KB, rounded to 1 decimal place."""
kb = size_bytes / 1024
if kb == 0:
return "0"
# Show 1 decimal place for precision, strip trailing zero if whole number
formatted = f"{kb:,.1f}"
return formatted
def build_table(stats: dict, sort_by: str) -> list[str]:
"""
Build a Markdown table from *stats*.
Returns a list of lines.
"""
# Prepare rows
rows = []
total_count = 0
total_bytes = 0
for ext, data in stats.items():
rows.append(
{
"label": data["label"],
"count": data["count"],
"size_bytes": data["size_bytes"],
"ext_key": ext,
}
)
total_count += data["count"]
total_bytes += data["size_bytes"]
# Sort
if sort_by == "count":
rows.sort(key=lambda r: (-r["count"], r["label"].lower()))
elif sort_by == "size":
rows.sort(key=lambda r: (-r["size_bytes"], r["label"].lower()))
else: # "ext"
rows.sort(key=lambda r: r["label"].lower())
# Build Markdown lines
lines = [
"| File Type | Count | Size (KB) |",
"| :--- | :--- | :--- |",
]
for row in rows:
lines.append(
f"| {row['label']} | {row['count']} | {format_size_kb(row['size_bytes'])} |"
)
# Totals row
lines.append(f"| **Total** | **{total_count}** | **{format_size_kb(total_bytes)}** |")
return lines
def main() -> None:
parser = argparse.ArgumentParser(
description="Audit repository tech-stack (file types, counts, sizes)."
)
parser.add_argument(
"path",
nargs="?",
default=".",
help="Root directory to scan (default: current directory).",
)
parser.add_argument(
"--output",
"-o",
default=None,
help="Output Markdown file path (default: TECHSTACK.md in scanned dir).",
)
parser.add_argument(
"--ignore",
nargs="*",
default=None,
help="Extra directory/file names to ignore.",
)
parser.add_argument(
"--no-default-ignore",
action="store_true",
help="Disable the built-in ignore list.",
)
parser.add_argument(
"--exclude-ext",
nargs="*",
default=None,
help="File extensions to exclude from output (without dot, e.g. png mp4 git).",
)
parser.add_argument(
"--sort",
choices=["count", "size", "ext"],
default="count",
help="Sort order for the table (default: count descending).",
)
args = parser.parse_args()
root = os.path.abspath(args.path)
root_name = os.path.basename(root)
# Build ignore set
ignore_set: set = set() if args.no_default_ignore else set(DEFAULT_IGNORE)
if args.ignore:
ignore_set.update(args.ignore)
# Always ignore the output file itself
out_path = args.output or os.path.join(root, "TECHSTACK.md")
out_name = os.path.basename(out_path)
ignore_set.add(out_name)
# Excluded extensions
exclude_exts: set = set()
if args.exclude_ext:
exclude_exts = {e.lower().lstrip(".") for e in args.exclude_ext}
print(f"Scanning: {root}")
print(f"Ignoring: {', '.join(sorted(ignore_set))}")
if exclude_exts:
print(f"Excluding extensions: {', '.join(sorted(exclude_exts))}")
stats = scan_files(root, ignore_set, exclude_exts)
table_lines = build_table(stats, sort_by=args.sort)
# Compose Markdown
md_lines = [
f"## Techstack\n",
f"Audit of **{root_name}** project files (excluding environment and cache):\n",
]
md_lines.extend(table_lines)
md_lines.append("") # trailing newline
content = "\n".join(md_lines)
with open(out_path, "w", encoding="utf-8") as fh:
fh.write(content)
total = sum(d["count"] for d in stats.values())
print(f"Done β {total} files across {len(stats)} types written to {out_path}")
if __name__ == "__main__":
main()
|