[Python] Issue with Path in Github Actions using Python

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have a github actions workflow where I run many different files, for which I append to the PYTHONPATH all the paths I need for the scripts to work. To do so, I created another program called workflow_import.py in the same directory as my main scripts where I simply add a function of this sort:

    def load_modules():
    if 'SOURCES_PATH' in os.environ:
    print('SOURCES_PATH') # debug line
    sources_path_list = eval(os.environ['SOURCES_PATH'])
    sys.path.extend(sources_path_list)


    I add this function to each of my scripts as in

    from workflow_import import load_modules


    Herein, I work with a environment variable called 'SOURCES_PATH' (aka. variables.SOURCES_PATH, don't know if saving it as a secret is more convenient) storing all the modules' location. Running the main script doesn't invoke any ModuleNotFindError. However, one of my scripts generates a new subfolder called \ref, and since it most certainly changes to that directory all of the subsequent scripts fail to find workflow_import.py or any other module from load_modules().

    I thought this was due to the sys.path() changing once \ref is created, but I don't know how to make it so it stays consistent within the workflow. As an example, I run the scripts in this manner:

    - name: Library Test
    shell: powershell
    run: |
    & $env:pYTHON_ENV_PATH ./libraries/library/tests/generate_reffiles.py


    Where PYTHON_ENV_PATH is another secret containing the python.exe path of my desired environment.

    Continue reading...

Compartilhe esta Página