I'm relatively new to Python, and I'm struggling to understand if what I'm trying to do is just not possible, or if I am just doing it wrong. I admit that I come from Perl - where the rules for where you put your packages, and how the directories should look like is a bit looser, so my point of view my be not so pythonic.
Also, this is a different version of a question I've asked a couple of times here and here and I keep getting answers (that I am grateful for) that say I should not, but never "it's impossible" or "here's how you do it, though you should not". If something is possible, but not advisable, I would rather be able to find out why by trying and seeing and if it is impossible by design, I'd like to know (and stop banging my head against a wall).
Apologies in advance for the long intro - here's the question, finally.
I have this nice module - svgpathtools - that contains methods, classes and sits in an install-specific directory (inside the Python install that comes with Blender), directory that looks like this:
/home/simone/blender/blender-2.92.0-linux64/2.92/python/lib/python3.7/site-packages/svgpathtools
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-37.pyc
│ ├── bezier.cpython-37.pyc
│ ├── document.cpython-37.pyc
│ ├── misctools.cpython-37.pyc
│ ├── parser.cpython-37.pyc
│ ├── path.cpython-37.pyc
│ ├── paths2svg.cpython-37.pyc
│ ├── polytools.cpython-37.pyc
│ ├── smoothing.cpython-37.pyc
│ ├── svg_io_sax.cpython-37.pyc
│ └── svg_to_paths.cpython-37.pyc
├── bezier.py
├── document.py
├── misctools.py
├── parser.py
├── path.py
├── paths2svg.py
├── polytools.py
├── smoothing.py
├── svg_io_sax.py
└── svg_to_paths.py
1 directory, 22 files
I want to add functionality to it without messing with that directory and without subclassing. The first for obvious reasons, the second because for now I am only adding a couple of methods max, so it's not worth maintaining a whole subclass (for now at least). So my idea is to have a directory that looks like this:
/home/simone/blender_learning/mesh-20210920
└── svgpathtools
├── __init__.py
└── distance.py
Now: if I keep svgpathtools/__init__.py
, python (3.8.10) won't find the original svgpathtools
in the Blender install subdirectory, so all its functionality is gone
and if I remove svgpathtools/__init__.py
, python won't find svgpathtools/distance.py
so import svgpathtools.distance
throws an error.
Which one is it then:
- it's impossible: because of the way python looks for packages, you can't have sub-packages in a different place than the main package
- I am doing it wrong in some way (please tell me why)
Pretty please: don't just tell me I should not do it without having told me which one it is. I know that doable <> advisable (playing with explosives? petting hungry leopards? eating fugu?)