From e9d1c2ab771bc352124f7c4a742e16f8dd09ff29 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 28 Sep 2025 15:58:03 +0100 Subject: [PATCH 1/4] Add StataNow19 directory on Windows --- nbs/01_config.ipynb | 3 ++- nbstata/config.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nbs/01_config.ipynb b/nbs/01_config.ipynb index b6df4fd..d03ae84 100644 --- a/nbs/01_config.ipynb +++ b/nbs/01_config.ipynb @@ -99,7 +99,8 @@ "#| 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\\Stata18',\n", " r'C:\\Program Files\\Stata17']\n", " else:\n", diff --git a/nbstata/config.py b/nbstata/config.py index bae6e26..dc790cf 100644 --- a/nbstata/config.py +++ b/nbstata/config.py @@ -20,7 +20,8 @@ # %% ../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\Stata18', r'C:\Program Files\Stata17'] else: From 62a079726452c9b63cdcd8bd1e3096d60f9b8709 Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Sun, 28 Sep 2025 16:18:38 +0100 Subject: [PATCH 2/4] On macOS additionally check /Applications/StataNow --- nbs/01_config.ipynb | 24 +++++++++++++----------- nbstata/config.py | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/nbs/01_config.ipynb b/nbs/01_config.ipynb index d03ae84..3f86f08 100644 --- a/nbs/01_config.ipynb +++ b/nbs/01_config.ipynb @@ -156,23 +156,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 ''" ] }, { diff --git a/nbstata/config.py b/nbstata/config.py index dc790cf..0abdf63 100644 --- a/nbstata/config.py +++ b/nbstata/config.py @@ -46,23 +46,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(): From b31af9d89e83a1864369013238da53ef303bb5dd Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Tue, 30 Sep 2025 08:53:33 +0100 Subject: [PATCH 3/4] Add possible StataNow18 directory on Windows --- nbs/01_config.ipynb | 1 + nbstata/config.py | 1 + 2 files changed, 2 insertions(+) diff --git a/nbs/01_config.ipynb b/nbs/01_config.ipynb index 3f86f08..5461df2 100644 --- a/nbs/01_config.ipynb +++ b/nbs/01_config.ipynb @@ -101,6 +101,7 @@ " if _dir is None:\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", diff --git a/nbstata/config.py b/nbstata/config.py index 0abdf63..3387336 100644 --- a/nbstata/config.py +++ b/nbstata/config.py @@ -22,6 +22,7 @@ def _win_find_path(_dir=None): if _dir is None: 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: From c39b4f9e553a3ecb28ff66a21e6f188a17aaf00c Mon Sep 17 00:00:00 2001 From: Tom Palmer Date: Tue, 30 Sep 2025 09:00:06 +0100 Subject: [PATCH 4/4] Strip single and double quotes from stata_dir --- nbs/01_config.ipynb | 5 +++-- nbstata/config.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nbs/01_config.ipynb b/nbs/01_config.ipynb index 5461df2..e2fbe19 100644 --- a/nbs/01_config.ipynb +++ b/nbs/01_config.ipynb @@ -426,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 3387336..0c31c25 100644 --- a/nbstata/config.py +++ b/nbstata/config.py @@ -114,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