Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving macro fails with NameError: name 'fnSuffix' is not defined #1280

Closed
fatherofinvention opened this issue Feb 3, 2022 · 4 comments
Closed

Comments

@fatherofinvention
Copy link

fatherofinvention commented Feb 3, 2022

Small description
When saving a recorded macro error NameError: name 'fnSuffix' is not defined is printed to the screen no matter what is entered as a keystroke. I have tried single characters, numbers, and strings, including keyboard modifiers and omiting them, but none of those combinations work.

Actual result with screenshot
CleanShot 2022-02-03 at 09 17 48@2x

Traceback (most recent call last): File "/opt/homebrew/Cellar/visidata/2.8/libexec/lib/python3.9/site-packages/visidata/basesheet.py", line 167, in execCommand escaped = super().execCommand2(cmd, vdglobals=vdglobals) File "/opt/homebrew/Cellar/visidata/2.8/libexec/lib/python3.9/site-packages/visidata/basesheet.py", line 69, in execCommand2 exec(code, vdglobals, LazyChainMap(vd, self)) File "macro-record", line 1, in <module> import plugins.dedupe File "/opt/homebrew/Cellar/visidata/2.8/libexec/lib/python3.9/site-packages/visidata/macros.py", line 60, in startMacro vd.cmdlog.saveMacro(vd.macroMode.rows, ks) File "/opt/homebrew/Cellar/visidata/2.8/libexec/lib/python3.9/site-packages/visidata/macros.py", line 39, in saveMacro macropath = Path(fnSuffix(options.visidata_dir+"macro")) NameError: name 'fnSuffix' is not defined

Steps to reproduce with sample data and a .vd

  1. Record macro
  2. Enter anything into keystroke input
  3. Get error

Additional context
Visidata version: 2.8
MacOS version: 12.2
Python version: 3.9.10

@anjakefala
Copy link
Collaborator

Thanks for the bug report @fatherofinvention! =) Should be fixed, now.

@code86
Copy link

code86 commented Feb 21, 2022

I am still getting the same error message as OP.

Ctrl+E (error-recent) shows error was activated in line 39 of macros.py

In macros.py (line 39), fnSuffix is called with one argument.

But in cmdlog.py (line 42), fnSuffix is defined with two parameters? (vd, prefix)

Could that be the problem?


File "/Users/code86/opt/miniconda3/envs/env2/lib/python3.8/site-packages/visidata/macros.py", line 39, in saveMacro
macropath = Path(fnSuffix(options.visidata_dir+"macro"))
NameError: name 'fnSuffix' is not defined

@anjakefala
Copy link
Collaborator

Hi @code86!

I should have been clearer in the message.

This bug was fixed on the develop branch of VisiData. We have not released a newer version of VisiData since it was fixed.

I am not sure how to use conda to install a package through a git branch, but the way to do it with pip is pip3 install --upgrade git+https://github.com/saulpw/visidata.git@develop.
(Edit: I checked, and the stackoverflow accepted way is to use pip as described https://stackoverflow.com/questions/19042389/conda-installing-upgrading-directly-from-github)


Some additional technical info:

In macros.py (line 39), fnSuffix is called with one argument.
But in cmdlog.py (line 42), fnSuffix is defined with two parameters? (vd, prefix)

Yup! That was the problem. Execstrings in VisiData (addCommand('keystroke', 'longname', 'execstr')) do not require vd. or sheet.prefixes. They will look up symbols in the current sheet and in vd obj before they look for it in the global namespace of the visidata module. sheet. and vd. are required outside of execstrings, as you noticed, and were forgotten in that location. Hence the bug.

@fscheong
Copy link

Thank you, @anjakefala!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants