-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running a script via a symlink in a different directory fails to load module files #1201
Comments
As is, file search doesn't do anything special wrt symlinks. I don't know whether it should. Is there current practice from other languages? |
In my experience with other languages, all worked fine with symlinks. For example, in Python, I created two files similar to my Prolog example above.
#!/usr/bin/env python3
import greetings
def main():
print(greetings.greetings('world'))
if __name__ == '__main__':
main()
def greetings(name):
return 'Hello, {}!'.format(name) And I create a symlink from |
Sounds like something worth considering. Do you happen to know a description on how Python deals with links to source files? Does this only apply for the main script? Does it in general try to find imported modules relative to the physical file? Does it also look relative tot the link? What if there are multiple chained links? It seems hard to find that documentation on the web 😢 |
This issue has been mentioned on SWI-Prolog. There might be relevant details there: |
I think it's just the main script. But I haven't tried importing modules through symlinks so I'm not sure it works with the same principle. The comments in the discourse thread mention PYTHONHOME and PYTHONPATH but I don't think they are related. Anyway thanks for considering this. Also I really appreciate your effort in making SWI-Prolog great. I love SWI-Prolog. Thank you! |
For now, I guess the way to go is a shell script using
|
Good idea. I worked around by compiling the script and making the symlink point to the compiled binary. But a shell script would be better. Thanks! |
On second thought, it'd be a nice feature to follow the symlinks even for the regular module import cases. It would help share the common code among code in different directories. If I have I think it's just a nice-to-have feature and a poor man's "package management" :) But it'd be useful sometimes. |
As a general rule, I would think that following symlinks would be best -- in other words, treat symlinks the same as hard links. Some specific situations require distinguishing symlinks from non-links (e.g., the Unix commands |
As an example, I have two source files --
main.pl
andgreetings.pl
in the same directory, say~/src
.main.pl
:greetings.pl
:If I run
main.pl
directly, it runs fine. I can run it from any other directories.But I put symlinks in my
~/bin
directory for some of my utilities so that I can run them easily. Those symlinks run fine as long as the linked prolog scripts are simple and don't import other module files. But when they do, as my example above, the module import fails. The error message is like below.I think SWI-Prolog tries to find module files from the directory where the symlink exists. It should probably follow the symlink and find the module files from the directory where the original script exists.
The text was updated successfully, but these errors were encountered: