update with_my script, use correct order of arguments
This commit is contained in:
parent
6d1fba2171
commit
5d3c0bdb1f
1 changed files with 8 additions and 12 deletions
20
with_my
20
with_my
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
This file is used for specifying pathes for 'my' package and potentially private configuration.
|
This file is used for specifying paths for 'my' package and potentially private configuration.
|
||||||
E.g. so you can run something like:
|
E.g. so you can run something like:
|
||||||
|
|
||||||
with_my python3 -c 'import my.books.kobo as kobo; print(kobo.get_todos())'
|
with_my python3 -c 'import my.books.kobo as kobo; print(kobo.get_todos())'
|
||||||
|
@ -29,22 +29,18 @@ if __name__ == '__main__':
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def upd(envvar, path):
|
def prepend(envvar, path):
|
||||||
if len(path) == 0:
|
if len(path) == 0:
|
||||||
return
|
return
|
||||||
val = os.environ.get(envvar, '')
|
old = os.environ.get(envvar, '')
|
||||||
if val == '':
|
val = path + ('' if len(old) == 0 else f':{old}')
|
||||||
val = path
|
|
||||||
else:
|
|
||||||
val = val + ':' + path
|
|
||||||
os.environ[envvar] = val
|
os.environ[envvar] = val
|
||||||
|
|
||||||
# TODO wonder why py.typed file in mycfg didn't help?
|
# todo wonder why py.typed file in mycfg didn't help?
|
||||||
for v in ['MYPYPATH', 'PYTHONPATH']:
|
for v in ['MYPYPATH', 'PYTHONPATH']:
|
||||||
upd(v, MY_DIR) # TODO not sure if it should do it if you use install -e?
|
prepend(v, MY_DIR)
|
||||||
|
# the private config has higher precedence over my.config in the package (which is just a stub)
|
||||||
# TODO not sure if it should update PYTHONPATH for my_config here??
|
prepend(v, MY_CONFIG)
|
||||||
upd(v, MY_CONFIG)
|
|
||||||
|
|
||||||
rest = sys.argv[1:]
|
rest = sys.argv[1:]
|
||||||
os.execvp(rest[0], rest)
|
os.execvp(rest[0], rest)
|
||||||
|
|
Loading…
Add table
Reference in a new issue