Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable and configure importlinter #896

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Conversation

DiamondJoseph
Copy link
Contributor

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
Copy link
Contributor Author

DiamondJoseph commented Feb 20, 2025

----------------
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
Copy link
Contributor Author

DiamondJoseph commented Feb 20, 2025

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

@danielballan
Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add linting to ensure boundaries of client/server code are respected
2 participants