Skip to content

Add a python -m magic entry point - #370

Open
dailyun wants to merge 2 commits into
ahupp:masterfrom
dailyun:codex/module-cli-337
Open

dailyun wants to merge 2 commits into
ahupp:masterfrom
dailyun:codex/module-cli-337

Conversation

@dailyun

@dailyun dailyun commented Oct 20, 2026 •

Copy link
Copy Markdown

Closes #337.

Add python -m magic FILE... using the existing from_file() API, plus --mime for MIME output. File-access and libmagic exceptions are reported on stderr without stopping the remaining files; the command returns 1 if any of those calls failed.

The tests use Popen.communicate(), os.path, tmpdir, and legacy-compatible formatting to follow the supported tox matrix.

Six new tests cover descriptions, MIME output, a missing file followed by a valid file, Unicode paths, missing arguments, and a libmagic exception. All six fail without the entry point. The full suite passes with 20 passed and 2 existing skips; mypy and Ruff checks pass. Both wheel and sdist build and contain the entry point, and the installed wheel was smoke-tested outside the checkout on Python 3.13/macOS arm64 with libmagic 5.48. The six CLI tests also pass in an official Python 3.5.10 Linux container with real libmagic. On Python 2.7.18, the CLI and test source compile, and CLI argument/error-flow checks pass with a stub backend; the full Python 2.7 suite was not run. Other Python/platform combinations were not run locally.

No new dependencies or changes to the recognition API. Prepared and tested with OpenAI Codex; not human-reviewed before submission.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T15:44:48.893352Z 946690f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 946690f4be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/cli_test.py Outdated
Comment on lines +13 to +17
return subprocess.run(
[sys.executable, "-m", "magic"] + list(args),
cwd=str(ROOT),
check=False,
capture_output=True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep CLI tests compatible with the supported runtimes

When the documented default tox matrix is run with the interpreters listed in tox.ini (py27, py35, and py36), this helper cannot execute: Python 2.7 has no subprocess.run, capture_output was added only in Python 3.7, and the f-strings later in this file fail to parse before Python 3.6. Because setup.py:32 still advertises Python 2.7+ and these environments remain explicitly configured, this commit makes those test jobs fail before exercising the entry point; use subprocess and formatting/path APIs available across the supported matrix.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e927a9a: the helper now uses Popen.communicate() and os.path; f-strings, capture_output, text, and the newer tmp_path fixture are gone. Native Python 3.13 full suite still passes (20 passed, 2 skipped). I also ran all six CLI tests with real libmagic in an official Python 3.5.10 Linux container: all passed. Python 2.7.18 compiles both source files and passes CLI argument/error-flow checks with a stub backend; I have not run its full suite. The PR validation notes now distinguish those scopes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow command line execution

1 participant