question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python-gflags is not Python 3 compatible

See original GitHub issue

Description of the problem:

See the last post in #3065 - the pkg_tar rule depends on the python-gflags (included in the Bazel repo), which is not py3 compatible and fails with a syntax error on my system. According to https://github.com/google/python-gflags/issues/20 (the error report to the syntax error I get) the argparse standard library should be preferred. The current version of gflags however seems to be py3 compatible, so an update might be worth investigating.

If possible, provide a minimal example to reproduce the problem:

load(“@bazel_tools//tools/build_defs/pkg:pkg.bzl”, “pkg_tar”)

Then run any BUILD file with a pgk_tar rule on Arch Linux (or any other distro that sets /usr/bin/python to python3)

Environment info

Have you found anything relevant by searching the web?

https://github.com/bazelbuild/bazel/search?q=from+third_party.py+import+gflags shows that it is only used in 16 files (2 of the results are duds).

I think it might be possible to remove or replace gflags 2.0 entirely from Bazel. I am not so sure if gflags 3.x should be used to replace it (it is not very well documented imho, but Google employees might be more used to writing code with it?) or if plain argparse might be a better choice. Gflags seems to be used by other languages (e.g. Java) too, so a common standard might be still desirable.

Another option might be to patch the few issues in https://github.com/bazelbuild/bazel/blob/master/third_party/py/gflags/__init__.py (https://github.com/bazelbuild/bazel/blob/master/third_party/py/gflags/BUILD claims that it is PY2AND3 compatible after all) - a few “except Foo as e” instead of “except Foo, e” and importing print_function from future are probably all it takes to make it work. This approach would break Python compatibility below 2.6, I am not sure if this is good or bad for your use case. There might be already some other libraries that also require more recent versions (…but is Python2 recent at all?).

Anything else, information or logs or outputs that would be helpful?

(If they are large, please upload as attachment or provide link).

This really should have been caught by some kind of test that takes a look at py_library rules with srcs_version tags and verifies that these are actually correct:

$ python -m py_compile foo.py 
  File "foo.py", line 1091
    except gflags_validators.Error, e:
                                  ^
SyntaxError: invalid syntax

$ python2 -m py_compile foo.py
$

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
damienmgcommented, Sep 26, 2017

Both code reviews have been merged, closing.

0reactions
gpsheadcommented, Mar 27, 2019

The correct thing to do here is move off of gflags entirely, not carry your own copy of the ancient dead code at all. Use absl.flags from https://pypi.org/project/absl-py/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect if code is python 3 compatible - Stack Overflow
Just open the python files in the pycharm editor, it will show warnings if the code is not compatible to Python2 or Python3....
Read more >
Porting Python 2 Code to Python 3 — Python 3.11.1 ...
To make your project be single-source Python 2/3 compatible, the basic ... Even if your dependencies are not supporting Python 3 yet that...
Read more >
Security update for javapackages-tools, javassist, mysql ...
An update that contains security fixes and contains one feature can now be installed. Description: This update for javapackages-tools, ...
Read more >
Commits - python-gflags - Google Code
Author Date Commit jwilliams@endpoint.com Feb 21, 2012 41 csilvers Jan 18, 2012 40 csilvers Jan 18, 2012 39
Read more >
python2-python-gflags-3.1.1-lp152.3.4.noarch RPM - RPMFind
Update to version 3.1.0 * Python3 compatibility * Removed ... support for CLIF flag processing (not included in python-gflags repo yet).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found