-
Notifications
You must be signed in to change notification settings - Fork 60
/
with_my
executable file
·46 lines (33 loc) · 1.31 KB
/
with_my
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
#!/usr/bin/env python3
"""
This file is used for specifying paths for 'my' package and potentially private configuration.
E.g. so you can run something like:
with_my python3 -c 'import my.books.kobo as kobo; print(kobo.get_todos())'
Feel free to use your preferred way of managing these packages otherwise.
"""
###### set this v
# can be empty if you're not planning to use modules that use private configuration
# otherwise see readme to learn how to set it
from pathlib import Path
MY_CONFIG = str(Path('~/.config/my').expanduser())
######
# you shouldn't have the need to modify rest; but let me know if you miss anything!
from pathlib import Path
# directory where 'my' package is present
MY_DIR = str(Path(__file__).resolve().absolute().parent)
if __name__ == '__main__':
import os
import sys
def prepend(envvar, path):
if len(path) == 0:
return
old = os.environ.get(envvar, '')
val = path + ('' if len(old) == 0 else f':{old}')
os.environ[envvar] = val
# todo wonder why py.typed file in mycfg didn't help?
for v in ['MYPYPATH', 'PYTHONPATH']:
prepend(v, MY_DIR)
# the private config has higher precedence over my.config in the package (which is just a stub)
prepend(v, MY_CONFIG)
rest = sys.argv[1:]
os.execvp(rest[0], rest)