10 examples of 'python get root directory' in Python

Every line of 'python get root directory' 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
12def get_root():
13 """Return the full path to the root of the package"""
14 return os.path.abspath(os.path.dirname(kgof.__file__))
24def get_root_dir():
25 return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
3def root():
4 """
5 Finds the root of the project and return it as string.
6
7 The root is the directory named alex.
8
9 """
10
11 path, directory = os.path.split(os.path.abspath(__file__))
12
13 while directory and directory != 'alex':
14 path, directory = os.path.split(path)
15
16 if directory == 'alex':
17 return os.path.join(path, directory)
18 else:
19 raise Exception("Couldn't determine path to the project root.")
14def get_root_dir():
15 import conda_build
16 conda_build_dir = os.path.realpath(os.path.dirname(conda_build.__file__))
17 return os.path.abspath(os.path.join(conda_build_dir, ".."))
13def find_project_root():
14 current = cwd
15 while True:
16 path = os.path.join(current, '.jinjaformrc')
17 if os.path.exists(path):
18 return current
19 current = os.path.dirname(current)
20 if current == os.path.sep:
21 return ''
8def root():
9 """ Returns the root path of Jasy """
10 return os.path.relpath(os.path.normpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)))
76def get_rootdir():
77 rootdir = run_command(['git', 'rev-parse', '--show-toplevel'])
78 return rootdir
8def root() -> Path:
9 return Path(root_dir)
498def django_find_root_dir():
499 """
500 Return path to directory (top-level Python package) that contains main django
501 files. Return None if no directory was detected.
502
503 Main Django project directory contain files like '__init__.py', 'settings.py'
504 and 'url.py'.
505
506 In Django 1.4+ the script 'manage.py' is not in the directory with 'settings.py'
507 but usually one level up. We need to detect this special case too.
508 """
509 # Get the directory with manage.py. Manage.py is supplied to PyInstaller as the
510 # first main executable script.
511 manage_py = sys._PYI_SETTINGS['scripts'][0]
512 manage_dir = os.path.dirname(os.path.abspath(manage_py))
513
514 # Get the Django root directory. The directory that contains settings.py and url.py.
515 # It could be the directory containig manage.py or any of its subdirectories.
516 settings_dir = None
517 files = set(os.listdir(manage_dir))
518 if 'settings.py' in files and 'urls.py' in files:
519 settings_dir = manage_dir
520 else:
521 for f in files:
522 if os.path.isdir(os.path.join(manage_dir, f)):
523 subfiles = os.listdir(os.path.join(manage_dir, f))
524 # Subdirectory contains critical files.
525 if 'settings.py' in subfiles and 'urls.py' in subfiles:
526 settings_dir = os.path.join(manage_dir, f)
527 break # Find the first directory.
528
529 return settings_dir
16def get_app_root_dir():
17 """Return the root dir of app"""
18 return op.dirname(op.dirname(op.abspath(get_main_file())))

Related snippets