InSyncWithFoo / ryecharm

The all-in-one PyCharm plugin for Astral-backed Python tools
https://insyncwithfoo.github.io/ryecharm/
MIT License
65 stars 2 forks source link

ryecharm run ruff on rst file #5

Closed trim21 closed 1 month ago

trim21 commented 1 month ago

What happened?

ryecharm run ruff on rst file and report syntax error

image

looks like it run ruff on rst file directly ruff check .\docs\enum.rst

image

image

Steps to reproduce

create a rst file and open it with ryecharm plugin

Relevant log output or stack trace

No response

Operating system

None

InSyncWithFoo commented 1 month ago

I'm afraid I can't reproduce the problem in any running mode.

What are your settings? Have you tried restarting the IDE and/or your computer?

If restarting doesn't work, could you check the logs (Ctrl + Shift + AShow Log in Explorer) and let me see its content? An email is fine if you don't want to post it publicly: <myusername>@gmail.com.

trim21 commented 1 month ago

image

trim21 commented 1 month ago
2024-09-20 02:26:05,989 [94317252]   INFO - #c.i.a.o.PathMacrosImpl - Saved path macros: {}
2024-09-20 02:26:16,220 [94327483]   INFO - #insyncwithfoo.ryecharm.Command - Running: (C:\Users\Trim21\proj\python\transmission-rpc) C:\Users\Trim21\scoop\shims\ruff.exe check --no-fix --exit-zero --quiet - --output-format json --stdin-filename C:\Users\Trim21\proj\python\transmission-rpc\docs\client.rst
2024-09-20 02:26:16,274 [94327537]   INFO - #insyncwithfoo.ryecharm.Command - <long output content removed>
trim21 commented 1 month ago

my ruff config:


[tool.ruff]
target-version = "py38"
extend-exclude = ["docs"]
line-length = 120

[tool.ruff.lint]
select = [
    "B",
    "C",
    "E",
    "F",
    "G",
    "I",
    "N",
    "Q",
    "S",
    "W",
    "BLE",
    "EXE",
    "ICN",
    "INP",
    "ISC",
    "NPY",
    "PD",
    "PGH",
    "PIE",
    "PL",
    "PT",
    "PYI",
    "RET",
    "RSE",
    "RUF",
    "SIM",
    "SLF",
    "TCH",
    "TID",
    "TRY",
    "YTT",
    "UP",
    "FA100",
    "FA102"
]

extend-fixable = ['UP']

ignore = [
    'PLR0911',
    'INP001',
    'N806',
    'N802',
    'N803',
    'E501',
    'BLE001',
    'RUF002',
    'S301',
    'S314',
    'S101',
    'N815',
    'S104',
    'C901',
    'ISC003',
    'PLR0913',
    'RUF001',
    'SIM108',
    'TCH003',
    'RUF003',
    'RET504',
    'TCH001',
    'TRY300',
    'TRY003',
    'TRY201',
    'TRY301',
    'PLR0912',
    'PLR0915',
    'PLR2004',
    'PGH003',
]
trim21 commented 1 month ago

I'm not sure if this help, but I'm editing doc files in this git repo https://github.com/trim21/transmission-rpc

InSyncWithFoo commented 1 month ago

Thanks. I can reproduce it now.

Unbelievable as it is, RyeCharm is working correctly. It is supposed to run Ruff on any Python file; a file is considered a Python file if it passes at least one of the following two criteria:

I always thought PyFile is reserved for, well, Python files (and injected Python fragments). I was wrong.

The annotator was indeed passed a PyFile. However, this PSI file seems to be used only as the host for the actual, injected .rst PSI file (and injected files are not passed to annotators). Regardless, the PyFile in question is still linked to your .rst file, text and all; its .language is also the same as that of normal Python files. I have no idea why this is even the case.

I'll add an extra check, but this is more of a design bug on PyCharm's side (see also PY-73814).

trim21 commented 1 month ago

I'll add an extra check, but this is more of a design bug on PyCharm's side.

At least ruff extend-exclude should work, docs directory is already excluded in ruff config.

https://github.com/trim21/transmission-rpc/blob/a672599ad7e973bdf399393b4f3d0bd0c13064dd/pyproject.toml#L78

InSyncWithFoo commented 1 month ago

At least ruff extend-exclude should work

The file's content is passed via standard input (note the - in the command). I might have to reconsider this decision if it proves to be too confusing. Note that letting Ruff reads the file itself isn't without its problems either: I would have to save the file beforehand.

Anyway, try the build out and let me know if it works.

trim21 commented 1 month ago

I think it works

trim21 commented 1 month ago

Ruff reads the file itself

ruff will ignore exclude config if it's called with ruff check /path/to/file

trim21 commented 1 month ago

I'm guessing the exclude config would work if I use LSP instead of cli?

InSyncWithFoo commented 1 month ago

I'm guessing the exclude config would work if I use LSP instead of cli?

Haven't rechecked, but that's probably correct.

trim21 commented 1 month ago

Yes files get excluded as expected in LSP mode.

InSyncWithFoo commented 1 month ago

I suppose this issue is solved then. If nothing changes I'll merge the fix tomorrow.

trim21 commented 1 month ago

thanks