Skip to content

Python3: fix remaining syntax errors found by py2exe - #9719

Merged
michaelDCurran merged 6 commits into
threshold_py3_stagingfrom
py3_syntax
Jun 12, 2019
Merged

Python3: fix remaining syntax errors found by py2exe#9719
michaelDCurran merged 6 commits into
threshold_py3_stagingfrom
py3_syntax

Conversation

@michaelDCurran

Copy link
Copy Markdown
Member

Link to issue number:

None.

Summary of the issue:

When running py2exe over the codebase, it found some syntax errors and one missing module.

Description of how this pull request fixes the issue:

Fixes all remaining syntax errors:

  • tuples in a for loop need to be in brackets.
  • One file had inconsistant whitepsace where there was a space at the beginning of a line before tabbed indentation.
  • numbers no longer need or can have an 'L' suffix at the end.
  • the 'ur' string prefix is no longer supported. Use 'r' instead. Note this was taken from draft pr Python 3: 'ur' string prefixes no longer supported. #9636 plus further strings missed by that pr.
  • Several strings containing backslashes did not have an 'r' prefix when they should have.
  • collections.Sequence is now collections.abc.Sequence.
  • raise excType,value,traceback is no longer valid syntax. Changed the one place we did this to just hold and raise the original exception object, as Python3 now includes the traceback on the exception object itself.

Testing performed:

Py2exe successfully parsed all modules in the codebase.

Known issues with pull request:

Py2exe still fails later on, unrelated to these syntax errors. See my next comment.

Change log entry:

None.

@michaelDCurran

michaelDCurran commented Jun 12, 2019

Copy link
Copy Markdown
Member Author

Py2exe still fails later on when copying py2exe/pywintypes37.dll.
It throws an assertion error because although the module has a __file__, attribute, its file extension is not one of the accepted python extensions. Rather it is .dll.
I'm not sure if this is a bug in py2exe... @LeonarddeR or @albertosottile ?
I saw that it was pywintypes37.dll by adding

print(mod.__file__)

directly above the assertion.
Full traceback follows:

Traceback (most recent call last):
  File "setup.py", line 231, in <module>
    + getRecursiveDataFiles('documentation', '../user_docs', excludes=('*.t2t', '*.t2tconf', '*/developerGuide.*'))
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\setuptools\__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "C:\Program Files (x86)\Python37-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Program Files (x86)\Python37-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Program Files (x86)\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 104, in run
    super(py2exe, self).run()
  File "C:\Users\mick\programming\git\nvda\include\py2exe\py2exe\distutils_buildexe.py", line 192, in run
    self._run()
  File "C:\Users\mick\programming\git\nvda\include\py2exe\py2exe\distutils_buildexe.py", line 273, in _run
    builder.build()
  File "C:\Users\mick\programming\git\nvda\include\py2exe\py2exe\runtime.py", line 264, in build
    self.copy_files(destdir)
  File "C:\Users\mick\programming\git\nvda\include\py2exe\py2exe\runtime.py", line 508, in copy_files
    assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])
AssertionError

@LeonarddeR

LeonarddeR commented Jun 12, 2019 via email

Copy link
Copy Markdown
Collaborator

@LeonarddeR

Copy link
Copy Markdown
Collaborator

See #9711 and #9701

Comment thread source/NVDAObjects/__init__.py Outdated
oldTime=getattr(self,'_basicTextTime',0)
if newTime-oldTime>0.5:
self._basicText=u" ".join([x for x in self.name, self.value, self.description if isinstance(x, basestring) and len(x) > 0 and not x.isspace()])
self._basicText=u" ".join([x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace()])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list (square) brackets were actually a part of this old syntax and can be removed. Also note that basestring is still in here, but that will probably be handled in a later stage?

Suggested change
self._basicText=u" ".join([x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace()])
self._basicText=u" ".join(x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace())

Comment thread source/baseObject.py Outdated
d=dict.get('_del_%s'%x,None)
if x in dict:
methodsString=",".join([str(i) for i in g,s,d if i])
methodsString=",".join([str(i) for i in (g,s,d) if i])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Square brackets can be removed

Comment thread source/logHandler.py Outdated
if className:
break
return ".".join([x for x in path,className,funcName if x])
return ".".join([x for x in (path,className,funcName) if x])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets can be removed

Comment thread source/test_traceback.py Outdated
@@ -0,0 +1,18 @@
import sys

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting stuff ;)

Comment thread source/watchdog.py Outdated
exc = self._exc_info
if exc:
raise exc[0], exc[1], exc[2]
# The execution of the function in the other thread cuased an exception.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuased > caused

Comment thread source/watchdog.py Outdated
# Re-raise it here.
# Note that in Python3, the traceback (stack) is now part of the exception,
# So the logged traceback will correctly show the stack for both this thread and the other thread.
raise e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this e coming from? Shouldn't this be exc?

@michaelDCurran

Copy link
Copy Markdown
Member Author

@LeonarddeR I believe I have addressed your review comments. Changes of basestring etc are coming in a separate pr very soon.
I have removed the accidentally committed test_traceback.py ;) but at least you got to see how I confirmed how Python3 exceptions work.

@michaelDCurran

Copy link
Copy Markdown
Member Author

setup.py now excludes win32api (which we don't need), so it gets around the possible bug when trying to include pywintypes37.dll.

Comment thread source/setup.py Outdated
"serial.serialposix",
"serial.socket_connection",
# Py2exe seems to implicitly include this, but we don't need it.
"win32api",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really like to know why this was included.

Also note the following lines from the output:

Copy d:\Development\NVDA\source repo\include\py2exe\win32wnet.pyd to D:\Development\NVDA\source repo\dist\win32wnet.pyd
Copy d:\Development\NVDA\source repo\include\py2exe\_winxptheme.pyd to D:\Development\NVDA\source repo\dist\_winxptheme.pyd
Copy ExtensionDLL d:\Development\NVDA\source repo\include\py2exe\pywintypes37.dll to D:\Development\NVDA\source repo\dist\

These 3 files are all pywin32. We also have the following files in library.zip:

  • win32wnet.pyc
  • winxptheme.pyc
  • _winxptheme.pyc

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Small additional detail. A non public application I wrote and converted to py2exe lately does not contain all these modules. So I really have the feeling that there is a reference in our code we aren't currently aware of.

@michaelDCurran

michaelDCurran commented Jun 12, 2019 via email

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants