Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx 1.8.0 fails build with syntax error unqualified exec is not allowed in function 'run' #5417

Closed
zxiiro opened this issue Sep 12, 2018 · 14 comments

Comments

@zxiiro
Copy link

zxiiro commented Sep 12, 2018

Problem

  • Build fails with syntax error SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables

Procedure to reproduce the problem

tox -e docs

This can be reproduced with docker too.

docker run -it --rm centos:7 /bin/bash

yum install git gcc python-virtualenv
virtualenv /tmp/venv
source /tmp/venv/bin/activate
pip install tox

git clone https://github.com/lfit/releng-lftools
cd releng-lftools
tox -e docs

Error logs / results

Running Sphinx v1.8.0

Exception occurred:
  File "/w/workspace/lf-infra-lftools-tox-verify-any/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py", line 26, in <module>
    from sphinx.ext import doctest
SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
The full traceback has been saved in /tmp/sphinx-err-SIpkyY.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Expected results

Docs successfully builds as it did on the previous release.

Reproducible project / your project

https://github.com/lfit/releng-lftools

Environment info

  • OS: Linux, Cent OS 7
  • Python version: 2.7.5
  • Sphinx version: 1.8.0
  • <Extra tools e.g.: Browser, tex or something else>
@zxiiro
Copy link
Author

zxiiro commented Sep 12, 2018

I posted the logs for one of our projects. But many of our projects that's using Sphinx started failing in our CI this morning with this issue after 1.8.0 was made public.

@tannewt
Copy link

tannewt commented Sep 12, 2018

This happens on Travis as well: https://travis-ci.org/adafruit/circuitpython/jobs/427888642#L1303

@kunicmarko20
Copy link

guits added a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
guits added a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
mergify bot pushed a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 8f2c660)
mergify bot pushed a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 8f2c660)
guits added a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 8f2c660)
guits added a commit to ceph/ceph-ansible that referenced this issue Sep 13, 2018
using sphinx 1.8.0 breaks our doc test CI job.

Typical error:

```
Exception occurred:
  File
  "/home/jenkins-build/build/workspace/ceph-ansible-docs-pull-requests/docs/.tox/docs/lib/python2.7/site-packages/sphinx/highlighting.py",  line 26, in <module>
      from sphinx.ext import doctest
      SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables (doctest.py, line 97)
```

See: sphinx-doc/sphinx#5417

Pinning to 1.7.9 to fix our CI.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 8f2c660)
@tk0miya
Copy link
Member

tk0miya commented Sep 13, 2018

Sorry for inconvenience. This might be related with doctest_global_setup. But I can't find where do you set up config variables on your project. Could you let me know where it is used?

@tk0miya
Copy link
Member

tk0miya commented Sep 13, 2018

Note: The code was added in #5307.
@akaihola Please let me know about the error if you find the reason.

@elafontaine
Copy link

This seems to be caused by the way exec works;
https://stackoverflow.com/questions/4484872/why-doesnt-exec-work-in-a-function-with-a-subfunction

