oscarlevin / pretext-tools

MIT License
7 stars 8 forks source link

Extension fails to activate on OSX #61

Closed siwelwerd closed 9 months ago

siwelwerd commented 11 months ago

I cannot get the extension to load on my desktop version of VSCode (I have been enjoying using it in Codespaces), running OSX version 13.5 (22G74).

Steps taken: I completely uninstalled VSCode (following steps here: https://stackoverflow.com/a/47561948), then downloaded and installed VSCode version 1.82.2. Then I installed the pretext-tools extension. When I click the 'PreTeXt' button on the bottom toolbar, I get an error pop up saying command 'pretext-tools.selectPretextCommand' not found.

I pulled up the Developer Tools, and noticed this error message indicating the extension is not activating properly.

mainThreadExtensionService.ts:113 Activating extension 'oscarlevin.pretext-tools' failed: Cannot read properties of undefined (reading 'label').
$onExtensionActivationError @ mainThreadExtensionService.ts:113
N @ rpcProtocol.ts:455
M @ rpcProtocol.ts:440
H @ rpcProtocol.ts:370
G @ rpcProtocol.ts:296
(anonymous) @ rpcProtocol.ts:161
w @ event.ts:1107
fire @ event.ts:1138
fire @ ipc.net.ts:650
X.onmessage @ localProcessExtensionHost.ts:585
localProcessExtensionHost.ts:283 Extension Host
localProcessExtensionHost.ts:284 Traceback (most recent call last):  File "/opt/homebrew/Caskroom/miniconda/base/bin/pretext", line 8, in <module>    sys.exit(main())  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/core.py", line 1130, in __call__    return self.main(*args, **kwargs)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/core.py", line 1055, in main    rv = self.invoke(ctx)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/core.py", line 1635, in invoke    rv = super().invoke(ctx)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/core.py", line 1404, in invoke    return ctx.invoke(self.callback, **ctx.params)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/core.py", line 760, in invoke    return __callback(*args, **kwargs)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func    return f(get_current_context(), *args, **kwargs)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/cli.py", line 81, in main    Project().print_target_names()  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 296, in print_target_names    for target in self.targets():  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 283, in targets    Target(xml_element=target_element, project_path=self.__project_path)  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 29, in __init__    if (ex_dir := self.external_dir()) is not None:  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 92, in external_dir    dir_ele = self.publication_xml().find("source/directories")  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 87, in publication_xml    ele_tree = ET.parse(self.publication())  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 78, in publication    return self.project_path() / self.require_tag_text("publication").strip()  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.9/site-packages/pretext/project/__init__.py", line 47, in require_tag_text    assert element is not None, f"Invalid project file: missing {tag_name} tag."AssertionError: Invalid project file: missing publication tag.

VSCode version info:

Version: 1.82.2 (Universal)
Commit: abd2f3db4bdb28f9e95536dfa84d8479f1eb312d
Date: 2023-09-14T05:59:47.790Z
Electron: 25.8.1
ElectronBuildId: 23779380
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 22.6.0

I am not ruling out pilot error here, but I feel like with a fresh install it ought to probably Just Work (TM)?

oscarlevin commented 11 months ago

I definitely need to improve the error handling on this. I suspect the issue is that pretext is trying to validate your project.ptx file, and that since v2.0 of the CLI was released, that is throwing an error that wasn't present before.

If you post the content of your project.ptx, I can help you fix that. You might also try starting a new project (CTRL+SHIFT+P -> "PreTeXt: New Project") and see if the issue persist with the new project.

siwelwerd commented 11 months ago

Thanks @oscarlevin. Happy to report that with the suggestion that Pretext 2.0 changes may be causing this, I figured it out. For reasons I don't understand (because python environment handling is a mess), I have multiple versions of PreTeXt installed in different locations, and the PATH variable I get when I open a shell in the terminal (from the OS) is different than the PATH variable I get when I open a shell in the terminal from VS code:

Opening a terminal from the OS:

(base) drew@Drews-MBP ~ % which pretext
/opt/homebrew/Caskroom/miniconda/base/bin/pretext
(base) drew@Drews-MBP ~ % echo $PATH
/opt/homebrew/Caskroom/miniconda/base/bin:/opt/homebrew/Caskroom/miniconda/base/condabin:/Users/drew/Library/Python/3.8/bin:/Library/TeX/texbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
(base) drew@Drews-MBP ~ % 

Using the terminal within VScode:

(base) drew@Drews-MBP calculus % which pretext
/Users/drew/Library/Python/3.8/bin/pretext
(base) drew@Drews-MBP calculus % echo $PATH
/Users/drew/Library/Python/3.8/bin:/Library/TeX/texbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/homebrew/Caskroom/miniconda/base/bin:/opt/homebrew/Caskroom/miniconda/base/condabin:/Users/drew/Library/Python/3.8/bin:/opt/homebrew/bin:/opt/homebrew/sbin
(base) drew@Drews-MBP calculus % 

Once I updated the /opt/homebrew/Caskroom/miniconda/base/bin/pretext to 2.0, now it works. But I was mislead thinking all my PreTeXt in VSCode was 2.0, because the terminal there was calling the /Users/drew/Library/Python/3.8/bin/pretext, while the error message above indicates the extension was calling the other one.

So all that to say: the version of PreTeXt used by the PreTeXt-tools extension may not be the same as the version used by the VS code terminal, which is likely to cause further difficulties in tracking down bugs.