Skip to content

Commit

Permalink
python3-nose: translate to python3 code before build
Browse files Browse the repository at this point in the history
Setuptools has removed support for 2to3 during builds since version
58[1]. But the nose's setup.py relies on use_2to3 option in setuptools,
it is failing an import and building without running 2to3 and generating
valid python3 code. As a workaround, we use command line 2to3 tool to
translate to Python3 code before build it.

Fixes:
$ python3
>>> import nose
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/site-packages/nose/_init_.py", line 1, in <module>
from nose.core import collector, main, run, run_exit, runmodule
File "/usr/lib/python3.10/site-packages/nose/core.py", line 153
print "%s version %s" % (os.path.basename(sys.argv[0]), _version_)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
>>>

[1] pypa/setuptools#2086

(From OE-Core rev: 11214c2de3282acb3a0fd28884d1a9c54c1c284a)

Signed-off-by: Yi Zhao <[email protected]>
Signed-off-by: Richard Purdie <[email protected]>
  • Loading branch information
yizhao1 authored and rpurdie committed Nov 8, 2021
1 parent dd9e149 commit 97b6287
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions meta/recipes-devtools/python/python-nose.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SECTION = "devel/python"
LICENSE = "LGPLv2.1"
LIC_FILES_CHKSUM = "file://lgpl.txt;md5=a6f89e2100d9b6cdffcea4f398e37343"

SRC_URI += "file://0001-Remove-use_2to3.patch"

SRC_URI[md5sum] = "4d3ad0ff07b61373d2cefc89c5d0b20b"
SRC_URI[sha256sum] = "f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98"

Expand All @@ -15,4 +17,8 @@ RDEPENDS:${PN} = "\
${PYTHON_PN}-unittest \
"

do_compile:prepend() {
2to3 --write --nobackups --no-diffs ${S}
}

BBCLASSEXTEND = "native nativesdk"
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
From 4307868e31065c56456ddbf03325fc03643cd33f Mon Sep 17 00:00:00 2001
From: Yi Zhao <[email protected]>
Date: Fri, 5 Nov 2021 10:12:16 +0800
Subject: [PATCH] Remove use_2to3

Since version 58, setuptools removed support for 2to3 during builds.

Upstream-Status: Pending

Signed-off-by: Yi Zhao <[email protected]>
---
setup.py | 3 +--
setup3lib.py | 7 +------
2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index a2091c0..7e01bba 100644
--- a/setup.py
+++ b/setup.py
@@ -13,8 +13,7 @@ if sys.version_info >= (3,):
from distribute_setup import use_setuptools
use_setuptools()

- extra = {'use_2to3': True,
- 'test_dirs': test_dirs,
+ extra = {'test_dirs': test_dirs,
'test_build_dir': 'build/tests',
'pyversion_patching': True,
}
diff --git a/setup3lib.py b/setup3lib.py
index 27bdb93..761b74f 100644
--- a/setup3lib.py
+++ b/setup3lib.py
@@ -18,7 +18,6 @@ else:
import logging
from setuptools import Distribution as _Distribution
from distutils.core import Command
- from setuptools.command.build_py import Mixin2to3
from distutils import dir_util, file_util, log
import setuptools.command.test
from pkg_resources import normalize_path
@@ -68,7 +67,7 @@ else:
self.pyversion_patching = False
_Distribution.__init__(self, attrs)

- class BuildTestsCommand (Command, Mixin2to3):
+ class BuildTestsCommand (Command):
# Create mirror copy of tests, convert all .py files using 2to3
user_options = []

@@ -83,7 +82,6 @@ else:
self.test_base = test_base

def run(self):
- use_2to3 = getattr(self.distribution, 'use_2to3', False)
test_dirs = getattr(self.distribution, 'test_dirs', [])
test_base = self.test_base
bpy_cmd = self.get_finalized_command("build_py")
@@ -112,9 +110,6 @@ else:
if fn.endswith(ext):
doc_modified.append(dstfile)
break
- if use_2to3:
- self.run_2to3(py_modified)
- self.run_2to3(doc_modified, True)
if self.distribution.pyversion_patching:
if patch is not None:
for file in modified:
--
2.17.1

0 comments on commit 97b6287

Please sign in to comment.