tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Enable and configure importlinter

Open DiamondJoseph opened this issue 10 months ago • 4 comments

Validation for pre-commit and github ci to catch incoming errors. Currently exposes several places where this contract is broken!

Fixes #864

Checklist

  • [ ] Add a Changelog entry
  • [ ] Add the ticket number which this PR closes to the comment section

DiamondJoseph avatar Feb 20 '25 14:02 DiamondJoseph

----------------
Broken contracts
----------------

Server cannot import from Client
--------------------------------

tiled.server is not allowed to import tiled.client:

-   tiled.server.app -> tiled.utils (l.43)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.authentication -> tiled.utils (l.60)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.core -> tiled.utils (l.29)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.dependencies -> tiled.media_type_registration (l.8, l.11)
    tiled.media_type_registration -> tiled.utils (l.6)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.links -> tiled.structures.core (l.6)
    tiled.structures.core -> tiled.utils (l.12)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.principal_log_filter -> tiled.utils (l.3)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.router -> tiled.utils (l.34)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.schemas -> tiled.structures.core (l.15)
    tiled.structures.core -> tiled.utils (l.12)
    tiled.utils -> tiled.client.container (l.350)

-   tiled.server.utils -> tiled.access_policies (l.4)
    tiled.access_policies -> tiled.utils (l.5)
    tiled.utils -> tiled.client.container (l.350)


Client cannot import from Server
--------------------------------

tiled.client is not allowed to import tiled.server:

-   tiled.client.constructors -> tiled.config (l.246)
    tiled.config -> tiled.adapters.mapping (l.16)
    tiled.adapters.mapping -> tiled.server.schemas (l.38)

-   tiled.client.constructors -> tiled.server.app (l.247)

-   tiled.client.context -> tiled.server.settings (l.455)

DiamondJoseph avatar Feb 20 '25 14:02 DiamondJoseph

I'd propose moving whatever is currently in tiled.client.container to either tiled.container or tiled.utils; move from tiled.server.schemas to tiled.schemas (schemas should be common(?)), same with tiled.server.settings to tiled.settings: or at least some subset of the settings. e.g.

# in tiled.settings
class Settings(BaseSettings):
    ...

# extended in tiled.server.settings
class ServerSettings(Settings):
    ...

Presumably this import is allowing client.from_app, for a same process client/server? tiled.client.constructors -> tiled.server.app

DiamondJoseph avatar Feb 20 '25 14:02 DiamondJoseph

Excellent. I've added some commits to:

  • Move tree from tiled.utils to tiled.client.utils. This is a more logical place for it, anyway. (This is a "historical" wart. It's one of the oldest functions in the code base, probably older than tiled.client.utils.)
  • Consolidated tiled.server.schemas into tiled.schemas. (Once upon a time, I was trying to avoid having pydantic as a client dependency because I normally think of that as a something in web server environments, not in scientific computing environments. But I've given up on trying to hold that line.)

With that, the remaining violations were all to do with, as you said, launching a server on a background thread from the client: building an app and configuring its settings. (Because the settings are all server settings, I don't see any reason to split that up or generalize it.)

---------
Contracts
---------

Analyzed 198 files, 739 dependencies.
-------------------------------------

Server cannot import from Client KEPT
Client cannot import from Server BROKEN

Contracts: 1 kept, 1 broken.


----------------
Broken contracts
----------------

Client cannot import from Server
--------------------------------

tiled.client is not allowed to import tiled.server:

-   tiled.client.constructors -> tiled.server.app (l.247)

-   tiled.client.context -> tiled.server.settings (l.455)

So I've added those two as exemptions in the importlinter configuration. What do you think?

danielballan avatar Feb 21 '25 17:02 danielballan

The remaining issue is that tiled.client code imports tiled.schema code which now import numpy/pandas/xarray/awkward/pyarrow.

We test that none of the above are imported until corresponding structures are used, because importing the full scipy stack is slow, and this is especially felt when doing quick CLI things.

danielballan avatar Feb 21 '25 22:02 danielballan