Giter VIP home page Giter VIP logo

Comments (10)

azazel75 avatar azazel75 commented on May 19, 2024

Indeed you're right!
Thanks, i'm fixing it now and then I'll release a new version

from metapensiero.pj.

azazel75 avatar azazel75 commented on May 19, 2024

You can try out the new 0.3 release now ;-)

from metapensiero.pj.

elgow avatar elgow commented on May 19, 2024

The new build works fine as installed. Thank you very much for the unbelievably quick fix.

Unfortunately, I'm hitting another problem with translation. Here's the stack trace:

File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/main.py", line 137, in main
args.stage3)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/main.py", line 68, in transform
enable_stage3=enable_stage3)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/api.py", line 57, in translate_file
enable_stage3=enable_stage3)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/api.py", line 137, in translates
jsast = t.transform_code(pyast)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 159, in transform_code
self._finalize_target_node(result)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in _transform_node
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 232, in _transform_node
self._finalize_target_node(transformed, py_node=py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in _transform_node
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 232, in _transform_node
self._finalize_target_node(transformed, py_node=py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 239, in _transform_node
self._finalize_target_node(py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 232, in _transform_node
self._finalize_target_node(transformed, py_node=py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in _transform_node
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 232, in _transform_node
self._finalize_target_node(transformed, py_node=py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in _transform_node
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 232, in _transform_node
self._finalize_target_node(transformed, py_node=py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 256, in _finalize_target_node
targs.append(self._transform_node(arg))
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in _transform_node
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 219, in
res = [self._transform_node(child) for child in py_node]
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/processor/transforming.py", line 230, in _transform_node
transformed = transformation(self, py_node)
File "/Volumes/Work/Home/UW/.virtualenvs/try3/lib/python3.5/site-packages/metapensiero/pj/transformations/comprehensions.py", line 23, in ListComp
assert isinstance(x.generators[0].target, ast.Name)
AssertionError

And here's the code:

def dup_message_template(new_entry, tracker_entries):
# nonlocal html
ret = html.div('#dup_entries', [html.h5(None, ['A new entry for ', new_entry.patient, ' : ', new_entry.mrn, ' : ',
new_entry.accession_number, ' may duplicate:']),
html.ul(None, [html.li(None, [ tracker_link(entry.tracker_id),
':'.join([entry.patient, entry.mrn, entry.accession_number])]) for entry, idx in tracker_entries]),
html.p(None, [html.strong(None, ['Still want to create Tracker entry?'])])])
return str(ret)

The calls to html.___() are to a javascript html builder library called pithy. Other functions are my own. The same code translates fine in Transcrypt (http://www.transcrypt.org/), so unless I'm venturing out of the subset supported by javascripthon I think it's a compiler bug.

If you'd prefer that I submit this as an issue I'll do that. Just let me know.

Thanks again,

Ed

On Fri, 8 Apr 2016, Alberto Berti wrote:

You can try out the new 0.3 release now ;-)


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub[AK_suXV86sj5wH2N7aHI4bsvlJLvJRSsks5p1sQHgaJpZM4IDQSU.gif]

from metapensiero.pj.

azazel75 avatar azazel75 commented on May 19, 2024

yes, it's a problem with comprehensions, they are quite in flux right now, i've still to decide how to proceed with them (if to limit their translation at what ES6 can do or if cook up a complete polyfill, like transcrypt does). It's a current, known limitation of my package.

But this isn't just it... there is another subtle problem in your code. JavaScripthon doesn't convert your ':'.join in something meaningful in JavaScript, it's not a complete polyfill for python's base objects api. JS has Array.join() which is somewhat the python's reversed.. You should use that syntax if you want your code to run with JavaScripthon.

I want to keep polyfills to a bare minimum in order of avoiding to pay a high speed tradeoff when running the code, but I have yet to set a clear limit. I think i will translates what "fits" into ES6 and then decide if to go further with polyfilling

from metapensiero.pj.

azazel75 avatar azazel75 commented on May 19, 2024

to solve this situation you can also think about using something like lodash or underscore.

from metapensiero.pj.

elgow avatar elgow commented on May 19, 2024

Hello Alberto,

Thank you for helping me out with this. I'll look at how I could code my function with lodash or _.js. I really like the simple Javascript emitted by JavaScripthon, as opposed to the extensive leading boilerplate that Transcrypt produces. I'll need to decide whether relying more on Javascript libraries for things like join() and comprehension/map operations is a good trade-off for the simpler javascript code.

Ed

On Fri, 8 Apr 2016, Alberto Berti wrote:

to solve this situation you can also think about using something like lodash or underscore.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub[AK_subnbOc6NmyUcZZpvO5W2aOh4yGYnks5p1vQCgaJpZM4IDQSU.gif]

from metapensiero.pj.

azazel75 avatar azazel75 commented on May 19, 2024

It's very simple to use for example lodash from JavaScripthon if you are using a modern packager (like webpack), simply do:

  1. npm install lodash;
  2. In your sources import it like "import lodash as _"
  3. use _ in your code

from metapensiero.pj.

elgow avatar elgow commented on May 19, 2024

Hello Alberto,

The thing is, one of the main reasons I'm interested in JavaScripthon is that it can be installed with just pip. I'm concerned about the growing complexity of the build environment for my application. I find Javascript ES5 to be a frightful language. At first I thought about coding in ES6 and transpiling to ES5 with babel, but that seemed to entail installing node.js just to get babel. I know that's normal for web developers, but most of us where I work are Python devs, not web devs. Using JavaScripthon or Transcrypt allows the client-side code to be written in Python, and also provides a build environment that sticks to Python tooling. For Python devs that's much simpler.

I do appreciate the tip, though. It's quite interesting to be able to import Javascript libraries into Python client-side code.

Thanks again,

Ed

On Sat, 9 Apr 2016, Alberto Berti wrote:

It's very simple to use for example lodash from JavaScripthon if you are using a modern packager (like webpack), simply do:

  1. npm install lodash;
  2. In your sources import it like "import lodash as _"
  3. use _ in your code


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub[AK_suXnjcMtYy6--k4_Wdt-Vil8jeXzBks5p17fBgaJpZM4IDQSU.gif]

from metapensiero.pj.

jsmesami avatar jsmesami commented on May 19, 2024

Hi Ed,
I guess that JavaScripthon focus is different: It's meant to be a simple and small transpiler without much batteries included. Frontend world is indeed clunky and JavaScripthon will help only with the lingo part.
As a Python developer myself, I suggest you install Node into your app's virtual environment:

pip install nodeenv
nodeenv -p --prebuilt

With npm, you will get much more than just Babel. For example Less for css, which makes styling almost bearable.

from metapensiero.pj.

azazel75 avatar azazel75 commented on May 19, 2024

Good catch @jsmesami, i didn't know the nodeenv stuff (nice paintings, by the way)
Here the usefulness of JavaScripthon may seem diminished but hey, balance between polyfills vs having the user choose his own js tools isn't so simple, but nothing it's written in stone.

Perhaps a translator like Typescript does a better job at insulating the python's developer that wants to do some little work on the client-side, but I usually develop client-side code using various JS libraries where my converted code is mostly... the glue, and i didn't want to reinvent the wheel. Lets leave to the full time JS developers the burden and optimize their functional oriented libraries, much like we have to let them take care of the html ui ones.

What really bothers me about JavaScripthon right now is about the widespread pattern of using anonymous functions in JS to do functional stuff and the apparent lack in Python for anything similar to JS anon functions... (lambdas usually don't compare). It's not that I'm falling in love with anon functions but i keep thinkng if it's possible to translate that pattern to one (detectable by JavaScripthon) that is more pythonesque.

from metapensiero.pj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.