-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from karlicoss/my.config
initial steps for my.config
- Loading branch information
Showing
11 changed files
with
90 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
* IDE setup: make sure my.config is in your package search path | ||
In runtime, ~my.config~ is imported from the user config directory dynamically. | ||
|
||
However, Pycharm/Emacs/whatever you use won't be able to figure that out, so you'd need to adjust your IDE configuration. | ||
|
||
- Pycharm: basically, follow the instruction [[https://stackoverflow.com/a/55278260/706389][here]] | ||
|
||
i.e. create a new interpreter configuration (e.g. name it "Python 3.7 (for HPI)"), and add =~/.config/my=. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
''' | ||
A hook to insert user's config directory into Python's search path. | ||
- Ideally that would be in __init__.py (so it's executed without having to import explicityly) | ||
But, with namespace packages, we can't have __init__.py in the parent subpackage | ||
(see http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-init-py-trap) | ||
Please let me know if you are aware of a better way of dealing with this! | ||
''' | ||
|
||
|
||
# separate function to present namespace pollution | ||
def setup_config(): | ||
from pathlib import Path | ||
import sys | ||
import os | ||
import warnings | ||
|
||
# not sure if that's necessary, i.e. could rely on PYTHONPATH instead | ||
# on the other hand, by using MY_CONFIG we are guaranteed to load it from the desired path? | ||
mvar = os.environ.get('MY_CONFIG') | ||
if mvar is not None: | ||
mycfg_dir = Path(mvar) | ||
else: | ||
# TODO use appdir?? | ||
cfg_dir = Path('~/.config').expanduser() | ||
mycfg_dir = cfg_dir / 'my' | ||
|
||
# TODO maybe try importing first and if it's present, don't do anything? | ||
|
||
if not mycfg_dir.exists(): | ||
warnings.warn(f"my.config package isn't found! (expected at {mycfg_dir}). This might result in issues.") | ||
from . import mycfg_stub as mycfg | ||
sys.modules['my.config'] = mycfg | ||
else: | ||
mp = str(mycfg_dir) | ||
if mp not in sys.path: | ||
sys.path.insert(0, mp) | ||
|
||
try: | ||
import my.config | ||
except ImportError as ex: | ||
warnings.warn(f"Importing my.config failed! (error: {ex}). This might result in issues.") | ||
|
||
|
||
setup_config() | ||
del setup_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
Feel free to remove this if you don't need it/add your own custom settings and use them | ||
""" | ||
|
||
class hypothesis: | ||
# expects outputs from https://github.com/karlicoss/hypexport | ||
# (it's just the standard Hypothes.is export format) | ||
export_path = '/path/to/hypothesis/data' |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ def main(): | |
'testing': [ | ||
'pytest', | ||
'pytz', | ||
'pylint', | ||
], | ||
}, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters