Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

from __future__ in the main file causes SyntaxError #57

Closed
sjincho opened this issue Nov 29, 2017 · 4 comments
Closed

from __future__ in the main file causes SyntaxError #57

sjincho opened this issue Nov 29, 2017 · 4 comments

Comments

@sjincho
Copy link

sjincho commented Nov 29, 2017

If the main python script contains from __future__ import ... statements, running par file causes the following error:

$ ./train.par
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 165, in _run_module_as_main
    mod_name, loader, code, fname = _get_main_module_details(_Error)
  File "/usr/lib/python2.7/runpy.py", line 133, in _get_main_module_details
    return _get_module_details(main_name)
  File "/usr/lib/python2.7/runpy.py", line 119, in _get_module_details
    code = loader.get_code(mod_name)
  File "./train.par/__main__.py", line 74
SyntaxError: from __future__ imports must occur at the beginning of the file

This seems to be due to the boilerplate added by subpar compiler before the __future statements.:

# Boilerplate added by subpar/compiler/python_archive.py
from subpar.runtime import support as _
_.setup(import_roots=[u'__main__', u'six_archive'])
del _
# End boilerplate
@duggelz
Copy link
Contributor

duggelz commented Nov 29, 2017

Can you please link to your exact source code? I have code specifically to handle future imports (

# Find a good place to insert the boilerplate, which is the
) but it's regular expression based, rather than a real parser, so it probably needs a tweak.

See original issue #4

@sjincho
Copy link
Author

sjincho commented Nov 29, 2017

@duggelz
Copy link
Contributor

duggelz commented Nov 29, 2017

Aha, I did not realize that doc comments were allowed before future imports. Should be an easy fix, although I'm travelling so it will be a little while.

Note to self, the documented semantics of future imports: https://docs.python.org/2/reference/simple_stmts.html#future

duggelz pushed a commit that referenced this issue Jan 17, 2018
duggelz pushed a commit that referenced this issue Jan 29, 2018
* Add testcases for module doc comments in main source file.

* Fix handling of module doc comments in main source file

See issue #57

* Fix indentation of regular expression

* Cleanup test name.

See #20
@jarondl
Copy link

jarondl commented Mar 20, 2018

It seems like this was fixed in #67 and can be closed, right?

@duggelz duggelz closed this as completed Mar 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants