quarto-ext / include-code-files

Quarto extension to include code from source files.
MIT License
56 stars 6 forks source link

install fails on Mac OS x #6

Open bob-carpenter opened 1 year ago

bob-carpenter commented 1 year ago

I'm not sure what I'm supposed to be doing but the instructions as given on the README.md don't work for me.

~/github/bob-carpenter/stan-getting-started (main)$ quarto add quarto-ext/include-code-files

Quarto extensions may execute code when documents are rendered. If you do not 
trust the authors of the extension, we recommend that you do not install or 
use the extension.
 ? Do you trust the authors of this extension (Y/n) › Yes
[✓] Downloading
[✓] Unzipping
    Found 1 extension.

The following changes will be made:
Include Code Files   [Install]   1.0.0 (filter)
 ? Would you like to continue (Y/n) › Yes

[✓] Extension installation complete.
Learn more about this extension at https://www.github.com/quarto-ext/include-code-files

And then I put this in my Yaml:

filters:
    - include-code-filters

and then I run and it fails with this message when doing the final rendering:

Error running filter /Applications/quarto/share/filters/main.lua:
Error running filter /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-filters:
Could not find executable /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-filters
stack traceback:
    /Applications/quarto/share/filters/main.lua:4026: in function </Applications/quarto/share/filters/main.lua:4005>
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    /Applications/quarto/share/filters/main.lua:449: in local 'callback'
    /Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
stack traceback:
    /Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    /Applications/quarto/share/filters/main.lua:449: in local 'callback'
    /Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
make: *** [stan-getting-started.pdf] Error 1

After I run the install, I can't find the include-code-filters anywhere on my OS.

dragonstyle commented 1 year ago

Looks like perhaps a simple typo?

filters:
  - include-code-files

per

https://github.com/quarto-ext/include-code-files

bob-carpenter commented 1 year ago

Thanks, @dragonstyle. That was definitely user error on my part.

The install produced an include-code-files.lua but it's not getting picked up. Then I moved a .lua file into quarto directory, but that didn't work either:

Error running filter /Applications/quarto/share/filters/main.lua:
Error running filter /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-files:
Could not find executable /Users/bcarpenter/github/bob-carpenter/stan-getting-started/quarto/include-code-files
stack traceback:
    /Applications/quarto/share/filters/main.lua:4026: in function </Applications/quarto/share/filters/main.lua:4005>
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    /Applications/quarto/share/filters/main.lua:449: in local 'callback'
    /Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
stack traceback:
    /Applications/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    /Applications/quarto/share/filters/main.lua:449: in local 'callback'
    /Applications/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:495: in function </Applications/quarto/share/filters/main.lua:476>
make: *** [stan-getting-started.pdf] Error 1

Is there some way I can install this extension and distribute with my document? Otherwise, this is going to be too hard for me and people I'd like to run this document to use. Which is too bad, because this is exactly the extension I want. I wrote one myself in Java for a previous set of documentation I was writing 15 years ago, but don't want to go down that rabbit hole again.

rfhb commented 1 year ago

Worked for me running within the repo's quarto folder quarto add quarto-ext/include-code-files (creates _extensions folder infrastructure)

dragonstyle commented 1 year ago

Archive.zip

There is a sample I created. I used:

0) make a directory to work in and cd to that directory 1) quarto add quarto-ext/include-code-files to add the extension 1a) (after installation, note the presence of an _extension directory which contains the newly added extension 2) Make a test.qmd like:

---
title: "My Document"
filters:
   - include-code-files
---

```{.python include="script.py"}

3) Make a script.py like:
````python
# Program to add two matrices using nested loop

X = [[12,7,3],
    [4 ,5,6],
    [7 ,8,9]]

Y = [[5,8,1],
    [6,7,3],
    [4,5,9]]

result = [[0,0,0],
         [0,0,0],
         [0,0,0]]

# iterate through rows
for i in range(len(X)):
   # iterate through columns
   for j in range(len(X[0])):
       result[i][j] = X[i][j] + Y[i][j]

for r in result:
   print(r)

4) quarto render test.qmd

bob-carpenter commented 1 year ago

Thanks for all the help.

I just created a PR that adds a note to README.md explaining that the _extensions directory needs to go in the same directory as your quarto files. At least that's what solved the problem for me. If there's a more general solution, please include that instead of my PR.

P.S. Thanks for the extension---it's just what I need!