Commit Graph

2736 Commits

Author SHA1 Message Date
Brandon T. Willard
86fda31ab1 Move compilation and parsing functions out of importer.py
Functions and variables relating to compilation and parsing have been moved to
`compiler.py` and `lex/__init__.py`, respectively.  Those functions are
  - `hy_parse` from `hy.importer` to `hy.lex`
  - `hy_eval`, `ast_compile`, and `calling_module` from `hy.importer` to
  `hy.compiler`

Closes hylang/hy#1695.
2018-11-28 14:12:33 -05:00
Kodi Arfer
3e0112f362
Merge pull request #1691 from jwilk-forks/isidentifier
Catch IndentationError in isidentifier()
2018-11-27 17:23:57 -05:00
Jakub Wilk
28504ba85d Catch IndentationError in isidentifier()
Fixes:

    >>> from hy._compat import isidentifier
    >>> isidentifier(u"  0\n 0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "hy/_compat.py", line 47, in isidentifier
        tokens = list(T.generate_tokens(StringIO(x).readline))
      File "/usr/lib/python2.7/tokenize.py", line 374, in generate_tokens
        ("<tokenize>", lnum, pos, line))
      File "<tokenize>", line 2
        0
        ^
    IndentationError: unindent does not match any outer indentation level
2018-11-27 17:15:21 -05:00
Kodi Arfer
c5abc85a2d
Merge pull request #1682 from brandonwillard/macro-changes
Macro processing updates and fixes
2018-11-09 11:13:32 -05:00
Brandon T. Willard
aa9182d76c Make the stdlib dictionary a class instance variable 2018-11-08 22:57:17 -06:00
Brandon T. Willard
3b01742818 Update NEWS 2018-11-08 22:57:17 -06:00
Brandon T. Willard
010986e8ca Implement minimal macro namespacing and add tests
This commit adds just enough namespacing to resolve a macro first in the macro's
defining module's namespace (i.e. the module assigned to the `HyASTCompiler`),
then in the namespace/module it's evaluated in.  Namespacing is accomplished by
adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be
checked for this definition namespace attribute and their car symbol resolved
per the above.

As well, a couple tests have been added that cover
- the loading of module-level macros
  - e.g. that only macros defined in the `require`d module are added
- the AST generated for `require`
  - using macros loaded from modules imported via bytecode
- the non-local macro namespace resolution described above
  - a `require`d macro that uses a macro `require` exclusively in its
    module-level namespace
- and that (second-degree `require`d) macros can reference variables within
  their module-level namespaces.

Closes hylang/hy#1268, closes hylang/hy#1650, closes hylang/hy#1416.
2018-11-08 22:57:17 -06:00
Brandon T. Willard
144a7fa240 Produce Python AST for require statements and skip self requires
Closes hylang/hy#1211.
2018-11-08 22:57:17 -06:00
Kodi Arfer
58003389c5 Integrate hy.inspect into hy.macros
It's compatibility code, and there's not a lot of it, and having a module with the same name as a standard module can be a bit troublesome.
2018-11-08 22:57:17 -06:00
Kodi Arfer
701db83ba9 Remove get_arity
This function wasn't being used anywhere.
2018-11-08 22:56:42 -06:00
Kodi Arfer
4132adb9fe
Merge pull request #1683 from brandonwillard/fix-py27-failed-import-modules
Fix `sys.modules` for failed imports in Python 2.7
2018-10-16 16:05:40 -04:00
Brandon T. Willard
a9763b34cf Fix sys.modules for failed imports in Python 2.7
Newly imported modules with compile and/or run-time errors were not being
removed from `sys.modules`.  This commit modifies the Python 2.7 loader so that
it follows Python's failed-initial-import logic and removes the module from
`sys.modules`.
2018-09-29 20:57:28 -05:00
Kodi Arfer
d2319dc91c
Merge pull request #1679 from brandonwillard/fix-doc-macro
Fix missing import in `doc` macro expansion
2018-09-24 17:01:39 -04:00
Brandon T. Willard
96f99c29d1 Fix missing import in doc macro expansion 2018-09-24 16:39:13 -04:00
Kodi Arfer
1707f602f7
Merge pull request #1678 from brandonwillard/run-ambiguous-files-as-hy
Allow `runpy` to consider non-standard Hy source extensions
2018-09-24 16:36:36 -04:00
Brandon T. Willard
c0c5c9c699 Make cmdline Hy process unknown filetypes as Hy source
This change a Hy-preferring `runhy` that is used by cmdline Hy.  Standard
`runpy` is still patched so that it can run `.hy` files, but the default
behaviour for unknown filetypes is preserved (i.e. assume they are Python
source).

