Robot Framework
pythonpathsetter.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 
17 
18 import sys
19 import fnmatch
20 from os.path import abspath, dirname
21 
22 ROBOTDIR = dirname(abspath(__file__))
23 
24 def add_path(path, end=False):
25  if not end:
26  remove_path(path)
27  sys.path.insert(0, path)
28  elif not any(fnmatch.fnmatch(p, path) for p in sys.path):
29  sys.path.append(path)
30 
31 def remove_path(path):
32  sys.path = [p for p in sys.path if not fnmatch.fnmatch(p, path)]
33 
34 
35 # When, for example, robot/run.py is executed as a script, the directory
36 # containing the robot module is not added to sys.path automatically but
37 # the robot directory itself is. Former is added to allow importing
38 # the module and the latter removed to prevent accidentally importing
39 # internal modules directly.
40 add_path(dirname(ROBOTDIR))
41 remove_path(ROBOTDIR)
def add_path(path, end=False)
def abspath(path, case_normalize=False)
Replacement for os.path.abspath with some enhancements and bug fixes.
Definition: robotpath.py:65