Page MenuHomePhabricator

Fix import paths in utils.py when importing MySqlDict
Closed, ResolvedPublic

Description

When running run-pipeline.sh, we get an import-error in utils.py

from src.MySqlDict import MySqlDict
ModuleNotFoundError: No module named 'src'

This happens, for example, when we call generate_backtesting_eval.py when importing functions from utils.py

from utils import getLinks
from utils import process_page

The reason is that the python-script is called from src/scripts/ such that the path src.MySqlDict (in utils.py) is not found and the import fails.
This was introduced in this patch: https://gerrit.wikimedia.org/r/c/research/mwaddlink/+/677835

A quick fix would be to add an additional path to the python system-paths in utils.py via:

import sys
sys.path.append("../../")
from src.MySqlDict import MySqlDict

However, I think there should be a better fix to make sure we define the python-paths properly for importing functions.

@Tgr suggested to add to the scripts something like :

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
export PYTHONPATH=$(dirname $(dirname "$DIR"))

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I think we should do a quick fix, just wanted to also link T280015: Convert run-pipeline.sh to python script as a more comprehensive fix for this issue.

@MGerlach do you have capacity to work on a patch for this?

@MGerlach do you have capacity to work on a patch for this?

I can have a look this week.

Change 681095 had a related patch set uploaded (by Kosta Harlan; author: MGerlach):

[research/mwaddlink@main] Fix import paths in utils.py when importing MySqlDict

https://gerrit.wikimedia.org/r/681095

kostajh claimed this task.
kostajh moved this task from Incoming to QA on the Growth-Team (Sprint 0 (Growth Team)) board.
kostajh added a subscriber: Etonkovidova.

We have a simple fix for this. @Etonkovidova nothing to QA here, it fixes a problem with ./run-pipeline.sh invocation on stat1008.

Change 681095 merged by jenkins-bot:

[research/mwaddlink@main] Fix import paths in utils.py when importing MySqlDict

https://gerrit.wikimedia.org/r/681095