metapensiero / metapensiero.pj

Javascript for refined palates: a Python 3 to ES6 Javascript translator
Other
900 stars 73 forks source link

name 'hq' is not defined #53

Closed retorquere closed 2 years ago

retorquere commented 3 years ago

While compiling files in https://github.com/retorquere/biblib, I'm getting

An error occurred while compiling source file 'test.py'
NameError: name 'hq' is not defined
azazel75 commented 3 years ago

Hi Emiliano,

"Emiliano" == Emiliano Heyns notifications@github.com writes:

Emiliano> While compiling files in https://github.com/retorquere/biblib, I'm getting
Emiliano> ```
Emiliano> An error occurred while compiling source file 'test.py'
Emiliano> NameError: name 'hq' is not defined
Emiliano> ```

I'm sorry but i do not know anything about such project. Please ask to its project maintainer

cheers -- Alberto Berti - Information Technology Consultant PGP: 9377 A68C C5B5 B534 36BD F20B E3B5 C559 99D6 7CF9

        "gutta cavat lapidem"
retorquere commented 3 years ago

The project doesn't use hq and has no outside dependencies.

On Fri, 27 Nov 2020, 17:40 Alberto Berti, notifications@github.com wrote:

Hi Emiliano,

"Emiliano" == Emiliano Heyns notifications@github.com writes:

Emiliano> While compiling files in https://github.com/retorquere/biblib, I'm getting Emiliano> Emiliano> An error occurred while compiling source file 'test.py' Emiliano> NameError: name 'hq' is not defined Emiliano>

I'm sorry but i do not know anything about such project. Please ask to its project maintainer

cheers

Alberto Berti - Information Technology Consultant PGP: 9377 A68C C5B5 B534 36BD F20B E3B5 C559 99D6 7CF9

"gutta cavat lapidem"

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/metapensiero/metapensiero.pj/issues/53#issuecomment-734915218, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABAIDFWVWZAI77NX6PHFA3SR7JA5ANCNFSM4UFCME7A .

596050 commented 3 years ago

This error doesn't seem to occur in python 3.8 but can be reproduced in >= 3.9?

retorquere commented 3 years ago

Ah -- I'm on 3.9

azazel75 commented 3 years ago

unfortunately I haven't had the time to test it on 3.9

gw2princeps commented 3 years ago

This error doesn't seem to occur in python 3.8 but can be reproduced in >= 3.9?

Reproducible on python 3.9.1

icarito commented 3 years ago

Yes confirm I see the same issue with Python 3.9.2. Here's a debug output, seems something to do with macropy internally with javascripthon.

