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

SyntaxError in asdl when building 2.7 with system Python 3 #60168

Closed
cjerdonek opened this issue Sep 18, 2012 · 24 comments
Closed

SyntaxError in asdl when building 2.7 with system Python 3 #60168

cjerdonek opened this issue Sep 18, 2012 · 24 comments
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@cjerdonek
Copy link
Member

BPO 15964
Nosy @loewis, @ncoghlan, @vstinner, @tiran, @ezio-melotti, @serwy, @cjerdonek
Files
  • issue-15964-1.patch
  • patch_2and3.py
  • patch_2and3_rev1.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-10-08.13:09:22.203>
    created_at = <Date 2012-09-18.14:26:18.797>
    labels = ['easy', 'type-feature', 'docs']
    title = 'SyntaxError in asdl when building 2.7 with system Python 3'
    updated_at = <Date 2013-10-08.13:09:22.202>
    user = 'https://github.com/cjerdonek'

    bugs.python.org fields:

    activity = <Date 2013-10-08.13:09:22.202>
    actor = 'eli.bendersky'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2013-10-08.13:09:22.203>
    closer = 'eli.bendersky'
    components = ['Documentation', 'Devguide']
    creation = <Date 2012-09-18.14:26:18.797>
    creator = 'chris.jerdonek'
    dependencies = []
    files = ['27260', '29677', '29773']
    hgrepos = []
    issue_num = 15964
    keywords = ['patch', 'easy', 'needs review']
    message_count = 24.0
    messages = ['170646', '170682', '170720', '170728', '170729', '170730', '170928', '170991', '170992', '171001', '171018', '171020', '171080', '171081', '171091', '184006', '185662', '185982', '185995', '186507', '186543', '198449', '198770', '198772']
    nosy_count = 11.0
    nosy_names = ['loewis', 'ncoghlan', 'vstinner', 'christian.heimes', 'ezio.melotti', 'roger.serwy', 'Arfrever', 'eli.bendersky', 'chris.jerdonek', 'docs@python', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15964'
    versions = ['Python 2.7']

    @cjerdonek
    Copy link
    Member Author

    Building with--

    ./configure --with-pydebug && make -j2

    errors out after switching branches from default to 2.7 when the system Python is Python 3 (on Mac OS X 10.7.4 using MacPorts).

    To reproduce:

    $ sudo port select python python32
    $ python
    No such file or directory
    $ python3 -V
    Python 3.2.3
    $ hg update default
    $ ./configure --with-pydebug && make -j2
    $ hg update 2.7
    $ cp Modules/Setup.dist Modules/Setup
    $ ./configure --with-pydebug && make -j2
    ...
    config.status: creating pyconfig.h
    config.status: pyconfig.h is unchanged
    creating Modules/Setup
    creating Modules/Setup.local
    creating Makefile
    ./install-sh -c -d Include
    ./Parser/asdl_c.py -h Include ./Parser/Python.asdl
    gcc -c -fno-strict-aliasing -g -O2 -g -O0 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Parser/printgrammar.o Parser/printgrammar.c
    gcc -c -fno-strict-aliasing -g -O2 -g -O0 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Parser/pgenmain.o Parser/pgenmain.c
      File "./Parser/asdl_c.py", line 1
        print "Must specify exactly one output file"
                                                   ^
    SyntaxError: invalid syntax
    make: *** [Include/Python-ast.h] Error 1
    make: *** Waiting for unfinished jobs....

    Running "make distclean" doesn't fix this. Here is one work-around:

    $ sudo port select python python27
    $ ./configure --with-pydebug && make -j2

    Perhaps the right work-around can be documented in the devguide, or maybe this can be addressed another way.

    @cjerdonek cjerdonek added type-bug An unexpected behavior, bug, or error build The build process and cross-build labels Sep 18, 2012
    @tiran
    Copy link
    Member

    tiran commented Sep 18, 2012

    I think this might be related to bpo-15923. It shouldn't be necessary to rebuild the AST definition unless you have modified the grammar and AST files.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 19, 2012

    The case that "python" is a Python 3 binary is not a supported installation (see PEP-394). asdl_c.py works on both 2.x and 3.x unmodified in the 3.x branch, however, backporting this to 2.7 would be a new feature (support for building on systems where "python" is Python 3).

    The proper work-around is to "make touch" after a hg update to bring the files in the right order.

    bpo-15923 is really a separate issue since it complains about an actual bug in asdl_c.py.

    So I propose to close this as "won't fix".

    @cjerdonek
    Copy link
    Member Author

    The case that "python" is a Python 3 binary is not a supported installation

    Just to clarify, in the original scenario, "python" did not refer to anything. From the original comment:

    $ python
    No such file or directory

    ("python2" and "python3" did refer to the respective versions.)

    The proper work-around is to "make touch" after a hg update to bring the files in the right order.

    I had tried this in the 2.7 branch and got:

    $ make touch
    make: *** No rule to make target `touch'.  Stop.

    @tiran
    Copy link
    Member

    tiran commented Sep 19, 2012

    $ make touch
    make: *** No rule to make target `touch'. Stop.

    Martin meant:

    touch Include/Python-ast.h Python/Python-ast.c

    @cjerdonek
    Copy link
    Member Author

    Yes, that works. Rather than closing this as "won't fix," however, I would suggest that we document the workaround in the devguide.

    @cjerdonek
    Copy link
    Member Author

    Switching this to a devguide issue so the work-around can be documented, for example in this section:

    http://docs.python.org/devguide/faq.html#how-do-i-switch-between-branches-inside-my-working-copy

    @cjerdonek cjerdonek added easy docs Documentation in the Doc dir and removed build The build process and cross-build labels Sep 21, 2012
    @cjerdonek cjerdonek added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Sep 21, 2012
    @cjerdonek
    Copy link
    Member Author

    Attaching patch.

    I started a new section in the FAQ called "Build Troubleshooting" which is something Nick suggested in the context of addressing this issue. I'm sure we could add a couple more questions to this section right now if we wanted to.

    @cjerdonek
    Copy link
    Member Author

    Adding Nick because he is the one that suggested adding a "Build Troubleshooting" section to the devguide FAQ (meant to add him above).

    @ncoghlan
    Copy link
    Contributor

    We should be able to add the "make touch" target to the 2.7 Makefile without running afoul of the "no new features" rule.

    However, agreed this is mostly a docs problem. We're seeing a couple of common traps that people run into when first getting started, so it will be good to get answers up somewhere where people are likely to look (and where search engines will be able to see the error messages).

    @cjerdonek
    Copy link
    Member Author

    We should be able to add the "make touch" target to the 2.7 Makefile without running afoul of the "no new features" rule.

    To keep things simpler, I'm going to create a separate issue for this so that it can be discussed and committed independently of this doc-only issue. If necessary, we can always modify the answers to existing FAQ's in that issue.

    @cjerdonek
    Copy link
    Member Author

    We should be able to add the "make touch" target to the 2.7 Makefile without running afoul of the "no new features" rule.

    I created bpo-16004 for this: http://bugs.python.org/issue16004

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 23, 2012

    Martin meant:
    touch Include/Python-ast.h Python/Python-ast.c

    No, I *actually* meant 'make touch'.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 23, 2012

    Just to clarify, in the original scenario, "python" did not refer to
    anything. From the original comment:
    $ python
    No such file or directory

    So can you find out why asdl_c.py actually printed this error? With no python executable in PATH, it shouldn't even run.

    @cjerdonek
    Copy link
    Member Author

    So can you find out why asdl_c.py actually printed this error?

    I collected some additional information. Here is the beginning of Parser/asdl_c.py:

    #! /usr/bin/env python
    """Generate C code from an ASDL description."""

    And in the scenario of this issue I have--

    $ python
    -bash: /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/python: No such file or directory

    But--

    $ /usr/bin/env python -V
    Python 3.2.3

    Some more data:

    $ /usr/bin/env python -c "import sys; print(sys.executable)"
    /opt/local/Library/Frameworks/Python.framework/Versions/3.2/Resources/Python.app/Contents/MacOS/Python
    $ echo $PATH
    /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/texbin
    $ which python
    /opt/local/bin/python
    $ /opt/local/bin/python -c "import sys; print(sys.executable)"
    /opt/local/Library/Frameworks/Python.framework/Versions/3.2/Resources/Python.app/Contents/MacOS/Python

    It's not immediately clear to me why running python doesn't find python in the second $PATH entry even though which python does. Also, creating a new terminal doesn't seem to exhibit the same problem, so the error state may not be fully reproducible after all (at least on my machine).

    In any case, Christian's work-around does resolve the issue for this particular error state while other solutions don't.

    @ezio-melotti
    Copy link
    Member

    make touch is now in 2.7, so the patch should be updated.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Mar 31, 2013

    I use Arch Linux which has /usr/bin/python as 3.3.0. I can confirm that "touch Include/Python-ast.h Python/Python-ast.c" fixes the problem.

    But would it have been simpler just to convert the print statements to functions so that asdl_c.py would work with Python 3 as well as Python 2?

    @ezio-melotti
    Copy link
    Member

    Do you want to provide a patch and test that it works?

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Apr 4, 2013

    The attached patch allows the same parser code to run under Python 2 and Python 3. I'm not sure how to test it other than by running the test suite which passed.

    @ezio-melotti
    Copy link
    Member

    I left a review. To test it you could try to reproduce the steps described in the first message and see what happens.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Apr 11, 2013

    Attached is the updated patch to include Ezio's review. Thanks Ezio!

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Sep 26, 2013

    Did anyone ended up updating the devguide about this? I can't find anything related in there.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 1, 2013

    New changeset 56ed149e597a by Eli Bendersky in branch 'default':
    Mention 'make touch' in the devguide.
    http://hg.python.org/devguide/rev/56ed149e597a

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Oct 1, 2013

    make touch was added to the bots in bpo-19106 and is now also recommended in the devguide for folks running into this problem. IMHO this is all we need here, because there's no point toiling to make the auto-generation scripts in every version to work with any other version of Python. It's error prone and keeps us back (there's no reason not to use modern Python practices in the ASDL generator of 3.4, say, and instead cling to Python 2.4).

    So I'm going to close this issue in a few days unless new feedback emerges.

    @elibendersky elibendersky mannequin closed this as completed Oct 8, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants