5 examples of 'consider adding this directory to path' in Python

Every line of 'consider adding this directory to path' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
4def add_to_path(directory):
5 """Add directory to sys.path for importing modules
6
7 Args:
8 ``directory``: a string to the directory.
9 """
10 if sys.path.count(directory) == 0:
11 sys.path.insert(0, directory)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

27def addpath(path):
28 """
29 Add a directory to the python path environment, and to the PYTHONPATH
30 environment variable for subprocesses.
31 """
32 path = abspath(path)
33 if 'PYTHONPATH' in os.environ:
34 PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
35 else:
36 PYTHONPATH = path
37 os.environ['PYTHONPATH'] = PYTHONPATH
38 sys.path.insert(0, path)
5def add_path_tree( base_path, path, skip_dirs=[ '.svn', '.git' ]):
6 path = os.path.join( base_path, path )
7 partial_data_files = []
8 for root, dirs, files in os.walk( os.path.join( path )):
9 sample_list = []
10 for skip_dir in skip_dirs:
11 if skip_dir in dirs:
12 dirs.remove( skip_dir )
13 if files:
14 for filename in files:
15 sample_list.append( os.path.join( root, filename ))
16 if sample_list:
17 partial_data_files.append((
18 root.replace(
19 base_path + os.sep if base_path else '',
20 '',
21 1
22 ),
23 sample_list
24 ))
25 return partial_data_files
24def addpath():
25 try:
26 import dynts
27 except ImportError:
28 p = lambda x : os.path.split(x)[0]
29 path = p(p(os.path.abspath(__file__)))
30 sys.path.insert(0, path)
6def addpath():
7 try:
8 import astrometry
9 from astrometry.util.shell import shell_escape
10 from astrometry.util.filetype import filetype_short
11 except ImportError:
12 me = __file__
13 path = os.path.realpath(me)
14 utildir = os.path.dirname(path)
15 assert(os.path.basename(utildir) == 'util')
16 andir = os.path.dirname(utildir)
17 if os.path.basename(andir) == 'astrometry':
18 rootdir = os.path.dirname(andir)
19 sys.path.insert(1, andir)
20 else:
21 # assume there's a symlink astrometry -> .
22 rootdir = andir
23 #sys.path += [rootdir]
24 sys.path.insert(1, rootdir)

Related snippets