[icarito@tengu thunder]$ python3 -m metapensiero.pj -s "print" -d
DEBUG:__main__:Log started
INFO:macropy.core.import_hooks:Expand macros in /home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/transformations/classes.py
INFO:macropy.core.macros:Finding macros in 'metapensiero.pj.transformations.classes'
INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'metapensiero.pj.transformations.classes'
INFO:macropy.core.macros:Importing macros from 'macropy.experimental.pattern' into 'metapensiero.pj.transformations.classes'
INFO:macropy.core.import_hooks:Expand macros in /home/icarito/.local/lib/python3.9/site-packages/macropy/experimental/__init__.py
INFO:macropy.core.macros:Finding macros in 'macropy.experimental'
INFO:macropy.core.import_hooks:Expand macros in /home/icarito/.local/lib/python3.9/site-packages/macropy/experimental/pattern.py
INFO:macropy.core.macros:Finding macros in 'macropy.experimental.pattern'
INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'macropy.experimental.pattern'
INFO:macropy.core.macros:Importing macros from 'macropy.core.hquotes' into 'macropy.experimental.pattern'
DEBUG:macropy.core.macros:Found macro 'hq', type 'Block', line 333
DEBUG:macropy.core.macros:Found macro 'q', type 'Block', line 255
DEBUG:macropy.core.macros:Found macro 'switch', type 'Block', line 393
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/__main__.py", line 262, in <module>
    main()
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/__main__.py", line 161, in main
    res = transform_string(input, es5, es6, stage3,
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/__main__.py", line 112, in transform_string
    res, src_map = api.translates(input, enable_es6=enable_es6,
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/api.py", line 144, in translates
    t = Transformer(transformations, JSStatements, es6=enable_es6,
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/processor/transforming.py", line 53, in __init__
    self.transformations = load_transformations(py_ast_module)
  File "/home/icarito/.local/lib/python3.9/site-packages/metapensiero/pj/processor/transforming.py", line 305, in load_transformations
    __import__(mod_name)
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 925, in _find_spec
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/import_hooks.py", line 147, in find_spec
    code, tree = self.expand_macros(source, origin, spec)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/import_hooks.py", line 110, in expand_macros
    new_tree = macropy.core.macros.ModuleExpansionContext(
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 533, in expand_macros
    tree = super().expand_macros(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 355, in expand_macros
    return self.walk_tree(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 489, in walk_tree
    self.walk_children(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 454, in walk_children
    new_value = self.walk_tree(old_value)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 489, in walk_tree
    self.walk_children(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 459, in walk_children
    new_t = self.walk_tree(t)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 489, in walk_tree
    self.walk_children(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 454, in walk_children
    new_value = self.walk_tree(old_value)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 489, in walk_tree
    self.walk_children(tree)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 459, in walk_children
    new_t = self.walk_tree(t)
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 480, in walk_tree
    new_tree = self.walk_tree(expand_it.send(new_tree))
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/macros.py", line 422, in macro_expand
    new_tree = function(
  File "/home/icarito/.local/lib/python3.9/site-packages/macropy/core/failure.py", line 29, in clear_errors
    return hq[raise_error(MacroExpansionError(msg))]
NameError: name 'hq' is not defined
azazel75 commented 3 years ago

Yes, I had started using macropy for some transformations but I'm not maintaining it anymore. Now I use javascripthon very seldomly so I don't have a real incentive to make it work with new pythons.. is this still usefu for you guys?

icarito commented 3 years ago

I find I prefer it to other options (I've tried RapydScript-NG, pscript and transcrypt). Each has drawbacks. But my distro (Arch based) packages Python 3.9 only... I'm starting a new project and was thinking of using it.

azazel75 commented 3 years ago

@icarito Nice to know, can you tell me why you prefer it? Also, on master now there's a basic Python 3.9 support, could you please try it out? and give me feedback?

icarito commented 3 years ago

Hi @azazel75 I'm sorry that I took so long to reply, I'm traveling since a few days ago.

Yes of course I will share with you what I find!

This is a superficial description from memory from experiments in the past 2-3 years. Perhaps you know more deeply what other differences are, advantages/disadvantages.

Blessings and thank you for your very useful response!

icarito commented 3 years ago

I will be trying Javascripthon again and letting you know how it goes!

ENDrain commented 3 years ago

I'm having this error now on Python 3.9.4. My program in rather simple, doesn't have any dependencies, only imports re.

Console debug output: ```console > pj src\ -d DEBUG:metapensiero.pj.__main__:Log started INFO:macropy.core.import_hooks:Expand macros in c:\program files\python39\lib\site-packages\metapensiero\pj\transformations\classes.py INFO:macropy.core.macros:Finding macros in 'metapensiero.pj.transformations.classes' INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'metapensiero.pj.transformations.classes' INFO:macropy.core.macros:Importing macros from 'macropy.experimental.pattern' into 'metapensiero.pj.transformations.classes' INFO:macropy.core.import_hooks:Expand macros in c:\program files\python39\lib\site-packages\macropy\experimental\__init__.py INFO:macropy.core.macros:Finding macros in 'macropy.experimental' INFO:macropy.core.import_hooks:Expand macros in c:\program files\python39\lib\site-packages\macropy\experimental\pattern.py INFO:macropy.core.macros:Finding macros in 'macropy.experimental.pattern' INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'macropy.experimental.pattern' INFO:macropy.core.macros:Importing macros from 'macropy.core.hquotes' into 'macropy.experimental.pattern' DEBUG:macropy.core.macros:Found macro 'hq', type 'Block', line 333 DEBUG:macropy.core.macros:Found macro 'q', type 'Block', line 255 DEBUG:macropy.core.macros:Found macro 'switch', type 'Block', line 393 Traceback (most recent call last): File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\program files\python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Program Files\Python39\Scripts\pj.exe\__main__.py", line 7, in File "c:\program files\python39\lib\site-packages\metapensiero\pj\__main__.py", line 222, in main transform( File "c:\program files\python39\lib\site-packages\metapensiero\pj\__main__.py", line 97, in transform api.translate_file(src_fname, dst_fname, enable_es6=enable_es6, File "c:\program files\python39\lib\site-packages\metapensiero\pj\api.py", line 68, in translate_file js_text, src_map = translates(src_text, True, src_relpath, File "c:\program files\python39\lib\site-packages\metapensiero\pj\api.py", line 144, in translates t = Transformer(transformations, JSStatements, es6=enable_es6, File "c:\program files\python39\lib\site-packages\metapensiero\pj\processor\transforming.py", line 53, in __init__ self.transformations = load_transformations(py_ast_module) File "c:\program files\python39\lib\site-packages\metapensiero\pj\processor\transforming.py", line 305, in load_transformations __import__(mod_name) File "", line 1007, in _find_and_load File "", line 982, in _find_and_load_unlocked File "", line 925, in _find_spec File "c:\program files\python39\lib\site-packages\macropy\core\import_hooks.py", line 147, in find_spec code, tree = self.expand_macros(source, origin, spec) File "c:\program files\python39\lib\site-packages\macropy\core\import_hooks.py", line 110, in expand_macros new_tree = macropy.core.macros.ModuleExpansionContext( File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 533, in expand_macros tree = super().expand_macros(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 355, in expand_macros return self.walk_tree(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 489, in walk_tree self.walk_children(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 454, in walk_children new_value = self.walk_tree(old_value) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 489, in walk_tree self.walk_children(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 459, in walk_children new_t = self.walk_tree(t) self.walk_children(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 454, in walk_children new_value = self.walk_tree(old_value) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 489, in walk_tree self.walk_children(tree) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 459, in walk_children new_t = self.walk_tree(t) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 480, in walk_tree new_tree = self.walk_tree(expand_it.send(new_tree)) File "c:\program files\python39\lib\site-packages\macropy\core\macros.py", line 422, in macro_expand new_tree = function( File "c:\program files\python39\lib\site-packages\macropy\core\failure.py", line 29, in clear_errors return hq[raise_error(MacroExpansionError(msg))] NameError: name 'hq' is not defined ```

I've noticed there's some error with macropy so I updated it. Error changed to this:

Console debug output: ```console > pj src\ -d Traceback (most recent call last): File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\program files\python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Program Files\Python39\Scripts\pj.exe\__main__.py", line 4, in File "c:\program files\python39\lib\site-packages\metapensiero\pj\__main__.py", line 14, in from . import api File "c:\program files\python39\lib\site-packages\metapensiero\pj\api.py", line 21, in from . import transformations File "c:\program files\python39\lib\site-packages\metapensiero\pj\transformations\__init__.py", line 11, in import macropy.activate File "c:\program files\python39\lib\site-packages\macropy\activate.py", line 4, in macropy.activate() AttributeError: module 'macropy' has no attribute 'activate' ```
azazel75 commented 3 years ago

@ENDrain Thanks for reporting. Two things:

ENDrain commented 3 years ago

Thanks for advice! I've tried both unreleased branch and stable version with 3.6. Neither worked producing different errors. I'll report later

azazel75 commented 3 years ago

@icarito, do you had the chance to test it out?

Morsmalleo commented 2 years ago

Recieving this error with Python3.9.2

setup of metapensiero.pj was done using this git repository

icarito commented 2 years ago

Alberto, I'm so sorry I didn't respond to you at the time, I was travelling and had to abandon my pet project at the time. Bit it it did work, but I haven't tested again!

@Morsmalleo 's message brought it back to my attention.

icarito commented 2 years ago

I've just tested the version in this repository with Python 3.9.9 and it works for me!

Installed it with pip install git+https://github.com/metapensiero/metapensiero.pj

Morsmalleo commented 2 years ago

I've just tested the version in this repository with Python 3.9.9 and it works for me!

Installed it with pip install git+https://github.com/metapensiero/metapensiero.pj

I will try this myself and see if it solves the problem

Morsmalleo commented 2 years ago

I've just tested the version in this repository with Python 3.9.9 and it works for me! Installed it with pip install git+https://github.com/metapensiero/metapensiero.pj

I will try this myself and see if it solves the problem

Yep working for me, just getting a TransformationError: Node type 'Global': Line: 37, Column: 4. No Transformation for the node error now

azazel75 commented 2 years ago

Thank you Sebastian, I'll release a new version soon

cybercat2 commented 2 years ago

What can I say, I'm just different... I'm still getting the 'hq' error, and I've done the update above. Anyone else having this problem still?

Thanks, Chris.kelly.tn@gmail.com

beauxq commented 2 years ago

I still see the hq error after pip install git+https://github.com/metapensiero/metapensiero.pj

Morsmalleo commented 2 years ago

I still see the hq error after pip install git+https://github.com/metapensiero/metapensiero.pj

What pip version and python version are you using

beauxq commented 2 years ago

I still see the hq error after pip install git+https://github.com/metapensiero/metapensiero.pj

What pip version and python version are you using

Python 3.9.5 pip 20.0.2

Morsmalleo commented 2 years ago

I still see the hq error after pip install git+https://github.com/metapensiero/metapensiero.pj

What pip version and python version are you using

Python 3.9.5 pip 20.0.2

Try upgrading to 3.9.9 that's what I did and it worked for me

Morsmalleo commented 2 years ago

I still see the hq error after pip install git+https://github.com/metapensiero/metapensiero.pj

What pip version and python version are you using

Python 3.9.5 pip 20.0.2

Try upgrading to 3.9.9 that's what I did and it worked for me

I originally tried with python 3.9.2 but upgrading to python 3.9.9 did it for me

azazel75 commented 2 years ago

Sorry, I discovered that this copy of the repo wasn't in sync with the main on gitlab and so some of the fixes for py3.9 didn't show up here. This error shouldn't happen anymore because macropy isn't used anymore

azazel75 commented 2 years ago

Please try to install the master from here now

public-rant commented 2 years ago

Installing from master solved the issue for me.

azazel75 commented 2 years ago

A new release 0.12 containing the fixes described here has now been released