469,914 Members | 2,095 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,914 developers. It's quick & easy.

Importing modules through directory shortcuts on Windows

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
Apr 26 '06 #1
2 1370
Brian Quinlan wrote:
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.
Apr 26 '06 #2
You can use win32file.DeviceIoControl to link directories.
I can post some code to do so if anyone's interested.

Roger
"Brian Quinlan" <br***@sweetapp.com> wrote in message news:ma***************************************@pyt hon.org...
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



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Apr 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Vsevolod (Simon) Ilyushchenko | last post: by
reply views Thread by Mark English | last post: by
3 posts views Thread by Charles Krug | last post: by
2 posts views Thread by spike grobstein | last post: by
6 posts views Thread by Kamilche | last post: by
6 posts views Thread by Walter Brunswick | last post: by
29 posts views Thread by Natan | last post: by
reply views Thread by Martin P. Hellwig | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.