Maybe you guys want to specify the context to exec to avoid that issue. (I don't have the pretention to understand what it means or which context to apply) :) . Just trying to help as I'm impacted as well.

@gillesdouaire
Copy link

Right now we'll use Sphinx !=1.8.0 in our requirements to unblock-- so we'll use 1.7.9 for the time being, and then 1.8.1 as soon as it's out.

binji added a commit to WebAssembly/spec that referenced this issue Sep 13, 2018
binji added a commit to WebAssembly/spec that referenced this issue Sep 13, 2018
loicalbertin added a commit to ystia/yorc-a4c-plugin that referenced this issue Sep 14, 2018
cas-- added a commit to cas--/Deluge that referenced this issue Sep 14, 2018
benoit-pierre added a commit to benoit-pierre/setuptools that referenced this issue Sep 14, 2018
Pin Sphinx to 1.7.9 until sphinx-doc/sphinx#5417 is fixed.
benoit-pierre added a commit to benoit-pierre/setuptools that referenced this issue Sep 14, 2018
Pin Sphinx to 1.7.9 until sphinx-doc/sphinx#5417 is fixed.
benoit-pierre added a commit to benoit-pierre/setuptools that referenced this issue Sep 14, 2018
@akaihola
Copy link
Contributor

@tk0miya, the failing tests above seem to have been run on Python 2.7.5. Sphinx 1.8.0 only supports Python >=3.5.

I tried this minimal test case to see differences in behavior between Python versions:

def func():
    context = {}
    exec('print("hi")', context)

    def inner():
        return None

func()
  • with Python 2.6.9, this fails in the same way as the test mentioned above
  • with Python 2.7.15, it succeeds (strangely enough)
  • with Python 3.5.5, 3.6.5 and 3.7.0b4, it succeeds

I'll try to build Python 2.7.5 to see if there really is a difference between 2.7.5 and 2.7.15.

On Python 2.6, changing the exec line to:

exec 'print("hi")' in context

fixes the problem, but is not valid in Python 3.x.

What still baffles me is that the TestDirective.run() method doesn't actually have inner functions!

Anyway, if it's true that this doesn't fail on any Python version >=3.5, do we still want to try and fix compatibility on Python <3.5?

@tk0miya
Copy link
Member

tk0miya commented Sep 16, 2018

@akaihola No, Sphinx-1.8 has still supported python 2.7. So we should make a fix for both py27 and py34+

@tk0miya
Copy link
Member

tk0miya commented Sep 16, 2018

I confirmed with following Dockerfile:

FROM centos:7

RUN yum install -y git gcc epel-release
RUN yum install -y python-pip
RUN git clone https://github.com/lfit/releng-lftools
RUN pip install tox
WORKDIR /releng-lftools
RUN yum install -y python-devel
RUN tox -e docs --notest
RUN .tox/docs/bin/pip install -U Sphinx
RUN tox -e docs

@tk0miya
Copy link
Member

tk0miya commented Sep 16, 2018

Finally, I found the reason of the error. It seems list comprehension conflicts with exec under py2.7.5.

[root@0c85e272ba90 releng-lftools]# python -V
Python 2.7.5
[root@0c85e272ba90 releng-lftools]# cat test.py
def func():
    exec('print("h1")', {})
    (str(e) for e in range(10))
[root@0c85e272ba90 releng-lftools]# python test.py
  File "test.py", line 2
    exec('print("h1")', {})
SyntaxError: unqualified exec is not allowed in function 'func' it contains a nested function with free variables

And it is already resolved at latest python2.7.

$ python2.7 -V
Python 2.7.15
$ cat test.py
def func():
    exec('print("h1")', {})
    (str(e) for e in range(10))
$ python2.7 test.py
$

@tk0miya
Copy link
Member

tk0miya commented Sep 16, 2018

I confirmed #5443 fixes the problem:

FROM centos:7

RUN yum install -y git gcc epel-release
RUN yum install -y python-pip
RUN git clone https://github.com/lfit/releng-lftools
RUN pip install tox
WORKDIR /releng-lftools
RUN yum install -y python-devel
RUN tox -e docs --notest
RUN .tox/docs/bin/pip install -U git+https://github.com/tk0miya/sphinx@5417_crashed_with_py275
RUN tox -e docs

@elafontaine
Copy link

I think #5443 would be a simple fix to merge! The change is not that big and will resolve the issue :).

Thanks a lot @tk0miya for looking into this. It will make sphinx be able to be updated on old version of redhat as well.

jaraco added a commit to pypa/setuptools that referenced this issue Sep 16, 2018
jaraco added a commit to pypa/setuptools that referenced this issue Sep 16, 2018
tk0miya added a commit that referenced this issue Sep 16, 2018
Fix #5417: Sphinx fails to build with syntax error in Python 2.7.5
@tk0miya
Copy link
Member

tk0miya commented Sep 16, 2018

Fixed by #5443.
Thank you for reporting.

@tk0miya tk0miya closed this as completed Sep 16, 2018
jrprice added a commit to talvos/talvos that referenced this issue Sep 18, 2018
Temporary workaround for this Sphinx issue:
sphinx-doc/sphinx#5417
vovkos added a commit to vovkos/doxyrest that referenced this issue Sep 19, 2018
jodal added a commit to mopidy/mopidy that referenced this issue Sep 19, 2018
clrpackages pushed a commit to clearlinux-pkgs/setuptools that referenced this issue Sep 20, 2018
…uild_meta`` sdist directory argument to point to the same target (meaning the build frontend no longer needs to clean manually the dist dir to avoid multiple sdist presence, and setuptools no longer needs to handle conflicts between the two).

Alexander Duryagin (6):
      always process module.__path__ for namespace packages, fixes #1321
      added changelog.d entry
      xfail namespace packages tests on appveyor instead of skipping them
      change formatting to fix flake8 warning
      remove xfail for namespace tests that actually pass in AppVeyor
      remove xfail for AppVeyor from namespace tests entirely

Bernat Gabor (4):
      build_meta.get_requires_for_build_sdist does not include wheel
      build_meta sdist directory delegate to --dist-dir
      Add tests exposing the issues with sdist_directory not being --dist-dir
      add changelog for #1481

Christian González (1):
      link to setuptools doc

Jason R. Coombs (36):
      Reindent to avoid hanging indent.
      Delint
      Use unicode literals in test_easy_install.
      Delint
      Remove extraneous v
      Assign on separate lines
      Rely on rpartition.
      Suppress warnings in importer.find_module. Fixes #1111.
      Merge pull request #1489 from nerdoc/patch-1
      Merge pull request #1479 from jdufresne/bytes
      Add Tidelift badge to readme
      Merge pull request #1486 from pypa/bugfix/1111-import-warning
      Configure readthedocs with a .yml file
      Merge pull request #1477 from gaborbernat/no-sdist-wheel
      Merge ancient easy_install history into changelog
      Remove backwards compatibility notes and future plans from Easy Install docs
      Update Easy Install docs reflecting the deprecation.
      Pin against sphinx 1.8.0 due to sphinx-doc/sphinx#5417.
      Fix broken reference to setuptools docs
      Fix other broken references due to moving changelog
      Merge pull request #1490 from pypa/bugfix/sphinx/5417
      Merge pull request #1427 from stephenfin/touch-egg-info-directory
      Update changelog
      Merge pull request #1324 from torsava/safe_name
      Merge pull request #1402 from daa/pkg-resources-always-handle-namespace-package-path
      Minor reword
      Add periods to changelog entries
      Revert "Make safe_name compliant to PEP 503 and behaviour of pip > 8.1.2"
      Merge pull request #1491 from pypa/revert-1324-safe_name
      Bump version: 40.2.0 → 40.3.0
      wordsmith changelog
      Merge pull request #1481 from gaborbernat/sdist-dir
      Bump version: 40.3.0 → 40.4.0
      Update pavement not to import pip
      Bump to pyparsing 2.2.1 and re-run paver update_vendored. Fixes #1480.
      Bump version: 40.4.0 → 40.4.1

Jon Dufresne (2):
      Add tests for setuptools.glob
      Remove use of compatibility shim six.binary_type

Stephen Finucane (3):
      gitignore: Ignore .venv directory
      trivial: Fix file permissions
      egg_info: Touch 'egg-info' directory

Tomas Orsava (1):
      Make safe_name compliant to PEP 503 and behaviour of pip > 8.1.2

v40.4.1
-------

* #1480: Bump vendored pyparsing to 2.2.1.

v40.4.0
-------

* #1481: Join the sdist ``--dist-dir`` and the ``build_meta`` sdist directory argument to point to the same target (meaning the build frontend no longer needs to clean manually the dist dir to avoid multiple sdist presence, and setuptools no longer needs to handle conflicts between the two).

v40.3.0
-------

(NEWS truncated at 15 lines)
charman added a commit to hltcoe/concrete-python that referenced this issue Feb 28, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants