buck icon indicating copy to clipboard operation
buck copied to clipboard

Python3 compatibility issue in buck_parser/buck.py

Open navkast opened this issue 4 years ago • 0 comments

Background

  • I'm using the latest Buck release: https://github.com/facebook/buck/releases/tag/v2021.01.12.01
  • I'm using Python 3.7.
  • Mac OS X Big Sur on a case-sensitive partition.

Problem

I see that the dictionary parsed here: https://github.com/facebook/buck/blob/master/python-dsl/buck_parser/buck.py#L2011 includes a byte literal:

{   '__env': {   
        b'PATH': None,
        'PATH': '/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/salt/bin:/usr/local/bin'
      }
}

Note the b'PATH'. I was able to get this printed by adding a pprint as follows: https://github.com/facebook/buck/commit/58d2e1d2c6ae53c14171051dfad881ae1e0e650b

This causes errors like:

[2021-02-18 22:42:44.666][warn ][command:224770f1-54e3-4ad5-a1ec-f024a8a8406e][tid:35][com.facebook.buck.event.listener.LoggingBuildListener] Buck wasn't able to parse /path/to/buck/file/BUCK:
TypeError: keys must be str, int, float, bool or None, not bytes
Call stack:
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)

I think the __env addition comes from https://github.com/facebook/buck/blob/master/python-dsl/buck_parser/buck.py#L1951.

Stackoverflow question that might help with why byte literals are problematic: https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal/6269785

Workaround

My workaround is to just use an older version of BUCK and use python2.7.

navkast avatar Feb 19 '21 04:02 navkast