Thursday, 20 May 2021

How to block intra package imports

I'm building a python application and my codebase has the following structure:

/utils
  /foo
/package_1
  /foo
/package_2
  /foo
/whatever

I would like to enforce the following rules:

  1. In utils package is possible to import only from utils package itself
  2. In package_1 is possible to import from utils and package_1 itself
  3. In package_2 is possible to import from utils and package_2 itself
  4. In whatever you can import from all the other packages

Which automatic strategy can I use to enforce this coding rule?



from How to block intra package imports

No comments:

Post a Comment