Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions nbs/01_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 ''"
]
},
{
Expand Down Expand Up @@ -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'))"
]
},
Expand Down
33 changes: 19 additions & 14 deletions nbstata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down Expand Up @@ -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
Expand Down