diff --git a/nbs/01_config.ipynb b/nbs/01_config.ipynb index b6df4fd..e2fbe19 100644 --- a/nbs/01_config.ipynb +++ b/nbs/01_config.ipynb @@ -99,7 +99,9 @@ "#| export\n", "def _win_find_path(_dir=None):\n", " if _dir is None:\n", - " dirs = [r'C:\\Program Files\\Stata19',\n", + " dirs = [r'C:\\Program Files\\StataNow19',\n", + " r'C:\\Program Files\\Stata19',\n", + " r'C:\\Program Files\\StataNow18',\n", " r'C:\\Program Files\\Stata18',\n", " r'C:\\Program Files\\Stata17']\n", " else:\n", @@ -155,23 +157,25 @@ "def _mac_find_path(_dir=None):\n", " \"\"\"\n", " Attempt to find Stata path on macOS when not on user's PATH.\n", - " Modified from stata_kernel's original to only location \"Applications/Stata\". \n", + " Modified from stata_kernel's original to \"/Applications/StataNow\" and \"/Applications/Stata\".\n", "\n", " Returns:\n", " (str): Path to Stata. Empty string if not found.\n", " \"\"\"\n", " if _dir is None:\n", - " _dir = '/Applications/Stata'\n", - " path = Path(_dir)\n", - " if not os.path.exists(path):\n", - " return ''\n", + " dirs = [r'/Applications/StataNow',\n", + " r'/Applications/Stata']\n", " else:\n", - " try:\n", - " # find the application with the suffix .app\n", - " # example path: /Applications/Stata/StataMP.app\n", - " return str(next(path.glob(\"Stata*.app\")))\n", - " except StopIteration:\n", - " return ''" + " dirs = [_dir] \n", + " for this_dir in dirs:\n", + " path = Path(this_dir)\n", + " if os.path.exists(path):\n", + " try:\n", + " # find the application with the suffix .app\n", + " # example path: /Applications/Stata/StataMP.app\n", + " return str(next(path.glob(\"Stata*.app\")))\n", + " except StopIteration:\n", + " return ''" ] }, { @@ -422,12 +426,13 @@ "source": [ "#| export\n", "def set_pystata_path(stata_dir=None):\n", + " stata_dir = stata_dir.strip('\"\\'')\n", " if stata_dir is None:\n", " stata_dir, _ = find_dir_edition()\n", " if not os.path.isdir(stata_dir):\n", - " raise OSError(f'Specified stata_dir, \"{stata_dir}\", is not a valid directory path')\n", + " raise OSError(f'Specified stata_dir, {stata_dir}, is not a valid directory path')\n", " if not os.path.isdir(os.path.join(stata_dir, 'utilities')):\n", - " raise OSError(f'Specified stata_dir, \"{stata_dir}\", is not Stata\\'s installation path')\n", + " raise OSError(f'Specified stata_dir, {stata_dir}, is not Stata\\'s installation path')\n", " sys.path.append(os.path.join(stata_dir, 'utilities'))" ] }, diff --git a/nbstata/config.py b/nbstata/config.py index bae6e26..0c31c25 100644 --- a/nbstata/config.py +++ b/nbstata/config.py @@ -20,7 +20,9 @@ # %% ../nbs/01_config.ipynb 8 def _win_find_path(_dir=None): if _dir is None: - dirs = [r'C:\Program Files\Stata19', + dirs = [r'C:\Program Files\StataNow19', + r'C:\Program Files\Stata19', + r'C:\Program Files\StataNow18', r'C:\Program Files\Stata18', r'C:\Program Files\Stata17'] else: @@ -45,23 +47,25 @@ def _win_find_path(_dir=None): def _mac_find_path(_dir=None): """ Attempt to find Stata path on macOS when not on user's PATH. - Modified from stata_kernel's original to only location "Applications/Stata". + Modified from stata_kernel's original to "/Applications/StataNow" and "/Applications/Stata". Returns: (str): Path to Stata. Empty string if not found. """ if _dir is None: - _dir = '/Applications/Stata' - path = Path(_dir) - if not os.path.exists(path): - return '' + dirs = [r'/Applications/StataNow', + r'/Applications/Stata'] else: - try: - # find the application with the suffix .app - # example path: /Applications/Stata/StataMP.app - return str(next(path.glob("Stata*.app"))) - except StopIteration: - return '' + dirs = [_dir] + for this_dir in dirs: + path = Path(this_dir) + if os.path.exists(path): + try: + # find the application with the suffix .app + # example path: /Applications/Stata/StataMP.app + return str(next(path.glob("Stata*.app"))) + except StopIteration: + return '' # %% ../nbs/01_config.ipynb 12 def _other_find_path(): @@ -110,12 +114,13 @@ def find_edition(stata_dir): # %% ../nbs/01_config.ipynb 25 def set_pystata_path(stata_dir=None): + stata_dir = stata_dir.strip('"\'') if stata_dir is None: stata_dir, _ = find_dir_edition() if not os.path.isdir(stata_dir): - raise OSError(f'Specified stata_dir, "{stata_dir}", is not a valid directory path') + raise OSError(f'Specified stata_dir, {stata_dir}, is not a valid directory path') if not os.path.isdir(os.path.join(stata_dir, 'utilities')): - raise OSError(f'Specified stata_dir, "{stata_dir}", is not Stata\'s installation path') + raise OSError(f'Specified stata_dir, {stata_dir}, is not Stata\'s installation path') sys.path.append(os.path.join(stata_dir, 'utilities')) # %% ../nbs/01_config.ipynb 29