Next to the CTRL + I line formatting shortcut I would love to call the Black code formatter using some shortcut.
Black formatted code improves readability and thus efficiency in my eyes quite significantly…
Next to the CTRL + I line formatting shortcut I would love to call the Black code formatter using some shortcut.
Black formatted code improves readability and thus efficiency in my eyes quite significantly…
You can use neovim to get that working
(although I’ve switched to using ruff instead of black these days)
I’d suggest that to Anvil anyway – ruff over black – simply for performance reasons.
Thanks for the hot tip. We’ve implemented ruff in the anvil ide.
Ruff comes with Black like auto formatting. (Alt + Shift + F).
It also has a linter. You’ll see some additional linting in the anvil IDE. We’re using a modest lint configuration which you can customise.
If you’d like to customise the ruff configuration then simply follow the Ruff docs. Add a pyproject.toml or ruff.toml to the root of you your anvil project. And next time you open the anvil ide the linter will follow your preferred configuration.
Whoop! Absolutely fantastic! Thank you.
Black has always been on our list but there was no obvious root without implementing server requests to format the code. And black never supported 2 space indenting, which is common for anvil projects.
Ruff has a browser compatible wasm implementation which was perfect. And they support 2 space indenting too.
As another aside if you have have a bunch of lint highlights in a file you can hit ctrl + shift + M
(cmd
on Mac) and show all lint warnings in a bottom panel. Each lint warning has a shortcut to auto fix it (if it’s fixable).
And when you’re in a file F8 should jump you to the next lint warning.
Is there a way to see linting highlights across the whole app?
@stucork Getting even better!
In my eyes you should really consider to announce this feature in your newsletter so it is not overseen. It is just one of those tiny but nevertheless super helpful things.
No, the current implementation for linting is only per file. The ruff linter is naive and doesn’t know/need to know about the rest of your app. I know VS code has a bottom panel for seeing linting across the whole project. So that’d probably want to be a feature request. Whenever I’ve used vs code’s global linting panel, it’s been a massive performance hog, which we’d want to avoid, especially in larger projects.
Where do I put this file? I tried putting it in assets but it does not seem to be applying
(It’s the same file from the Ruff docs, found here at: Configuring Ruff - Ruff with the line length changed, but the IDE is still capping at 88)
Do I need to use github or something?
Yes you’ll need to checkout your app locally and put it the root of your project. Then push it back to anvil.
I second the request from @duncan_richards12!
If the performance impact is only apparent when opening the app-wide linter panel, it wouldn’t bother anyone. If it’s too slow all you need to do is close it.
Ah, going through the Docs now I remember why I never set up github.
I can’t make my code a public repo for company policy reasons, and we don’t need anything found in the business plan that would allow it to be private, so there is no reason for them to upgrade.
Is there a way to configure it to look somewhere else for the file? or should I start a new FR
@ianb, this doesn’t require github, just a local installation of git. I’ve been doing that for a few years now.
Ok, yeah I’m getting the flashbacks now. I use windows and could not get an SSH key to generate/work, (even with WSL I don’t recall why) and when I signed up for anvil I used my google account login directly so there is no password, (Using login/password fails) so there is no way to connect to the repo like this:
Edit: I think VS code had a solution for this years ago, I’m going to go see if I can get SSH to work on windows.
That should be easier these days as you can just install and use openssh on windows now - so all the instructions you see for *nix systems should also work.
(says the man who hasn’t touched a windows machine for over a decade now)…
I got it to work, thanks
This command will clone the Anvil app repository to your computer. You shouldn’t need to install anything. It worked on a new Windows 11 computer I got recently and in all other computers before that one.
You will need to enter your Anvil account credentials, or you can create a public key and add it here:
I don’t think VS code has a solution for this. I imagine VS code will use whatever tools you have installed.
I use PyCharm, and the first time you use it in a computer without git installed, it asks you if you want to install it and offer to install it for you.
Without a configuration file, does ruff use the default configuration shown here?
If not, can we have the default configuration?
(I am wondering if there is anything specific about folder, import, etc. that I may break)