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

"--filter" doesn't use shebang in executable filters #1389

Closed
jkr opened this issue Jun 30, 2014 · 3 comments
Closed

"--filter" doesn't use shebang in executable filters #1389

jkr opened this issue Jun 30, 2014 · 3 comments

Comments

@jkr
Copy link
Collaborator

jkr commented Jun 30, 2014

Presumably as a result of 3fe6b57, pandoc now prefers the default version of program to that in the shebang. For example, in arch, python means python3, so I put #!/usr/bin/env python2 at the top of my executable. But if invoked with --filter, it still runs python.

Example, let's call it "filter.py":

#!/usr/bin/env python2

import pandocfilters as PF
import sys

def str_to_py_version(k, v, fmt, meta):
    if k == "Str":
        return PF.Str(sys.version.split()[0])

if __name__ == '__main__':
    PF.toJSONFilter(str_to_py_version)

using development pandoc:

jkr@bucket $ echo "foo" | pandoc -t json | ./filter.py | pandoc -f json
<p>2.7.6</p>

jkr@bucket $ echo "foo" | pandoc --filter ./filter.py
<p>3.4.0</p>

It should use the shebang in executables.

@jkr
Copy link
Collaborator Author

jkr commented Jun 30, 2014

A quick look at the code suggests that it's because findExecutable (on line 101) only looks in the PATH for executables, and if it doesn't find them there, assumes they're not executable.

@jgm
Copy link
Owner

jgm commented Jun 30, 2014

Yep - we should also check directly to see if the file is executable.

+++ Jesse Rosenthal [Jun 30 14 12:11 ]:

A quick look at the code suggests that it's because findExecutable (on
line 101) only looks in the PATH for executables, and if it doesn't
find them there, assumes they're not executable.


Reply to this email directly or [1]view it on GitHub.

References

  1. "--filter" doesn't use shebang in executable filters #1389 (comment)

@jkr
Copy link
Collaborator Author

jkr commented Jun 30, 2014

Actually, findExecutable seems like it would do the job, if given in an absolute path. Would there be any problem with running canonicalizePath if it's a path? Something like

mbexe <- if '/' `elem` f -- don't check PATH if filter name it has a path
                  then canonicalizePath f >>= findExecutable
                  else findExecutable f

Seems to build and work.

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

No branches or pull requests

2 participants