Repository navigation
Tags
Tags
release: 0.4.0 (#74) * release: 0.4.0 New commands and flags - pywho doctor: health checks for the usual environment problems: an activated venv that is not the running Python, pip and python from different environments, PYTHONPATH/PYTHONHOME, missing sys.path entries, packages installed in two versions, package folders without metadata, stale .pth files, externally managed Pythons (PEP 668). Exit code 1 when a check fails. - pywho diff A B: compare two `pywho --json --packages` snapshots. - --python PATH on every command: run inside another interpreter or virtual environment without installing pywho there. This makes `uvx pywho --python .venv` describe the project, not uv's tool folder. - pywho trace names the installed package behind a module, the tool that installed it and the packages that require it. Fixes from the code audit - trace missed shadows in the current folder when run as the installed command; scan reported project files as shadowing themselves. - Crash (on Python 3.15: an empty list) on a package folder without metadata; package location was one folder above site-packages. - A venv on top of conda was reported as conda; virtualenv 20+ as venv. - A local file hiding a stdlib module was labelled stdlib; namespace packages showed as NOT FOUND; os and os.path showed "frozen". - --json before a subcommand was ignored; --version printed 0.3.3. - Colour codes leaked into redirected output on Windows Terminal, and redirected output could fail with UnicodeEncodeError. - `python -m pywho` imported project files named like the modules pywho itself uses (json.py, enum.py). Hardening - python, pip and a --python name are looked up in the PATH folders only, never in the current folder (Windows). - Control characters in file names, snapshots and package metadata are escaped before printing. - trace leaves no __pycache__ folders in the traced project. Speed - The default report no longer starts a second interpreter for the pip version, and package metadata is read without parsing descriptions: the report and `scan` run two to three times faster. Housekeeping - One source for the version (src/pywho/__init__.py), one ruff config (target py310), pre-commit hooks updated to the versions CI uses. - Removed the dead Python 3.9 stdlib list, MANIFEST.in and the duplicate GitHub Pages docs workflow (docs live on Read the Docs). - README, docs, CHANGELOG and SECURITY.md updated. * fix: judge .pth files by the locale's real encoding doctor fell back to locale.getpreferredencoding(), which answers "utf-8" in UTF-8 mode (the default from Python 3.15). A .pth file written in the ANSI code page was then misread and reported as stale. Use locale.getencoding() where it exists, as site.py does. Docs: `uv run --with pywho pywho` runs in uv's temporary environment; recommend `uvx` or `pipx run` together with `--python` instead. * fix: tests pass without a virtual environment, plus portability fixes CI installs into the runner's own Python (no venv). One test compared sys.path against the folder of sys.executable, and Windows lists the base Python's folder on the sys.path of every environment: every windows job would have failed. A second test failed the same way under /usr/bin/python3. - doctor: a free-threaded Python (pythonXYt.zip) and the marker setuptools adds for an editable install (*.__path_hook__) are no longer reported as sys.path entries that do not exist. - report: the user site-packages folder is listed only when Python uses it, so not inside a virtual environment. - trace: the Package line is found for a package that is linked into site-packages (Homebrew, Nix, stow). - --python: a relative interpreter path is made absolute. Windows refused to start one written with "/" when NoDefaultCurrentDirectoryInExePath is set. * fix: scan line breaks, --python env, tests independent of the shell - scan: "No shadows detected." was printed with its line breaks escaped as \x0a, because colorize() escapes every control character. - --python NAME: only a name that reads as an interpreter (starts with "py") is refused when it is both a folder here and a command on PATH. `--python env` on Linux hit /usr/bin/env and was refused. - tests: an autouse fixture pins NO_COLOR and clears FORCE_COLOR, PIPENV_ACTIVE and POETRY_ACTIVE (13 tests failed with FORCE_COLOR=1, one inside a pipenv shell), restores sys.dont_write_bytecode and drops the throw-away *_xyz packages from sys.modules. - tests: .cmd shims are written in the OEM code page, so a non-ASCII interpreter path works on Windows. - tests: new guards for --python before every subcommand, run_doctor's wiring, --json without packages, RECORD lines after the first one and mixed-case module names. - docs: how a --python name is read; SECURITY.md notes that import hooks asked during a trace see the current folder first. * test: cover the entry points and unreadable-file paths Codecov compares the PR with main (97.02%). Branch coverage on Linux 3.12 was 96.67% counted Codecov's way (partial branches as partial lines). - tests run python -m pywho in-process, import _bootstrap, and cover norm_path without a current folder, a python command that cannot start, a folder named *.pth, a folder that cannot be listed and a RECORD file that is not text. - cli.py: drop the unused __main__ block; python -m pywho runs pywho/__main__.py. Now 98.12% the Codecov way. * docs: date the 0.4.0 changelog entry
feat: add project-wide shadow scanner (pywho scan) (#3) Add `pywho scan` subcommand that recursively scans directories for .py files shadowing stdlib or installed packages. Includes severity levels (HIGH for stdlib, MEDIUM for installed), smart directory exclusions, JSON output, and Python API via scan_path(). Revamp README with badges, table of contents, and quick-reference command table. Co-authored-by: ahsan.sheraz <ahsan.sheraz@bonial.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
feat: add import resolution tracer (pywho trace) (#1) * feat: add import resolution tracer (pywho trace) New `pywho trace <module>` subcommand that explains where an import resolves and why. Includes sys.path search order, module classification, cache detection, and shadow warnings. - tracer.py: core trace engine with trace_import() API - trace_formatter.py: colored terminal output for trace reports - CLI: `pywho trace <module>` with --verbose and --json flags - 21 new tests (53 total) - Updated README, docs, API reference, and CHANGELOG - Version bump to 0.2.0 * fix: classify site-packages modules before stdlib path check On macOS system Python, site-packages lives under the same prefix as stdlib. Check for 'site-packages' in origin path first to correctly classify third-party packages on all platforms. --------- Co-authored-by: ahsan.sheraz <ahsan.sheraz@bonial.com>