For local code editing, I have the following pyproject.toml
defined.
[tool.ruff]
src = ["client_code", "server_code"]
[tool.ruff.lint]
select = ["E", "F", "I001"]
[tool.ruff.lint.isort]
known-third-party = ["anvil"]
The first config option means that anything within the client_code
or server_code
directories is treated as a local module and appears in its own section at the bottom of the imports.
However, if the same code is then pushed to the IDE and opened, it wants to sort the imports differently. My client and server code modules are treated as third parties and included in that section instead.
Any idea how I get it working consistently?
1 Like
could you provide an example that doesn’t behave like you’d expect?
Sure. I’ll put something together…
In the meantime, what version of ruff is being used by the IDE?
anvil is using ruff v0.11.0
1 Like
Here’s an MWE:
The imports in the main
server module behave differently in the IDE to how they do locally.
IDE - local server modules not recognised and treated as third party:
import datetime
import anvil.server
from ServerModule2 import hello2
from ServerModule3 import hello3
local - local server modules recognised and shown separately:
import datetime
import anvil.server
from ServerModule2 import hello2
from ServerModule3 import hello3
I’m using ruff 0.11.10 locally and I can see there’s an isort related change in 0.11.9. I’ll play with downgrading and see what happens…
1 Like
It’s not the ruff version. 0.11.0 shows the same behaviour locally.
2 Likes
ok - we’ll add it to our list to update ruff. Thanks for investigating
I don’t think the version is the problem here. I downgraded to 0.11.0 and I still saw the same discrepancy.
1 Like
ok - so the ruff in the IDE behaves like the ruff playground
It doesn’t have context of the file system
see this link:
it behaves like the ide
and not something I think we’ll be able to easily change
using relative imports will put them after the third party imports
1 Like
ahhh… Of course! relative imports was the way forward here.
Thank you.
1 Like