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

Are patterns supported? #76

Open
liavkoren opened this issue Oct 22, 2018 · 1 comment
Open

Are patterns supported? #76

liavkoren opened this issue Oct 22, 2018 · 1 comment

Comments

@liavkoren
Copy link

Eg, I'd like the ability to say that modules in utils may not import from from any path that matches apps.*.models.

@seddonym
Copy link
Owner

Thanks for the issue request!

I want to dig a bit more into what you're asking for - from what I understand, there are two potential features here.

Feature one: container wildcards

The first potential feature is to support container wildcards in your contract. I've created an issue for this here: #77

The answer with this one is, it's not possible yet but I'm planning on implementing it soon. In the meantime, you can just list all your apps in the containers and you get the same result. Let me know if (and why) it's causing you a lot of pain and I may be able to prioritise it.

Feature two: layers at different levels

As I understand it, the example you give might be for the following files:

mypackage/
  utils/
    util.py
  apps/
    foo/
       forms.py
       models.py
    bar/
       forms.py
       models.py

You would want to disallow, say, mypackage.utils.util from importing mypackage.apps.foo.models (but you wouldn't mind if it imported from mypackage.apps.foo.forms).

Currently this isn't possible, because layers have to exist in the same container. So you could make utils be a layer below apps, but then it wouldn't be allowed to import anything from apps, not just the models files. Rethinking layers so they could exist at different levels in the package from each other is a potential change to the tool, but I'm not sold on it yet as I think it's easier to understand a codebase in which the layers are at the same level. Feel free to convince me otherwise!

However, I'm planning to add support for closed layers: #78 I think this might give you what you need. Your contract might look something like this:

My contract:
    containers:
        - mypackage.apps.foo
        - mypackage.apps.bar
    layers:
        - [closed] forms
        - models

This would prevent anything from anywhere else in the codebase from reaching down below the forms module to layers underneath. This would effectively make models in each app a module private to the app. That would restrict utils from importing models, but everything else as well.

Closed layers for me is a feature I'd really like to implement soon, especially if others are interested in it too.

Let me know your thoughts.

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

No branches or pull requests

2 participants