I am testing the following GitHub Actions workflow:
name: Run Azure Login with OpenID Connect and PowerShell
on: [push]
permissions:
id-token: write
contents: read
jobs:
Windows-latest:
runs-on: windows-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade azure-keyvault-secrets azure-identity azure-mgmt-resource
- name: OIDC Login to Azure Public Cloud with AzPowershell (enableAzPSSession true)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: 'Get resource group with PowerShell action'
uses: azure/powershell@v1
with:
inlineScript: |
Get-AzResourceGroup
azPSVersion: "latest"
- name: Run python code
run: |
python test/test_1.py
All steps except the last one run without errors. Running the python script gives me an error when import project files from other folders, while locally on my PC it runs without problems:
0s
Run python test/test_1.py
python test/test_1.py
shell: C:Program FilesPowerShell7pwsh.EXE -command ". '{0}'"
env:
pythonLocation: C:hostedtoolcachewindowsPython3.11.9x64
PKG_CONFIG_PATH: C:hostedtoolcachewindowsPython3.11.9x64/lib/pkgconfig
Python_ROOT_DIR: C:hostedtoolcachewindowsPython3.11.9x64
Python2_ROOT_DIR: C:hostedtoolcachewindowsPython3.11.9x64
Python3_ROOT_DIR: C:hostedtoolcachewindowsPython3.11.9x64
AZURE_HTTP_USER_AGENT:
AZUREPS_HOST_ENVIRONMENT:
Traceback (most recent call last):
File "D:areporepotesttest_1.py", line 9, in <module>
from code.data.constants import DATETIME_FORMAT
ModuleNotFoundError: No module named 'code.data'
The project structure looks like this:
repo/
|-- code/
| |-- data/
| | |-- constants.py
|-- test/
| |-- test_1.py
I looked at similar questions and only found the suggestion to add “_init_.py” files, but it also didn’t change anything. I added empty “_init_.py” like shown below:
repo/
|-- __init__.py
|-- code/
| |-- __init__.py
| |-- data/
| | |-- __init__.py
| | |-- constants.py
|-- test/
| |-- __init__.py
| |-- test_1.py
Another suggestion was to add the following at the begining of the file, but also didn’t help:
import sys
sys.path.append("../")
Would appreciate other ideas!