facebook / buck

A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
https://buck.build
Apache License 2.0
8.56k stars 1.16k forks source link

Python3 compatibility issue in buck_parser/buck.py #2589

Open navkast opened 3 years ago

navkast commented 3 years ago

Background

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.