This is the readme file for py2cs.py. It explains what the script does, why I created it, and how to use the script. A last section explains why the code is as it is and how it may evolve. Full source code for the script is in its github repository. This script is offered under the terms of Leo's MIT License.
This script makes a coffeescript (.coffee) file in the output directory for each source file listed on the command line (wildcard file names are supported). This script never creates directories automatically, nor does it overwrite .coffee files unless the --overwrite command-line option is in effect.
This script merely converts python syntax to the roughly equivalent coffeescript syntax. It knows nothing about coffeescript semantics. It is intended only to help start creating coffeescript code from an existing python code base.
This script already does much of the grunt work of converting python to coffeescript. The script processes itself without error, but coffeescript itself complains about some results.
The proximate cause for this script were the notes from a DropBox sprint. Coffeescript is obviously successful. Numerous python-to-javascript systems seem unlikely ever to gain traction. Googling 'python to javascript' or 'python to coffeescript' yields no similar tools, despite many similar searches. This script will be useful to me.
-
Put
py2cs.py
on your path. -
Enter a directory containing .py files:
cd myDirectory
-
Generate foo.coffee from foo.py:
py2cs foo.py
-
Look at foo.coffee to see the generated coffeescript code:
edit foo.coffee
-
(Optional) Run coffeescript itself on the code:
coffee foo.coffee
-
Regenerate foo.coffee, overwriting the previous .coffee file:
py2cs.py foo.py -o
-
(Optional) Specify a configuration file containing defaults:
py2cs.py -c myConfigFile.cfg -o
Usage: py2cs.py [options] file1, file2, ...
Options:
-h, --help show this help message and exit
-c FN, --config=FN full path to configuration file
-d DIR, --dir=DIR full path to the output directory
-o, --overwrite overwrite existing .coffee files
-v, --verbose verbose output
Note: glob.glob wildcards can be used in file1, file2, ...
py2cs.py could be improved, but it is useful as is.
Edward K. Ream
February 21 to 25, 2016