-
Notifications
You must be signed in to change notification settings - Fork 917
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·57 lines (44 loc) · 1.57 KB
/
__init__.py
File metadata and controls
executable file
·57 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
LIB_PATHS = ()
DATA_PATHS = ("docs", "software/gcloud", "data")
REQUIRED_VERSION = (3, 11)
_INITIALIZED = None
def Setup():
"""Setup the import path for the project and check the validity of the runtime."""
global _INITIALIZED
if _INITIALIZED:
return
if sys.version_info < REQUIRED_VERSION:
sys.stderr.write(
f"Python version {sys.version_info.major}.{sys.version_info.minor} "
f"not supported version {REQUIRED_VERSION[0]}.{REQUIRED_VERSION[1]} "
"or above required - Exiting\n"
)
sys.exit(os.EX_CONFIG)
for path in LIB_PATHS:
absolute_path = os.path.join(os.getcwd(), path)
if not os.path.isdir(absolute_path):
sys.stderr.write(
f'Required directory "{absolute_path}" not found - Exiting\n'
)
sys.exit(os.EX_CONFIG)
sys.path.insert(1, absolute_path)
_INITIALIZED = True
def CheckWorkingDirectory():
"""Check that the working directory is correct and contains the right directories."""
if os.path.basename(os.getcwd()) != "schemaorg":
sys.stderr.write(
'Script should be run from within the "schemaorg" '
'directory! - Exiting\n'
)
sys.exit(os.EX_USAGE)
for directory_name in DATA_PATHS:
if not os.path.isdir(directory_name):
sys.stderr.write(
f'Required directory {directory_name} not found - Exiting\n'
)
sys.exit(os.EX_CONFIG)
Setup()