Getting a python module to play nicely with paths

This is has taken a fair while to get spinning nicely, but I think I now have it working with enough different use cases to be usable generally.

A Python file can find other files when the directory it is in contains an empty file. It uses this to say 'ok, so we have other things here, I'll look for them if someone asks for something'.

So if in your python script you call for a certain import, it will then use this to try and find it.

However, the python path scoped to that instance of python running that scripted import might not understand where it is locally, so teh import will then fail.

A simple solution to this is to tell teh locally scoped python path where it is:

python3 import os.path import sys PACKAGE_PARENT = '..' SCRIPT_DIR = os.path.dirname(os.path.realpath( os.path.join(os.getcwd(), os.path.expanduser(__file__)))) sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

And this is fine. As long as that happens BEFORE any imports are called then the local scope of the python path will be nailed to the directory scope, the will act as a placeholder for the filename and then open and search names internal to that and all is good in the world.

What you might not then be expecting is the perfectly valid and good standard of PEPE402, which basically says 'imports shall be ordered based on os importance and above all code', which if you're using an IDE that automatically moves things areound for you (auto-linters etc) then it will move the python path directives UNDER the imports that need them.

A quick solve to this is to put this in settings.json for VScode "python.formatting.autopep8Args": ["--ignore","E402"],