0

I'm building a complex set of Python / PyPI packages and modules.

I would like to have modules hello.a, hello.b and hello.b.c respectively in packages hello-a, hello-b and hello-b-c. Package hello-b-c would depend on hello-b.

Is it possible? Would you suggest a different setup?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
ragazzojp
  • 477
  • 3
  • 14
  • 1
    You're looking for namespace packages. See https://stackoverflow.com/a/50282888/7976758; https://docs.python.org/3/reference/import.html#namespace-packages – phd Jan 22 '21 at 15:03
  • 1
    Yes as @phd said, in principle it looks like you need namespace packages, and you should look into that. You should try to give more details though. In particular I am worried about the `hello.b` and `hello.b.c` combination. If I am not mistaken: if you want to have `hello.b.c` in its own distribution package, then you can not have code in `hello.b` in a different distribution package; `hello.b` should stay empty. I am not 100% sure, so you would need to try. – sinoroc Jan 23 '21 at 10:45
  • 1
    You might be in this situation: https://stackoverflow.com/a/62992832/11138259 – sinoroc Jan 23 '21 at 10:47
  • Conceptually, I would like to achieve this: `hello.a` and `hello.b` are both optional features of project `hello` and `hello.b.c` is an optional sub-feature of `hello.b`, all installable independently (excluding the fact that `b.c` requires `b`). – ragazzojp Jan 24 '21 at 22:02
  • So try something, let us know how far you manage to get and what your next blocker is. My point of view, is that it might be possible, but you might have to make some compromises, as I explained already. – sinoroc Jan 24 '21 at 22:46
  • 1
    I understood how PEP 420 namespace packages work and this is what I need (excluding for `hello.b` and `hello.b.c` as `b` can't contain code, as `hello` can't). I appreciate your comments, I'll write an answer myself for posterity to summarize. Last question: are you aware of major incompatibilities between PEP 420 packages and pip and conda? The PEP is old but I still read mixed feelings about it. Better a flat set of non-overlapping distribution packages to stay on the safe side or PEP 420 is relatively safe? I'm targeting runtime environment is Python 3.6+. – ragazzojp Jan 25 '21 at 19:17
  • Should be safe to use PEP 420. As far as I can see, it's a finalized proposition, so it's standard, and it looks like it's in all Python since version 3.3. I don't expect any issues, if things are done right. -- If you encounter issues later when implementing, don't hesitate to post a new question and add link here with a tag for my name and most likely I should receive a notification. – sinoroc Jan 25 '21 at 20:10

0 Answers0