Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Get Buck working for 3.10
Browse files Browse the repository at this point in the history
Summary:
On 3.10 some `collections` classes have been moved to
`collections.abc` and it causes Buck 1 to crash. This diff fixes those
instances.

Really pex should be upgraded, but I made an attempt and it was very difficult
due to our custom changes to pex.

fbshipit-source-id: fee5798d3b700a4a63c7ff101c0cb7a4146c4589
  • Loading branch information
lisroach authored and facebook-github-bot committed Apr 27, 2022
1 parent 9ad8ecb commit a87b76c
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion scripts/slice_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import argparse
import codecs
import collections
import math
import os

Expand Down
7 changes: 4 additions & 3 deletions third-party/py/pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import io
import os
import errno
Expand All @@ -19,8 +18,10 @@
raise ImportError("unittest2 is required for tests on pre-2.7")

try:
import collections.abc as collections_abc
from test import support
except ImportError:
import collections as collections_abc # Fallback for PY3.2.
from test import test_support as support
TESTFN = support.TESTFN

Expand Down Expand Up @@ -1395,7 +1396,7 @@ def _check(glob, expected):
P = self.cls
p = P(BASE)
it = p.glob("fileA")
self.assertIsInstance(it, collections.Iterator)
self.assertIsInstance(it, collections_abc.Iterator)
_check(it, ["fileA"])
_check(p.glob("fileB"), [])
_check(p.glob("dir*/file*"), ["dirB/fileB", "dirC/fileC"])
Expand All @@ -1420,7 +1421,7 @@ def _check(glob, expected):
P = self.cls
p = P(BASE)
it = p.rglob("fileA")
self.assertIsInstance(it, collections.Iterator)
self.assertIsInstance(it, collections_abc.Iterator)
# XXX cannot test because of symlink loops in the test setup
#_check(it, ["fileA"])
#_check(p.rglob("fileB"), ["dirB/fileB"])
Expand Down
1 change: 1 addition & 0 deletions third-party/py/pex/README.facebook
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Local modifications:
- Make pexes work when being invoked from a version of python without site.USER_SITE
- Fix concurrency when two instances of zip-safe pex invoked D21508334
- Handle EACCES and EPERM in safe_copy
- Imported from collections.abc instead of collections to support Python 3.10
5 changes: 4 additions & 1 deletion third-party/py/pex/pex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

from __future__ import absolute_import

from collections import Iterable
try:
from collections.abc import Iterable
except ImportError: # For PY3.2
from collections import Iterable

from pkg_resources import Requirement

Expand Down
2 changes: 1 addition & 1 deletion third-party/py/pex/pex/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
import posixpath
from collections import Iterable
from collections.abc import Iterable

from .compatibility import string as compatible_string
from .compatibility import PY3
Expand Down
4 changes: 2 additions & 2 deletions third-party/py/pex/pex/orderedset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# modifications
#

import collections
import collections.abc


class OrderedSet(collections.MutableSet):
class OrderedSet(collections.abc.MutableSet):
KEY, PREV, NEXT = range(3)

def __init__(self, iterable=None):
Expand Down
14 changes: 9 additions & 5 deletions third-party/py/pywatchman/pywatchman/pybser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
# no unicode literals

import binascii
import collections
import ctypes
import struct
import sys
Expand All @@ -41,6 +40,11 @@
compat,
)

try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc # Fallback for PY3.2.

BSER_ARRAY = b'\x00'
BSER_OBJECT = b'\x01'
BSER_BYTESTRING = b'\x02'
Expand Down Expand Up @@ -177,8 +181,8 @@ def append_recursive(self, val):
self.ensure_size(needed)
struct.pack_into(b'=cd', self.buf, self.wpos, BSER_REAL, val)
self.wpos += needed
elif isinstance(val, collections.Mapping) and \
isinstance(val, collections.Sized):
elif isinstance(val, collections_abc.Mapping) and \
isinstance(val, collections_abc.Sized):
val_len = len(val)
size = _int_size(val_len)
needed = 2 + size
Expand All @@ -205,8 +209,8 @@ def append_recursive(self, val):
for k, v in iteritems:
self.append_string(k)
self.append_recursive(v)
elif isinstance(val, collections.Iterable) and \
isinstance(val, collections.Sized):
elif isinstance(val, collections_abc.Iterable) and \
isinstance(val, collections_abc.Sized):
val_len = len(val)
size = _int_size(val_len)
needed = 2 + size
Expand Down
1 change: 0 additions & 1 deletion third-party/py/pywatchman/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# no unicode literals

import binascii
import collections
import inspect
import unittest
import os
Expand Down
2 changes: 1 addition & 1 deletion third-party/py/setuptools/README.facebook
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Project URL: https://pypi.python.org/packages/source/s/setuptools/setuptools-18.5.tar.gz#md5=533c868f01169a3085177dffe5e768bb
Version: 18.5
License: PSF or ZPL
Local modifications: kept only pkg_resources & _markerlib modules
Local modifications: kept only pkg_resources & _markerlib modules, made "import symbol" optional to support python 3.10
2 changes: 1 addition & 1 deletion third-party/py/setuptools/pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import functools
import pkgutil
import token
import symbol
import operator
import platform
import collections
Expand All @@ -40,6 +39,7 @@
from pkgutil import get_importer

try:
import symbol
import _imp
except ImportError:
# Python 3.2 compatibility
Expand Down

0 comments on commit a87b76c

Please sign in to comment.