Python Forum

Full Version: problem with sphinx and file directory in script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am trying to use sphinx to document some of my code but I'm having problems getting my files directories. I dont want to write down the full path of the script. when I run my script in the terminal I get the directory of my script, but when the same commands are run with sphinx, it gets my virtual environments folder. this is what my file structure looks like:
projectDir
  • test.py
  • folder
    • file.log
  • venv
    • venv's files

this is the part of the code I'm having problems with:
##########################
if __name__ == "__main__":
    print(f"{os.path.dirname(os.path.abspath(sys.modules['__main__'].__file__))}/folder/file.log")
    print(os.path.abspath(sys.modules['__main__'].__file__))
    print(pathlib.Path(__file__).parent.absolute())
    fileHandler = logging.FileHandler(f"{pathlib.Path(__file__).parent.absolute()}/folder/file.log")
when I run in a terminal, from any directory, this works. However when I use sphinx to make html I get this error, the path upto and including the project directory is correct but for some reason it looks in venv/bin:
Quote:FileNotFoundError: [Errno 2] No such file or directory: 'projectDir/venv/bin/folder/file.log'