API cleanup
See original GitHub issueCurrently the only way of creating a js
is calling the cli
interface. Even calling the underlying code is not working as it relays on global defined variables for cli
. Also the compiler
is only importable over a hack.
import tempfile
import sys
import os
def transcrypt_code(code):
"""
The api is pretty messy so to get it working we create a tem file
"""
import transcrypt
transpilerDir = transcrypt.__path__._path[0]
modulesDir = '{}/modules'.format(transpilerDir)
# Both CPython and Transcrypt will use all dirs in sys.path as search roots for modules
# CPython will also search relatively from each module, Transcrypt only
# from the main module
sys.path = [modulesDir] + sys.path
sys.modules.pop('org', None)
from org.transcrypt import compiler
name = None
with tempfile.NamedTemporaryFile() as f:
name = f.name
f.write(code.encode())
compiler.Program(name)
with open(os.path.join(
os.path.dirname(name), "__javascript__",
os.path.basename(name) + ".js")) as f:
ret = f.read()
return ret
if __name__ == "__main__":
transcrypt_code("print('helo')")
This results in an error:
Traceback (most recent call last):
File "trans.py", line 39, in <module>
transcrypt_code("print('helo')")
File "trans.py", line 30, in transcrypt_code
compiler.Program(name)
File "/tmp/env3/lib/python3.5/site-packages/transcrypt/modules/org/transcrypt/compiler.py", line 93, in __init__
self.rawModuleCaption = '\n\n// ============ Source: {} ============\n\n' if utils.commandArgs.anno else ''
AttributeError: 'CommandArgs' object has no attribute 'anno'
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Cleanup API - Vertuna WIKI - ConfiForms
You can use it to cleanup data stored by ConfiForms plugin, all data or filtered by filter criteria. Same format as for filters...
Read more >API | Testing Library
API. React Testing Library re-exports everything from DOM Testing Library as well as these ... cleanup; act; renderHook; renderHook Options.
Read more >API cleanup for freshly created projects - DatoCMS
API cleanup for freshly created projects. December 6th, 2022. We want our APIs to be as clean as possible, but we also don't...
Read more >Cleanup - Oil Spill Prevention and Response - API
Cleanup. When a spill occurs, the prior planning and coordination of the National Response System greatly enhances the speed and effectiveness of the ......
Read more >Using the API to cleanup redundant unit files in IBM Rhapsody
Unlike "Clean Redundant Source Files" in the Code menu, there is no built-in mechanism to remove file units from the project directory. However, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, if you want to invoke Transcrypt from a Python script, simply importing it doesn’t work. Invoking it is possible, but has to be done via the command line, as in shipment_test.py below. It’s admitted that this is less elegant than be able to call the compiler directly. I’ll register this as an enhancement.
I don’t expect this to be handled anytime soon, so I’ve added the label postponed and will close it again. Motivation: #258. Postponed issues can easily be searched since they share the same label.