Add Python 3.12 to the test suite; mark it as supported
[dotbot.git] / bin / dotbot
blob5042b4bf104b1d228be2993c96d08639f5d71168
1 #!/usr/bin/env sh
3 # This is a valid shell script and also a valid Python script. When this file
4 # is executed as a shell script, it finds a python binary and executes this
5 # file as a Python script, passing along all of the command line arguments.
6 # When this file is executed as a Python script, it loads and runs Dotbot. This
7 # is useful because we don't know the name of the python binary.
9 ''':' # begin python string; this line is interpreted by the shell as `:`
10 command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
11 command -v python >/dev/null 2>&1 && exec python "$0" "$@"
12 >&2 echo "error: cannot find python"
13 exit 1
14 '''
16 # python code
18 import sys, os
20 # this file is syntactically valid Python 2; bail out if the interpreter is Python 2
21 if sys.version_info[0] < 3:
22 print('error: this version of Dotbot is not compatible with Python 2:\nhttps://github.com/anishathalye/dotbot/wiki/Troubleshooting#python-2')
23 exit(1)
24 if sys.version_info < (3, 6):
25 print('error: this version of Dotbot requires Python 3.6+')
26 exit(1)
28 PROJECT_ROOT_DIRECTORY = os.path.dirname(
29 os.path.dirname(os.path.realpath(__file__)))
31 def inject(lib_path):
32 path = os.path.join(PROJECT_ROOT_DIRECTORY, 'lib', lib_path)
33 sys.path.insert(0, path)
35 inject('pyyaml/lib')
37 if os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'dotbot')):
38 if PROJECT_ROOT_DIRECTORY not in sys.path:
39 sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
40 os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY)
42 import dotbot
44 def main():
45 dotbot.cli.main()
47 if __name__ == '__main__':
48 main()