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

Python2 compatibility #59

Closed
lifeforms opened this issue Apr 22, 2017 · 1 comment
Closed

Python2 compatibility #59

lifeforms opened this issue Apr 22, 2017 · 1 comment

Comments

@lifeforms
Copy link

Hi, I maintain the FreeBSD port of grc and I'm busy updating our package to v1.11.

I noticed that the README states that grc has python2 + python3 compatibility.

The python3 in the shebang is not a problem, we replace that with the python interpreter of the user's choosing.

However, in commit 1516a3e the python3-only FileNotFoundError was introduced. This gives the following error on python2:

# grc foo
Traceback (most recent call last):
  File "/usr/local/bin/grc", line 193, in <module>
    except FileNotFoundError:
NameError: name 'FileNotFoundError' is not defined

Besides the try-except part, grc seems to still run fine on python2 otherwise.

I would like not forcing users to install python3, so I would prefer to change the try-except in grc to something like this, which would work in python2/3 and still be mostly informative I think:

        try:
            os.execvp(args[0], args)
        except OSError:
            sys.stderr.write('grc: %s: command not found\n' % args[0])
            sys.exit(1)
        except Exception as e:
            sys.stderr.write('grc: %s: %s\n' % (args[0], e.strerror))
            sys.exit(1)

Other solutions would be welcome too.

Alternatively, if grc will support python3 only, this doesn't need to be changed (but the README would); in that case I might either patch it downstream for python2 users or I would just require python3 as a dependency.

@garabik
Copy link
Owner

garabik commented Apr 23, 2017

Good catch - I haven't noticed this while testing, because the nonexistent exception is invoked only if you run grc with an invalid command. I slightly modified your solution, since I prefer to have a full debug output if there is any other problem apart from OSError. I'll probably make a new fix-up release soon.

Yes, I'd very much prefer grc to work with python2 as well.

@garabik garabik closed this as completed Apr 23, 2017
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