1#!/usr/bin/env python3 2# The idea is for a tool named /tools/foo-bar you mv it to 3# /python/tools/foo_bar.py then softlink /tools/shim to /tools/foo-bar. 4# /tools/foo-bar then continues to work as an alias for 5# /python/tools/foo_bar.py but you get the advantage of formatting 6# & code sharing. 7import os 8import sys 9ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 10NAME = os.path.basename(sys.argv[0]).replace('-', '_') 11NAME = NAME if NAME.endswith('.py') else NAME + '.py' 12PATH = os.path.join(ROOT_DIR, 'python', 'tools', NAME) 13assert os.path.isfile(PATH), f'Shim target {PATH} does not exist.' 14os.execv(PATH, sys.argv) 15