ReFirmLabs / binwalk

Firmware Analysis Tool
MIT License
11.42k stars 1.57k forks source link

Docker image fails to build with Python 3.10 #591

Closed JElchison closed 2 months ago

JElchison commented 2 years ago

I'm trying to build the binwalk Docker image, and it seems to be failing:

$ sudo docker build -t binwalk https://github.com/ReFirmLabs/binwalk.git
Sending build context to Docker daemon  49.89MB
Step 1/13 : FROM python:3-buster AS build-and-install
 ---> 9fb898c38240
Step 2/13 : ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/src/app/bin     DEBIAN_FRONTEND=noninteractive
 ---> Using cache
 ---> 2dcdf7235932
Step 3/13 : COPY . /tmp
 ---> Using cache
 ---> a54f21c91897
Step 4/13 : WORKDIR /tmp
 ---> Using cache
 ---> f4c1f945cd2f
Step 5/13 : RUN set -xue     && apt-get update -qy     && apt-get -t buster dist-upgrade -yq --no-install-recommends -o Dpkg::Options::="--force-confold"     && ./deps.sh --yes     && python3 setup.py install && binwalk -h > /dev/null     && apt-get -yq purge *-dev git build-essential gcc g++     && apt-get -y autoremove     && apt-get -y autoclean     && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen     && echo "LANG=en_US.UTF-8" >> /etc/default/locale     && echo "LANGUAGE=en_US:en" >> /etc/default/locale     && echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale     && locale-gen
 ---> Using cache
 ---> 6ba603d19180
Step 6/13 : FROM build-and-install AS unit-tests
 ---> 6ba603d19180
Step 7/13 : RUN pip install coverage nose     && python3 setup.py test     && dd if=/dev/urandom of=/tmp/random.bin bs=1M count=1 && binwalk -J -E /tmp/random.bin
 ---> Running in 0994d1bfcc2e
Collecting coverage
  Downloading coverage-6.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (215 kB)
Collecting nose
  Downloading nose-1.3.7-py3-none-any.whl (154 kB)
Installing collected packages: nose, coverage
Successfully installed coverage-6.2 nose-1.3.7
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
running test
Traceback (most recent call last):
  File "/tmp/setup.py", line 330, in <module>
    setup(
  File "/usr/local/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.10/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/lib/python3.10/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.10/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/tmp/setup.py", line 302, in run
    retval = nose.core.run(argv=['--exe','--with-coverage'])
  File "/usr/local/lib/python3.10/site-packages/nose/core.py", line 301, in run
    return TestProgram(*arg, **kw).success
  File "/usr/local/lib/python3.10/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "/usr/local/lib/python3.10/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/usr/local/lib/python3.10/site-packages/nose/core.py", line 179, in parseArgs
    self.createTests()
  File "/usr/local/lib/python3.10/site-packages/nose/core.py", line 193, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames)
  File "/usr/local/lib/python3.10/site-packages/nose/loader.py", line 481, in loadTestsFromNames
    return unittest.TestLoader.loadTestsFromNames(self, names, module)
  File "/usr/local/lib/python3.10/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/local/lib/python3.10/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/local/lib/python3.10/site-packages/nose/loader.py", line 454, in loadTestsFromName
    return LazySuite(
  File "/usr/local/lib/python3.10/site-packages/nose/suite.py", line 53, in __init__
    super(LazySuite, self).__init__()
  File "/usr/local/lib/python3.10/unittest/suite.py", line 22, in __init__
    self._tests = []
  File "/usr/local/lib/python3.10/site-packages/nose/suite.py", line 106, in _set_tests
    if isinstance(tests, collections.Callable) and not is_suite:
AttributeError: module 'collections' has no attribute 'Callable'
The command '/bin/sh -c pip install coverage nose     && python3 setup.py test     && dd if=/dev/urandom of=/tmp/random.bin bs=1M count=1 && binwalk -J -E /tmp/random.bin' returned a non-zero code: 1

This appears to be an issue brought on by Python 3.10, in which the deprecated aliases to Collections Abstract Base Classes from the collections module were removed.

I believe the bug should be fixed in the upstream nose library, but it appears to be unmaintained. :-/

-- EDIT 1/20 for typo

akx commented 1 year ago

FWIW, my PR #454 switches tests to use pytest instead, which is very much maintained.