Importing modules through directory shortcuts on Windows

B

Brian Quinlan

Recently, I became responsible for maintaining some Python code, which
was organized as follows:

user/pylib
ui
...
project2/pylib
ui
...
project3/pylib
ui
...
python-packages/user => /user/pylib
project2 => /project2/pylib
project3 => /project3/pylib

The idea is that "python-packages" is added to sys.path and then every
project can import the library package from every other project. NOTE: I
think that this structure is crazy but I'm just the poor maintenance
programmer.

Anyway, the problem is that Windows does not have a symlink facility to
accommodate this (AFAIK) and the Python import mechanism does not
resolve shortcuts.

Therefore, I wrote a very simple import hook to get around that problem.
If you are interested, the code is here:
http://www.sweetapp.com/shortcut/shortcutimporter.py

BTW, does anyone else think that this functionality should be part of
core Python?

Cheers,
Brian
 
D

Duncan Booth

Brian said:
Anyway, the problem is that Windows does not have a symlink facility to
accommodate this (AFAIK) and the Python import mechanism does not
resolve shortcuts.

Windows does have the equivalent of symlinks provided you are running on
NTFS with Windows 2000 or later (Google for 'XP junction'). However, by
default the system provides no support for manipulating junction points, so
they are only really useful in an environment where you can control the
tools on the system, not something you can expect to use on arbitrary
systems.
 
R

Roger Upole

You can use win32file.DeviceIoControl to link directories.
I can post some code to do so if anyone's interested.

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top