Bug#937262: Help needed (Was: pdb2pqr: Python2 removal in sid/bullseye)

2019-12-13 Thread Andrey Rahmatullin
On Fri, Dec 13, 2019 at 10:10:03PM +0100, Andreas Tille wrote:
> i$ pdb2pqr
> Traceback (most recent call last):
>   File "/usr/bin/pdb2pqr", line 52, in 
> from main import mainCommand
>   File "/usr/share/pdb2pqr/main.py", line 77, in 
> import extensions
>   File "/usr/share/pdb2pqr/extensions/__init__.py", line 56, in 
> extDict[extName] = __import__(extName,globals(),locals(),[], -1)
> ValueError: level must be >= 0

"""
level specifies whether to use absolute or relative imports. The default
is -1 which indicates both absolute and relative imports will be
attempted. 0 means only perform absolute imports.  Positive values for
level indicate the number of parent directories to search relative to the
directory of the module calling __import__().
"""
https://docs.python.org/2.7/library/functions.html#__import__

-1 was removed in 3.3 as implicit relative import are not supported in
3.x. As this code seems to use relative imports you need to change -1 to
1.

> So I tried:
> 
> --- a/extensions/__init__.py
> +++ b/extensions/__init__.py
> @@ -53,7 +53,7 @@ _extList = [name for _, name, _ in 
> pkgutil.iter_modules(__path__)]
>  extDict = {}
>  
>  for extName in _extList:
> -extDict[extName] = __import__(extName,globals(),locals(),[], -1)
> +extDict[extName] = __import__(extName,globals(),locals(),[], 0)^M

Mindlessly changing the code is almost always a bad idea...

>   File "/usr/share/pdb2pqr/extensions/__init__.py", line 57, in 
> extDict[extName] = __import__(extName,globals(),locals(),[], 0)
> ModuleNotFoundError: No module named 'chi'
This is expected as it now tries to do "import chi". With 1 it should try
"from . import chi". This fails later, as the source also has implicit
relative imports that needs to be fixed, for example "from aconf import"
in src/utilities.py.

-- 
WBR, wRAR


signature.asc
Description: PGP signature


Bug#937262: Help needed (Was: pdb2pqr: Python2 removal in sid/bullseye)

2019-12-13 Thread Andreas Tille
On Fri, Dec 13, 2019 at 10:49:45PM +0500, Andrey Rahmatullin wrote:
> > I think at least this is solved now:
> > 
> >
> > https://salsa.debian.org/med-team/pdb2pqr/commit/1f4ee901456641140ef18ca8e91e4701e1175410
> 
> Nice catch, "env.Append(LIBS=[python_lib])" where "python_lib = 'python' +
> gcv('VERSION')" is definitely the cause.

Yes.  I've now a state where the package builds and installs.  However,
just calling pdb2pqr fails with

i$ pdb2pqr
Traceback (most recent call last):
  File "/usr/bin/pdb2pqr", line 52, in 
from main import mainCommand
  File "/usr/share/pdb2pqr/main.py", line 77, in 
import extensions
  File "/usr/share/pdb2pqr/extensions/__init__.py", line 56, in 
extDict[extName] = __import__(extName,globals(),locals(),[], -1)
ValueError: level must be >= 0


So I tried:

--- a/extensions/__init__.py
+++ b/extensions/__init__.py
@@ -53,7 +53,7 @@ _extList = [name for _, name, _ in 
pkgutil.iter_modules(__path__)]
 extDict = {}
 
 for extName in _extList:
-extDict[extName] = __import__(extName,globals(),locals(),[], -1)
+extDict[extName] = __import__(extName,globals(),locals(),[], 0)^M
 
 def setupExtensionsOptions(parser):
 """


which leads to:

$ pdb2pqr
Traceback (most recent call last):
  File "/usr/bin/pdb2pqr", line 52, in 
from main import mainCommand
  File "/usr/share/pdb2pqr/main.py", line 77, in 
import extensions
  File "/usr/share/pdb2pqr/extensions/__init__.py", line 57, in 
extDict[extName] = __import__(extName,globals(),locals(),[], 0)
ModuleNotFoundError: No module named 'chi'


I admit I have no clue whether my change was valid nor what to try next.

Kind regards

   Andreas.

-- 
http://fam-tille.de



Bug#937262: Help needed (Was: pdb2pqr: Python2 removal in sid/bullseye)

2019-12-12 Thread Scott Talbert

On Thu, 12 Dec 2019, Andreas Tille wrote:


Control: tags -1 help

Hi,

it seems pdb2pqr is orphaned upstream.  However, it seems to be worth
keeping inside Debian thus I tried my luck to port it to Python3 in
Git[1].  Unfortunately the build runs into

 scons: Building targets ...
 CopySubAction("pdb2pqr.py", "pdb2pqr.py.in")
 scons: *** [pdb2pqr.py] TypeError : a bytes-like object is required, not 
'str'
 Traceback (most recent call last):
   File "/usr/lib/scons/SCons/Action.py", line 1209, in execute
 result = self.execfunction(target=target, source=rsources, env=env)
   File "/usr/lib/scons/SCons/Action.py", line 1371, in __call__
 return self.parent.actfunc(*args, **kw)
   File "./site_scons/site_init.py", line 123, in CopySubAction
 contents = contents.replace(k, v)
 TypeError: a bytes-like object is required, not 'str'
 scons: building terminated because of errors.

I wonder whether it might just be a scons issue.  Please note that I'm
using scons 3.1.1-4 from experimental that is supposed to run with
Python3.

Any hint would be welcome.

Kind regards

  Andreas.


[1] https://salsa.debian.org/med-team/pdb2pqr


I don't see any Python3 changes in that repository.  Did you push your 
changes?


Anyway, the problem is likely in CopySubAction in site_scons/site_init.py.

On line 111, the file 'sourcefile' is opened as binary.  Then, when then 
next line, 'contents = r.read()' is executed, contents ends up as a bytes 
object.  Thus on line 123, when 'contents = contents.replace(k, v)' is 
executed, contents is a bytes object, whereas k and v are strings.  You 
can't mix strings and bytes objects like that in Python 3.


You could perhaps try opening the file as a text file instead (remove the 
'b') from the open function call.


Scott



Bug#937262: Help needed (Was: pdb2pqr: Python2 removal in sid/bullseye)

2019-12-12 Thread Andreas Tille
Control: tags -1 help

Hi,

it seems pdb2pqr is orphaned upstream.  However, it seems to be worth
keeping inside Debian thus I tried my luck to port it to Python3 in
Git[1].  Unfortunately the build runs into

  scons: Building targets ...
  CopySubAction("pdb2pqr.py", "pdb2pqr.py.in")
  scons: *** [pdb2pqr.py] TypeError : a bytes-like object is required, not 
'str'
  Traceback (most recent call last):
File "/usr/lib/scons/SCons/Action.py", line 1209, in execute
  result = self.execfunction(target=target, source=rsources, env=env)
File "/usr/lib/scons/SCons/Action.py", line 1371, in __call__
  return self.parent.actfunc(*args, **kw)
File "./site_scons/site_init.py", line 123, in CopySubAction
  contents = contents.replace(k, v)
  TypeError: a bytes-like object is required, not 'str'
  scons: building terminated because of errors.

I wonder whether it might just be a scons issue.  Please note that I'm
using scons 3.1.1-4 from experimental that is supposed to run with
Python3.

Any hint would be welcome.

Kind regards

   Andreas.


[1] https://salsa.debian.org/med-team/pdb2pqr

-- 
http://fam-tille.de