From 8ddf336418a609cb76f51aa7d24d665d1a617d86 Mon Sep 17 00:00:00 2001 From: steppi Date: Thu, 6 May 2021 21:31:44 -0400 Subject: [PATCH 1/3] Use appdirs to choose location of adeft home folder --- adeft/download/__main__.py | 2 +- adeft/locations.py | 10 ++++------ doc/requirements.txt | 1 + setup.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/adeft/download/__main__.py b/adeft/download/__main__.py index 0801e26b..1422bb79 100644 --- a/adeft/download/__main__.py +++ b/adeft/download/__main__.py @@ -5,7 +5,7 @@ setup_test_resource_folder -# Create .adeft folder if it does not already exist +# Create adeft data folder if it does not already exist if not os.path.exists(ADEFT_PATH): os.makedirs(ADEFT_PATH) diff --git a/adeft/locations.py b/adeft/locations.py index 988c9da6..d7cc7a38 100644 --- a/adeft/locations.py +++ b/adeft/locations.py @@ -6,14 +6,12 @@ """ import os -import pystow from adeft import __version__ +from appdirs import user_data_dir -# If the adeft resource directory does not exist, try to create it using PyStow -# Can be specified with ADEFT_HOME environment variable, otherwise defaults -# to $HOME/.data/adeft/<__version__>. The location of $HOME can be overridden with -# the PYSTOW_HOME environment variable -ADEFT_HOME = pystow.join('adeft') +ADEFT_HOME = os.environ.get('ADEFT_HOME') +if ADEFT_HOME is None: + ADEFT_HOME = os.path.join(user_data_dir(), 'adeft') ADEFT_PATH = os.path.join(ADEFT_HOME, __version__) ADEFT_MODELS_PATH = os.path.join(ADEFT_PATH, 'models') diff --git a/doc/requirements.txt b/doc/requirements.txt index 41e26f7d..fc518753 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -5,3 +5,4 @@ nltk wget requests flask +appdirs diff --git a/setup.py b/setup.py index 221cd6da..817fedee 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ ], packages=find_packages(), install_requires=['nltk', 'scikit-learn>=0.20.0', 'wget', - 'requests', 'flask', 'pystow'], + 'requests', 'flask', 'appdirs'], extras_require={'test': ['pytest', 'pytest-cov']}, keywords=['nlp', 'biology', 'disambiguation'], ext_modules=extensions, From 8a83781ed0a5264479a55f2fd0eda915f29d54dd Mon Sep 17 00:00:00 2001 From: steppi Date: Thu, 6 May 2021 22:52:43 -0400 Subject: [PATCH 2/3] Update intro notebook with new adeft home location --- notebooks/introduction.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebooks/introduction.ipynb b/notebooks/introduction.ipynb index df2c11b8..47045030 100644 --- a/notebooks/introduction.ipynb +++ b/notebooks/introduction.ipynb @@ -25,7 +25,7 @@ "$ python -m adeft.download\n", "```\n", "\n", - "By default, models will be stored in the users home directory in a hidden folder named ``.adeft``. Users may set the environment variable `ADEFT_HOME` in their shell profile to choose an alternative location." + "By default, models will be stored in a folder named ``adeft`` within a platform specific user data location determined by the [appdirs](https://pypi.org/project/appdirs/) Python package. Users may set the environment variable `ADEFT_HOME` in their shell profile to choose an alternative location." ] }, { @@ -453,7 +453,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.8.6" } }, "nbformat": 4, From ff7a4a6c5387cd45424e3f879e8de457228a18d0 Mon Sep 17 00:00:00 2001 From: steppi Date: Thu, 6 May 2021 22:55:14 -0400 Subject: [PATCH 3/3] Update module docstring for new home location --- adeft/locations.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adeft/locations.py b/adeft/locations.py index d7cc7a38..5313cb79 100644 --- a/adeft/locations.py +++ b/adeft/locations.py @@ -1,8 +1,9 @@ """ Contains paths to locations on user's system where models and resources are -to be stored. These all live in adeft's home folder which defaults to the -hidden directory ".adeft" in the user's home directory but which can be -specified by setting the environment variable ADEFT_HOME in the user's profile. +to be stored. These all live in adeft's home folder which defaults to +a directory "adeft" in a location determined by Python's `appdirs` package. +An alternative location can be specified by setting the environment variable +ADEFT_HOME in the user's profile. """ import os