use os.path.realpath instead, because it eliminates any symbolic links encountered in the path

This commit is contained in:
ander 2020-10-17 23:16:42 +03:00
parent 54d83a6211
commit d20fb74324

View file

@ -25,16 +25,16 @@ import logging
import os
import sys
# try to import cdist and if that fails, then add this file's parent dir to
# module search path and try again. additionally check if this file is
# symlinked, so user can symlink this file to, for example, ~/.local/bin.
# try to import cdist and if that fails,
# then add this file's parent dir to
# module search path and try again.
try:
import cdist
except ModuleNotFoundError:
cdist_bin = __file__
if os.path.islink(cdist_bin):
cdist_bin = os.readlink(cdist_bin)
cdist_dir = os.path.abspath(os.path.join(os.path.dirname(cdist_bin), os.pardir))
cdist_dir = os.path.realpath(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.pardir))
sys.path.insert(0, cdist_dir)
import cdist