Closes hylang/hy#1677.
2018-09-24 16:27:50 -04:00
Kodi Arfer
a2f3a08750
Merge pull request #1673 from brandonwillard/fix-docstring-with-imports
Fix AST handling of docstrings and __future__ ordering
2018-09-11 16:32:57 -04:00
Brandon T. Willard
f4e5f02b3e Updated NEWS 2018-09-11 16:26:21 -04:00
Brandon T. Willard
a9fca8001e Fix AST handling of docstrings and __future__ ordering
This closes hylang/hy#1367 and closes hylang/hy#1540
2018-09-11 16:26:21 -04:00
Kodi Arfer
4af87dca64
Merge pull request #1672 from brandonwillard/new-patch-importer
New patch importer
2018-09-03 07:36:53 -04:00
Brandon T. Willard
5d325a5156 Add a test for module docstrings 2018-08-27 01:02:29 -05:00
Brandon T. Willard
2ea1e8e017 Make Hy a Python-source module type 2018-08-26 13:20:49 -05:00
Brandon T. Willard
32033b03ce Fix pytest hook so that ignore works consistently 2018-08-26 00:27:36 -05:00
Brandon T. Willard
b12fd33e6f Update NEWS 2018-08-26 00:27:36 -05:00
Brandon T. Willard
bbc66d0042 Add test for shadowed-basename imports
This test ensures that Hy will load a `.hy` instead of a `.py` counterpart.
2018-08-26 00:27:36 -05:00
Brandon T. Willard
1da29417fe Add test for circular imports
Closes hylang/hy#1134.
2018-08-26 00:27:36 -05:00
Brandon T. Willard
cbaba4a10a Use Python cmdline file-relative sys.path
Closes hylang/hy#1457.
2018-08-26 00:27:21 -05:00
Brandon T. Willard
c022abc831 Add Python cmdline bytecode option and set sys.executable
Closes hylang/hy#459.
2018-08-26 00:17:12 -05:00
Brandon T. Willard
4839acadf7 Add tests for importing __main__.hy files
Closes hylang/hy#1466.
2018-08-25 22:50:45 -05:00
Brandon T. Willard
e9e7171b56 Add module reloading tests 2018-08-25 22:50:45 -05:00
Brandon T. Willard
87a5b117a1 Implement new importer using PEP-302 semantics
Python 3.x is patched in a way that integrates `.hy` source files into
Pythons default `importlib` machinery.  In Python 2.7, a PEP-302 "importer"
and "loader" is implemented according to the standard `import` logic (via
`pkgutil` and later pure-Python `imp` package code).

In both cases, the entry-point for the loaders is through `sys.path_hooks` only.
As well, the import semantics have been updated all throughout to utilize
`importlib` and follow aspects of PEP-420.  This, along with some light
patches, should allow for basic use of `runpy`, `py_compile` and `reload`.

In all cases, if a `.hy` file is shadowed by a `.py`, Hy will silently use
`.hy`.
2018-08-25 22:50:38 -05:00
Kodi Arfer
c92fb3c494
Merge pull request #1669 from Kodiologist/speed
Some simple speed-ups
2018-08-18 15:37:41 -07:00
Kodi Arfer
734cdcd2fd Delay importing the lexer and parser
This speeds up runs of Hy that never need to parse or compile Hy code (e.g., running a Hy program that's already byte-compiled).
2018-08-18 18:05:40 -04:00
Kodi Arfer
99851f7f6b Use fastentrypoints
This speeds up launching `hy`.
2018-08-18 18:05:40 -04:00
Kodi Arfer
d1c7ab08ed
Merge pull request #1662 from Kodiologist/win-strftime
Fix date and time hy-reprs on Windows
2018-08-08 06:32:34 -07:00
Kodi Arfer
7ba2105a2b Fix date and time hy-reprs on Windows 2018-08-08 09:26:20 -04:00
gilch
109c0b0f5b
Merge pull request #1664 from brandonwillard/require-in-macroexpand-all
Expand `require`d macros in `macroexpand-all`
2018-08-02 23:57:32 -06:00
Ryan Gonzalez
bd163f248d
Merge pull request #1668 from hylang/gilch-help-redirect
Point out appropriate help forums
2018-07-31 22:15:52 -05:00
gilch
8909ce63cc
Point out appropriate help forums 2018-07-31 20:51:04 -06:00
Kodi Arfer
0a384e7744
Merge pull request #1661 from Kodiologist/expr-compile
Fix handling of unpacking in method calls and attribute lookups
2018-07-30 10:24:57 -07:00
Brandon T. Willard
a46cc39d6b Include macroexpand-all changes in AUTHORS and NEWS 2018-07-25 17:22:40 -05:00
Brandon T. Willard
65b2bd18ce Add a test for require in the body of a macro 2018-07-25 17:20:19 -05:00
Brandon T. Willard
33f2b4a91a Compile requires in the body of a macro
This change enables further macro expansion for cases in which a macro
`require`s other macros within its body.
2018-07-25 17:20:19 -05:00
Kodi Arfer
081a710b0f Fix handling of unpacking in method calls and attribute lookups 2018-07-24 09:45:00 -07:00
Kodi Arfer
0f85331c81 Rename variables in @builds_model(HyExpression) 2018-07-24 09:41:57 -07:00
Kodi Arfer
271f2846dc Minor cleanup in test_ast 2018-07-24 09:37:19 -07:00
Kodi Arfer
45e99d027d Fix an intersphinx link 2018-07-24 09:31:36 -07:00
Kodi Arfer
5bfd4592f6
Merge pull request #1656 from Kodiologist/keyword-call
Make HyKeyword callable
2018-07-24 09:28:16 -07:00
Kodi Arfer
1d2c73165d Make HyKeyword callable
Co-authored-by: Simon Gomizelj <simon@vodik.xyz>
2018-07-24 09:19:37 -07:00
Kodi Arfer
d9fa039252
Merge pull request #1657 from Kodiologist/no-empty-exprs
Make empty expressions illegal at the top level
2018-07-24 09:15:27 -07:00