#!/usr/bin/env python
# Copyright 2017 the authors.
# This file is part of Hy, which is free software licensed under the Expat
# license. See the LICENSE.

import sys, os

from setuptools import find_packages, setup
from setuptools.command.install import install

from get_version import __version__

os.chdir(os.path.split(os.path.abspath(__file__))[0])

PKG = "hy"

long_description = """Hy is a Python <--> Lisp layer. It helps
make things work nicer, and lets Python and the Hy lisp variant play
nice together. """

class Install(install):
    def run(self):
        # Import each Hy module to ensure it's compiled.
        import os, importlib
        for dirpath, _, filenames in sorted(os.walk("hy")):
            for filename in sorted(filenames):
                if filename.endswith(".hy"):
                    importlib.import_module(
                        dirpath.replace("/", ".").replace("\\", ".") +
                        "." + filename[:-len(".hy")])
        install.run(self)

install_requires = ['rply>=0.7.0', 'astor>=0.5', 'clint>=0.4']
if os.name == 'nt':
    install_requires.append('pyreadline>=2.1')

ver = sys.version_info[0]

setup(
    name=PKG,
    version=__version__,
    install_requires=install_requires,
    cmdclass=dict(install=Install),
    entry_points={
        'console_scripts': [
            'hy = hy.cmdline:hy_main',
            'hy%d = hy.cmdline:hy_main' % ver,
            'hyc = hy.cmdline:hyc_main',
            'hyc%d = hy.cmdline:hyc_main' % ver,
            'hy2py = hy.cmdline:hy2py_main',
            'hy2py%d = hy.cmdline:hy2py_main' % ver,
        ]
    },
    packages=find_packages(exclude=['tests*']),
    package_data={
        'hy.contrib': ['*.hy', '__pycache__/*'],
        'hy.core': ['*.hy', '__pycache__/*'],
        'hy.extra': ['*.hy', '__pycache__/*'],
    },
    data_files=[
        ('get_version', ['get_version.py'])
    ],
    author="Paul Tagliamonte",
    author_email="tag@pault.ag",
    long_description=long_description,
    description='Lisp and Python love each other.',
    license="Expat",
    url="http://hylang.org/",
    platforms=['any'],
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        "License :: DFSG approved",
        "License :: OSI Approved :: MIT License",  # Really "Expat". Ugh.
        "Operating System :: OS Independent",
        "Programming Language :: Lisp",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.3",
        "Programming Language :: Python :: 3.4",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Topic :: Software Development :: Code Generators",
        "Topic :: Software Development :: Compilers",
        "Topic :: Software Development :: Libraries",
    ]
)

setup.py
#!/usr/bin/env python
# Copyright 2017 the authors.
# This file is part of Hy, which is free software licensed under the Expat
# license. See the LICENSE.

import sys, os

from setuptools import find_packages, setup
from setuptools.command.install import install

from get_version import __version__

os.chdir(os.path.split(os.path.abspath(__file__))[0])

PKG = "hy"

long_description = """Hy is a Python <--> Lisp layer. It helps
make things work nicer, and lets Python and the Hy lisp variant play
nice together. """

class Install(install):
    def run(self):
        # Import each Hy module to ensure it's compiled.
        import os, importlib
        for dirpath, _, filenames in sorted(os.walk("hy")):
            for filename in sorted(filenames):
                if filename.endswith(".hy"):
                    importlib.import_module(
                        dirpath.replace("/", ".").replace("\\", ".") +
                        "." + filename[:-len(".hy")])
        install.run(self)

install_requires = ['rply>=0.7.5', 'astor>=0.5', 'clint>=0.4']
if os.name == 'nt':
    install_requires.append('pyreadline>=2.1')

ver = sys.version_info[0]

