Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm trying to force Ruff to check and format my *.spec script for PyInstaller.

So far I added to pyproject.toml this table:

[tool.ruff]
include = [
    "*.py",
    "*.pyi",
    "*.ipynb",
    "pyproject.toml",
    # PyInstaller
    "*.spec",
]

But it only works with manual uv run ruff check.
When I run pre-commit run ruff-check, it says there is (no files to check).

Pre-commit hook is shamelessly copied from Astral-sh repo:

.pre-commit-config.yaml:

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.15.16
    hooks:
      - id: ruff-format
      - id: ruff-check
        args: [--fix, --exit-non-zero-on-fix]

I guess I should add some magic types_or: key to the hook's config, but what should it be set to?

You must be logged in to vote

This sounds like it might be a pre-commit question rather than a Ruff question, but I've used the identify-cli command described in https://pre-commit.com/#filtering-files-with-types before to check the file type that pre-commit will detect. It looks like there is a spec type, so that might be just what you need!

uvx --from identify identify-cli try.spec
["file", "non-executable", "spec", "text"]

Replies: 1 comment · 4 replies

Comment options

This sounds like it might be a pre-commit question rather than a Ruff question, but I've used the identify-cli command described in https://pre-commit.com/#filtering-files-with-types before to check the file type that pre-commit will detect. It looks like there is a spec type, so that might be just what you need!

uvx --from identify identify-cli try.spec
["file", "non-executable", "spec", "text"]
You must be logged in to vote
4 replies
@ratijas
Comment options

Thanks! This works for me:

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.15.16
    hooks:
      - id: ruff-format
        types_or: [python, spec]
      - id: ruff-check
        types_or: [python, spec]
        args: [--fix, --exit-non-zero-on-fix]

I sure hope spec thing won't catch something irrelevant, but that would be a problem of my future self (:

@ratijas
Comment options

(on a side note, PyInstaller kinda sucks for choosing to use a custom file extension which no editor or tool would ever recognize as Python code, and injecting implicit imports and properties such that -- even if you convince your editor/LSP to recognize it as Python -- there is no way it would "just work" or autocomplete, ehhh)

@Avasam
Comment options

for implicit import and properties:

TYPE_CHECKING = false

if TYPE_CHECKING:
    from implicit_import import *
    # I use pyinstaller, but I don't remember the spec import symbols locations by heart

I've also made sure all typed symbols you may need here are available in types-pyinstaller (even if internal/private) ever since I added the stubs to typeshed :) So you should be able to even type-check spec files.

@ratijas
Comment options

I imported everything explicitly, and it worked. But it's cool to have more options, I guess

Answer selected by ratijas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.