bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pygnulib: Portability fixes


From: Mathieu Lirzin
Subject: pygnulib: Portability fixes
Date: Mon, 25 Sep 2017 21:52:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Hello,

I have checked the "python" branch.

Here is a patch that removes the use of 'enum.Flags' that didn't exist
until python 3.6.  It seems that 'enum' classes are not well supported
with older version too.  So it seems more reasonable to not use them at
all.

>From 84b81d499f2b926c2771ed700b019add7a4b6342 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <address@hidden>
Date: Mon, 25 Sep 2017 21:31:11 +0200
Subject: [PATCH] pygnulib: Don't use Enums

Enums are a recent features of Python.  To maximize portability don't
use them.

* pygnulib/parser.py (CommandLine.Option): Don't inherit from enum.Flag.
* pygnulib/config.py (Option): Likewise.
---
 pygnulib/config.py | 3 +--
 pygnulib/parser.py | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/pygnulib/config.py b/pygnulib/config.py
index 27539b3..0f6d88a 100644
--- a/pygnulib/config.py
+++ b/pygnulib/config.py
@@ -6,7 +6,6 @@
 
 import codecs as _codecs_
 import collections as _collections_
-import enum as _enum_
 import os as _os_
 import re as _re_
 
@@ -22,7 +21,7 @@ def _regex_(regex):
 
 
 
-class Option(_enum_.Flag):
+class Option:
     Obsolete = (1 << 0)
     Tests = (1 << 1)
     CXX = (1 << 2)
diff --git a/pygnulib/parser.py b/pygnulib/parser.py
index 9ac0661..79e7279 100644
--- a/pygnulib/parser.py
+++ b/pygnulib/parser.py
@@ -5,7 +5,6 @@
 
 
 import argparse as _argparse_
-import enum as _enum_
 import os as _os_
 
 from .error import CommandLineError as _CommandLineError_
@@ -875,7 +874,7 @@ class CommandLine:
         return "\n".join(lines).format(program=self.__program)
 
 
-    class Option(_enum_.Flag):
+    class Option:
         """option bitwise flags"""
         DryRun = (1 << 0)
         Symlink = (1 << 1)
-- 
2.9.5

I don't know what the plan is, but I suppose that in the context of
Gnulib it is important to be compatible with Python 2?  

Right now this is not the case.  For example there are some 'print'
syntax that not recognized.  As suggested by [1], the following patch
would make it work:

>From 0bd0d3b7463fb20d8b069ef5b2aebcb96d44eb91 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <address@hidden>
Date: Mon, 25 Sep 2017 21:47:08 +0200
Subject: [PATCH] pygnulib: Support functional print in Python 2

* pygnulib.py: Import 'print_function'.
---
 pygnulib.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pygnulib.py b/pygnulib.py
index 27235d8..2cf39cb 100755
--- a/pygnulib.py
+++ b/pygnulib.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # encoding: UTF-8
 
-
+from __future__ import print_function
 
 import codecs
 import os
-- 
2.9.5

This fix is not sufficient to make the script work with Python 2, but it
is a start.

Thanks.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37

[1] http://www.catb.org/esr/faqs/practical-python-porting/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]