[WIP] Use tox and npm scripts
This PR:
- Adds tox for testing/linting Python
- Moves the JS-related scripts (running tests, building, etc.) to
package.json(from the Makefile)
There's not much advantage in using tox instead of the Makefiles, considering we just have a single Python version. I did it because I find it useful to understand the testing configuration, and I think it makes it easier for newcomers to just run the tests. With tox, they just have to:
cp .env.example .env
# Modify the TEST_DATABASE_URL with the test DB to use
tox
I also changed all example values in .env.example to be valid (and commented out SENTRY_DSN, otherwise it'll be used even with an invalid value), to make as easy as possible for new users.
Then I moved the NodeJS scripts from the Makefile to the package.json. This is important to guarantee that we're using the binaries that were installed by npm, not something that we happen to have in our path. By doing this, I fixed a tricky bug. We were using the binaries installed by npm by modifying the PATH in the Makefile, as:
https://github.com/frictionlessdata/goodtables.io/blob/60b9f2624cb052f278d692e9028e1d623291e6b4/Makefile#L5
However, this appends ./node_modules/.bin to the end of the PATH variable. Binaries are searched in the folders inside PATH in the order that they appear, so if (say) you had the karma binary installed in your system, it would be used instead of the one installed in ./node_modules.
If tests pass of course
I'm +1 to get back to package.json scripts. The reason of moving things to Makefile was to find some structure in overwhelming amount of command we had to write at some point. But Makefile is not really helping in it as it's been turned out.
PS.
As we was discussing with Adria I'm not sure why things like setup.py or tox.ini should exist in web apps at all. In my eyes a web app is just one environment directly interpreted set of scripts. So) But I don't mind any)
Great! I'll check why the tests aren't passing and update the PR.
As we was discussing with Adria I'm not sure why things like
setup.pyortox.inishould exist in web apps at all. In my eyes a web app is just one environment directly interpreted set of scripts. So) But I don't mind any)
I mostly agree regarding setup.py. Unless we're publishing to pypi as part of our deployment process, it doesn't bring us much. However, I think every Python project should use tox (or a similar tool).
It's much easier (for a newcomer) to run the tests, being sure the environment is correctly set. It's also useful to run linting. It can even be (ab)used to write something similar to npm scripts, where a command is executed with all the dependencies installed, so you could have tox -e start to start the project, removing the need for a virtualenv entirely.
It's even more useful in our case, where we have many different Python repositories, so we can be sure that wherever we run tox, it's using the correct dependencies and Python versions. There are other ways to do it (like configuring your shell to automatically enable the virtualenv), but tox is easier IMHO.