Adds newline='\n' to some open() calls

When writing a script file, we want the line ending to be LF.
Uses declare_namespace()

Newer setuptools seem to error out if declare_namespace() is not called
in namespace packages, even though extend_path() is used.