Skip to content

Commit e1f378d

Browse files
committed
Remove side-effects from pythonpathsetter import
Use a dedicated method instead. The main motivation is avoiding linting errors from unused imports (see #5387), but this may also help with issues `pythonpathsetter` has caused (#5384).
1 parent 7e89170 commit e1f378d

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

src/robot/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import sys
1919

2020
if __name__ == '__main__' and 'robot' not in sys.modules:
21-
import pythonpathsetter
21+
from pythonpathsetter import set_pythonpath
22+
set_pythonpath()
2223

2324
from robot import run_cli
2425

src/robot/libdoc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
from pathlib import Path
3838

3939
if __name__ == '__main__' and 'robot' not in sys.modules:
40-
import pythonpathsetter
40+
from pythonpathsetter import set_pythonpath
41+
set_pythonpath()
4142

4243
from robot.utils import Application, seq2str
4344
from robot.errors import DataError

src/robot/pythonpathsetter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sys
2828
from pathlib import Path
2929

30-
if 'robot' not in sys.modules:
30+
31+
def set_pythonpath():
3132
robot_dir = Path(__file__).absolute().parent # zipsafe
3233
sys.path = [str(robot_dir.parent)] + [p for p in sys.path if Path(p) != robot_dir]

src/robot/rebot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import sys
3434

3535
if __name__ == '__main__' and 'robot' not in sys.modules:
36-
import pythonpathsetter
36+
from pythonpathsetter import set_pythonpath
37+
set_pythonpath()
3738

3839
from robot.conf import RebotSettings
3940
from robot.errors import DataError

src/robot/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from threading import current_thread
3535

3636
if __name__ == '__main__' and 'robot' not in sys.modules:
37-
import pythonpathsetter
37+
from pythonpathsetter import set_pythonpath
38+
set_pythonpath()
3839

3940
from robot.conf import RobotSettings
4041
from robot.model import ModelModifier

src/robot/testdoc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from pathlib import Path
3535

3636
if __name__ == '__main__' and 'robot' not in sys.modules:
37-
import pythonpathsetter
37+
from pythonpathsetter import set_pythonpath
38+
set_pythonpath()
3839

3940
from robot.conf import RobotSettings
4041
from robot.htmldata import HtmlFileWriter, ModelWriter, JsonWriter, TESTDOC

0 commit comments

Comments
 (0)