InSyncWithFoo / ryecharm

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

Unable to run command pop up? #33

Open austinv11 opened 1 day ago

austinv11 commented 1 day ago

What happened?

I am running code in a jupyter notebook and I keep getting this error: image I believe it is related to the fact that I only have uv installed and not rye or ruff?

I also have one project which makes use of remote python interpreters and pycharm professional's deployment options. Maybe that is related?

Steps to reproduce

Unclear, this happens sporadically on my mac and windows which both only have uv installed

Relevant log output or stack trace

No response

Operating system

None

InSyncWithFoo commented 1 day ago

Jupyter notebooks are currently unsupported. It is an eventual goal, but I don't have any plan for this yet. To make things worse, Jupyter infrastructure is part of the Professional edition but not Community and thus closed-source.

RyeCharm currently doesn't care whether the interpreter exists or not (it might in the future, though), nor does it know anything about deployments, so those details are unrelated. It would, however, complain if the project cannot be found locally, as specified in the notification.

This notification that you see is normally only emitted for explicit actions. Skimming through places where such a notification is triggered, my guess is that you have either "Run on reformat"/"Run on optimize import" or the corresponding "Run on save" settings enabled. You can disable those settings for Jupyter projects as a workaround.

I'll see if I can find a way to differentiate notebooks from normal files.

InSyncWithFoo commented 1 day ago

Actually, I did differentiate them:

RuffImportOptimizer.kt:

override fun supports(file: PsiFile) =
    file.project.ruffConfigurations.run { formatting && formatOnOptimizeImports } && file.isSupportedByRuff

RuffFormatter.kt:

override fun canFormat(file: PsiFile) =
    file.project.ruffConfigurations.run { formatting && formatOnReformat } && file.isSupportedByRuff

KnownFiles.kt:

// TODO: .ipynb / Allow configuring what files
internal fun VirtualFile.isSupportedByRuff(project: Project? = null): Boolean {
    return extension == "py" || extension == "pyi" || extension == "pyw"
}

internal val PsiFile.isSupportedByRuff: Boolean
    get() = this is PyFile && !this.isReST || virtualFile?.isSupportedByRuff(project) == true

This is further confirmed via manual testing: RyeCharm is not invoked at all even with all the settings enabled.

austinv11 commented 1 day ago

Thanks for looking into this, I don't seem to have any of those actions enabled, other than image which is part of my deployment settings. Perhaps that's it?

InSyncWithFoo commented 1 day ago

I have never even seen this setting before, but then again, can't say I know much about non-local projects to begin with (support for these are also proprietary, by the way). I think the best I can do now is to tweak the notifications so that they are more specific about the problems in question; we'll see what comes after that.