[devel] [SCM] m/mathomatic/mathomatic.spec
Stanislav Levin
slev на basealt.ru
Чт Ноя 7 23:17:39 MSK 2019
07.11.2019 21:21, Vladimir D. Seleznev пишет:
> ^ Этот способ не работает.
Ниже перечислены изменения сделанные утилитой 2to3 в данном пакете.
--- ./mathomatic/primes/matho-sum 2019-11-07 22:34:48.543068658 +0300
+++ ./matho-sum 2019-11-07 22:42:52.909266580 +0300
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# Python program to sum many large integers separated by spaces or
newlines.
# The integers to sum may be entered on the command-line or into
standard input.
@@ -12,7 +12,7 @@
# read stdin if no command line args
while True:
try:
- input_line = raw_input()
+ input_line = input()
except:
break;
for s in string.split(input_line):
@@ -21,4 +21,4 @@
# sum together the command-line args
for arg in args:
sum += int(arg)
-print sum
+print(sum)
--- ./mathomatic/primes/matho-mult 2019-11-07 22:34:48.543068658 +0300
+++ matho-mult 2019-11-07 22:42:35.634259521 +0300
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# Python program to multiply many large integers separated by spaces or
newlines.
# The integers to multiply may be entered on the command-line or into
standard input.
@@ -15,7 +15,7 @@
# read stdin if no command line args
while True:
try:
- input_line = raw_input()
+ input_line = input()
except:
break;
for s in string.split(input_line):
@@ -24,4 +24,4 @@
# multiply together the command-line args
for arg in args:
prod *= int(arg)
-print prod
+print(prod)
--- ./mathomatic/primes/primorial 2019-11-07 22:34:48.544068659 +0300
+++ primorial 2019-11-07 22:42:58.551268884 +0300
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# This is a Python program to display large primorials.
# A primorial is the product of all primes up to the given number.
@@ -16,11 +16,11 @@
import sys
def usage(ev):
- print "This program calculates large primorials."
- print
- print "Usage: %s integers" % os.path.basename(sys.argv[0])
- print
- print "A primorial is the product of all primes up to the given
number."
+ print("This program calculates large primorials.")
+ print()
+ print("Usage: %s integers" % os.path.basename(sys.argv[0]))
+ print()
+ print("A primorial is the product of all primes up to the given
number.")
sys.exit(ev)
def output_primorial(arg):
@@ -36,9 +36,9 @@
for arg in args:
try:
if (int(arg) < 1):
- print >>sys.stderr, "Number too small."
+ print("Number too small.", file=sys.stderr)
sys.exit(1)
except:
- print >>sys.stderr, "Positive integer required."
+ print("Positive integer required.", file=sys.stderr)
usage(1)
output_primorial(arg)
--- ./mathomatic/examples/factorial 2019-11-07 22:34:48.538068656 +0300
+++ factorial 2019-11-07 22:43:04.379271266 +0300
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# This is a Python program to display large factorials and test "fact.py".
@@ -8,13 +8,13 @@
import string
def usage():
- print "This program calculates large factorials."
- print "Requires and tests \"fact.py\"."
- print
- print "Usage: %s integer_expressions" %
os.path.basename(sys.argv[0])
- print
- print "The integer expressions should be separated by spaces."
- print "A factorial is the product of all positive integers <= a
given integer."
+ print("This program calculates large factorials.")
+ print("Requires and tests \"fact.py\".")
+ print()
+ print("Usage: %s integer_expressions" %
os.path.basename(sys.argv[0]))
+ print()
+ print("The integer expressions should be separated by spaces.")
+ print("A factorial is the product of all positive integers <= a
given integer.")
sys.exit(2)
args = sys.argv[1:]
@@ -23,8 +23,8 @@
else:
try:
num = eval(string.join(args))
- print "factorial(", num, ") =", factorial(num)
+ print("factorial(", num, ") =", factorial(num))
except:
for arg in args:
num = eval(arg)
- print "factorial(", num, ") =", factorial(num)
+ print("factorial(", num, ") =", factorial(num))
Очевидно, что изменения верные.
Можете сравнить их, например, с Fedora:
https://src.fedoraproject.org/rpms/mathomatic/tree/master
Что именно в данном случае не работает?
> 2to3 в большинстве случаев _не_ генерирует рабочий код.
Это утверждение требующее каких-то доказательств.
Список всех багов по 2to3:
https://bugs.python.org/issue?%40search_text=&ignore=file%3Acontent&title=&%40columns=title&id=&%40columns=id&stage=&creation=&creator=&activity=&%40columns=activity&%40sort=activity&actor=&nosy=&type=&components=20&versions=&dependencies=&assignee=&keywords=&priority=&status=&%40columns=status&resolution=&nosy_count=&message_count=&%40group=&%40pagesize=50&%40startwith=0&%40sortdir=on&%40action=search
Да, бывают нюансы. Но бОльшую массу кода трансформирует и трансформирует
в рабочий Python3 код.
> после каждого
> перевода их надо проверять.
Безусловно (если есть понимание изменений), потому что утилита не
охватывает весь функциональный спектр.
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя : signature.asc
Тип : application/pgp-signature
Размер : 833 байтов
Описание: OpenPGP digital signature
Url : <http://lists.altlinux.org/pipermail/devel/attachments/20191107/19983b1c/attachment-0001.bin>
Подробная информация о списке рассылки Devel