setup(
    name=PKG,
    version=__version__,
    install_requires=install_requires,
    cmdclass=dict(install=Install),
    entry_points={
        'console_scripts': [
            'hy = hy.cmdline:hy_main',
            'hy%d = hy.cmdline:hy_main' % ver,
            'hyc = hy.cmdline:hyc_main',
            'hyc%d = hy.cmdline:hyc_main' % ver,
            'hy2py = hy.cmdline:hy2py_main',
            'hy2py%d = hy.cmdline:hy2py_main' % ver,
        ]
    },
    packages=find_packages(exclude=['tests*']),
    package_data={
        'hy.contrib': ['*.hy', '__pycache__/*'],
        'hy.core': ['*.hy', '__pycache__/*'],
        'hy.extra': ['*.hy', '__pycache__/*'],
    },
    data_files=[
        ('get_version', ['get_version.py'])
    ],
    author="Paul Tagliamonte",
    author_email="tag@pault.ag",
    long_description=long_description,
    description='Lisp and Python love each other.',
    license="Expat",
    url="http://hylang.org/",
    platforms=['any'],
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        "License :: DFSG approved",
        "License :: OSI Approved :: MIT License",  # Really "Expat". Ugh.
        "Operating System :: OS Independent",
        "Programming Language :: Lisp",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.3",
        "Programming Language :: Python :: 3.4",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Topic :: Software Development :: Code Generators",
        "Topic :: Software Development :: Compilers",
        "Topic :: Software Development :: Libraries",
    ]
)

setup.py
diff --git a/setup.py b/setup.py
index ad913523d..a9ac82e4e 100755
--- a/setup.py
+++ b/setup.py
@@ -30,7 +30,7 @@ def run(self):
                         "." + filename[:-len(".hy")])
         install.run(self)
 
-install_requires = ['rply>=0.7.0', 'astor>=0.5', 'clint>=0.4']
+install_requires = ['rply>=0.7.5', 'astor>=0.5', 'clint>=0.4']
 if os.name == 'nt':
     install_requires.append('pyreadline>=2.1')
 
diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py
index 1bacdf08b..cd982d1a6 100644
--- a/tests/compilers/test_ast.py
+++ b/tests/compilers/test_ast.py
@@ -588,3 +588,8 @@ def test_setv_builtins():
         (defn get [self] 42))
       (defn if* [self] 0))
     """)
+
+
+def test_lots_of_comment_lines():
+    # https://github.com/hylang/hy/issues/1313
+    can_compile(1000 * ";\n")

The lexer hits the maximum recursion depth given a file with too many comment lines
     $ yes ';' | head -n 500 >/tmp/foo.hy
     $ hy /tmp/foo.hy
     Traceback (most recent call last):
       File "/home/hippo/Desktop/hyenv/bin/hy", line 11, in <module>
         load_entry_point('hy', 'console_scripts', 'hy')()
       File "/home/hippo/Desktop/hyenv/hy/hy/cmdline.py", line 344, in hy_main
         sys.exit(cmdline_handler("hy", sys.argv))
       File "/home/hippo/Desktop/hyenv/hy/hy/cmdline.py", line 332, in cmdline_handler
         return run_file(options.args[0])
       File "/home/hippo/Desktop/hyenv/hy/hy/cmdline.py", line 211, in run_file
         pretty_error(import_file_to_module, "__main__", filename)
       File "/home/hippo/Desktop/hyenv/hy/hy/cmdline.py", line 184, in pretty_error
         return func(*args, **kw)
       File "/home/hippo/Desktop/hyenv/hy/hy/importer.py", line 95, in import_file_to_module
         _ast = import_file_to_ast(fpath, module_name)
       File "/home/hippo/Desktop/hyenv/hy/hy/importer.py", line 53, in import_file_to_ast
         return hy_compile(import_file_to_hst(fpath), module_name)
       File "/home/hippo/Desktop/hyenv/hy/hy/importer.py", line 41, in import_file_to_hst
         return import_buffer_to_hst(f.read())
       File "/home/hippo/Desktop/hyenv/hy/hy/importer.py", line 34, in import_buffer_to_hst
         return tokenize(buf + "\n")
       File "/home/hippo/Desktop/hyenv/hy/hy/lex/__init__.py", line 17, in tokenize
         return parser.parse(lexer.lex(buf))
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/parser.py", line 32, in parse
         lookahead = next(tokenizer)
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexer.py", line 56, in __next__
         return self.next()
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexer.py", line 41, in next
         return self.next()
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexer.py", line 41, in next
         return self.next()
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexer.py", line 41, in next
         return self.next()
       [Previous line repeated 976 more times]
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexer.py", line 38, in next
         match = rule.matches(self.s, self.idx)
       File "/home/hippo/Desktop/hyenv/lib/python3.6/site-packages/rply/lexergenerator.py", line 33, in matches
         return Match(*m.span(0)) if m is not None else None
     RecursionError: maximum recursion depth exceeded

