Write the version.json file when installed with ./setup.py install

Plus a little refactoring to avoid duplicate code when writing the
version.json file to an sdist tarball.