antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.22k stars 3.29k forks source link

Getting Started install instructions lead to TimeoutError on WSL2 #4698

Open LanHikari22 opened 1 month ago

LanHikari22 commented 1 month ago

Following the instructions in https://github.com/antlr/antlr4/blob/4.13.2/doc/getting-started.md,

  1. I first created a miniconda environment for antlr and then proceeded with installing antlr4-tools:

    conda create --prefix /home/lan/miniconda3/envs/antlr python=3.11
    conda activate /home/lan/miniconda3/envs/antlr
    python3 -m pip install antlr4-tools
  2. I then attempted to install the java app with

    antlr4

    and that produced the following error log:

    Traceback (most recent call last):
    File "/home/lan/miniconda3/envs/antlr/bin/antlr4", line 8, in <module>
    sys.exit(tool())
             ^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/site-packages/antlr4_tool_runner.py", line 141, in tool
    run_cli('org.antlr.v4.Tool')
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/site-packages/antlr4_tool_runner.py", line 132, in run_cli
    args, version = process_args()
                    ^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/site-packages/antlr4_tool_runner.py", line 126, in process_args
    args.version or os.environ.get("ANTLR4_TOOLS_ANTLR_VERSION") or latest_version()
                                                                    ^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/site-packages/antlr4_tool_runner.py", line 27, in latest_version
    with urlopen(f"https://search.maven.org/solrsearch/select?q=a:antlr4-master+g:org.antlr", timeout=10) as response:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/urllib/request.py", line 1352, in do_open
    r = h.getresponse()
        ^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/http/client.py", line 1395, in getresponse
    response.begin()
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/http/client.py", line 325, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/http/client.py", line 286, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/socket.py", line 706, in readinto
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/ssl.py", line 1314, in recv_into
    return self.read(nbytes, buffer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/lan/miniconda3/envs/antlr/lib/python3.11/ssl.py", line 1166, in read
    return self._sslobj.read(len, buffer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TimeoutError: The read operation timed out

The suspect line is the following:

with urlopen(f"https://search.maven.org/solrsearch/select?q=a:antlr4-master+g:org.antlr", timeout=10) as response:

I am unable to curl nor access this URL in my browser. However, I saw instructions on StackOverflow from user kaby76 (https://stackoverflow.com/q/78059474) to instead run

antlr -v 4.13.1

and that did allow me to acquire the CLI tool:

antlr4 -v 4.13.1
ANTLR Parser Generator  Version 4.13.1
 -o ___              specify output directory where all output is generated
 -lib ___            specify location of grammars, tokens files
 -atn                generate rule augmented transition network diagrams
 -encoding ___       specify grammar file encoding; e.g., euc-jp
 -message-format ___ specify output style for messages in antlr, gnu, vs2005
 -long-messages      show exception details when available for errors and warnings
 -listener           generate parse tree listener (default)
 -no-listener        don't generate parse tree listener
 -visitor            generate parse tree visitor
 -no-visitor         don't generate parse tree visitor (default)
 -package ___        specify a package/namespace for the generated code
 -depend             generate file dependencies
 -D<option>=value    set/override a grammar-level option
 -Werror             treat warnings as errors
 -XdbgST             launch StringTemplate visualizer on generated code
 -XdbgSTWait         wait for STViz to close before continuing
 -Xforce-atn         use the ATN simulator for all predictions
 -Xlog               dump lots of logging info to antlr-timestamp.log
 -Xexact-output-dir  all output goes into -o dir regardless of paths/package

Thanks, Mohammed

kaby76 commented 1 month ago

The address is using the "Official search by the maintainers of [Maven](https://maven.apache.org/) Central Repository". But, I just clicked on "API Guide", then one of the queries, and the page times out. I think the web service is unreliable. It might be best to use https://central.sonatype.com/?smo=true. It has an API.

kaby76 commented 1 month ago
504 ERROR
The request could not be satisfied.
CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
Generated by cloudfront (CloudFront)
Request ID: xGTki_3-jx8ZdW05RJj75iD0N_M_kls3O1UpAEEG1dWcY8qzr_nV2w==

Actually, the sonatype.com website points to the maven.org API. Not much we can do here in so far as using this API. It might be better to just query https://repo1.maven.org/maven2/org/antlr/antlr4/, which appears to be more reliable, and just scan for the latest.

kaby76 commented 1 month ago

Perhaps something like this? (I am not a Python programmer, but it "works".)

def latest_version():
    page = requests.get("https://repo1.maven.org/maven2/org/antlr/antlr4/")
    tree = html.fromstring(page.content)
    x = tree.xpath('//a/text()')
    if '../' in x: x.remove('../')
    if 'maven-metadata.xml' in x: x.remove('maven-metadata.xml')
    if 'maven-metadata.xml.md5' in x: x.remove('maven-metadata.xml.md5')
    if 'maven-metadata.xml.sha1' in x: x.remove('maven-metadata.xml.sha1')
    if 'maven-metadata.xml.sha256' in x: x.remove('maven-metadata.xml.sha256')
    if 'maven-metadata.xml.sha512' in x: x.remove('maven-metadata.xml.sha512')
    cleaned_data = [item.rstrip('/') for item in x]
    cleaned_data.sort(key=Version)
    last_element = cleaned_data[-1]
    return last_element