dawson-org / dawson-cli

A serverless web framework for Node.js on AWS (CloudFormation, CloudFront, API Gateway, Lambda)
https://dawson.sh
GNU General Public License v3.0
713 stars 25 forks source link

Python support (script only) #139

Closed alexcasalboni closed 7 years ago

alexcasalboni commented 7 years ago

I have implemented a first version of the main Python script that will parse api.py files. Plus tests.

You can call it from JS like this (sync version):

const spawn = require('child_process').spawnSync;
const python = spawn('python', ['python/require.py']);
console.log(python.status);  // exit code
console.log(python.output);  // list of outputs

or like this (async version):

const spawn = require('child_process').spawn;
const python = spawn('python', ['python/require.py']);
python.stdout.on('data', (data) => {
  console.log(data);
});
python.on('close', (code) => {
  console.log(code);
});

Some stats:


Pylint score: 8.95/10
Ran 10 tests in 0.027s
Total coverage: 96%
lusentis commented 7 years ago

Great work, thanks!

I'll update the test script in the root package.json to include this command: cd src/python && pip install -r requirements-dev.txt && bash runtests.sh.

Regarding "global" App Configuration (docs), do you think it's OK to require python users having a package.json file in their app? Or we may want to discuss other ways to specify App's Config - I don't know if there's something equivalent to package.json in python. (Currently, we use the name and dawson properties.)

alexcasalboni commented 7 years ago

Well, that package.json is basically a dawsonfile :)

I think it could work file for Python users as well.

alexcasalboni commented 7 years ago

P.S. as a side-effect of Python's flexibility, the script allows both functions and classes to be used as legit functions entry points (see tests!).

Basically, this

result = myfunction(event, context)
print json.dumps(result)

generates the same output of this (as long as the class is json-serializable):

obj = MyClass(event, context)
print json.dumps(obj)
lusentis commented 7 years ago

Is there a legit way of determining a python package name? That's the only required information, and would be a shame to require having a package.json file just to specify a name field. The "dawsonfile" is against dawson's zero-config principle.

Something like the app folder name - but more robust and consistent.