3 ms·
We have an internal tool that autoformats code (it calls clang for C++, some other tool for C#, and autopep8 for python). But for Python I did not want to rely
by malkia 5y ago
We have an internal tool that autoformats code (it calls clang for C++, some other tool for C#, and autopep8 for python). But for Python I did not want to rely on python, but have it a separate standalone .exe that can run by itself (almost, still needed python38.dll). So nuitka helped me there:
I wrote a small app, which is simply:
autopep8tool.py:
import autopep8; autopep8.main()
Then had this .bat file to do the .exe for me:
autopep8tool.make_exe.cmd:
@echo off
pushd %~dp0
call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat"
p4 edit ..\tools\autopep8tool.\*
p4 edit ..\tools\python38.dll
for /d %%i in (*.dist *.build) do rd %%i /s /q
echo import autopep8; autopep8.main() > autopep8tool.py
call nuitka --standalone --assume-yes-for-downloads --unstripped --windows-dependency-tool=pefile autopep8tool.py
copy autopep8tool.dist\autopep8tool.\* ..\tools
copy autopep8tool.dist\python38.dll ..\tools
for /d %%i in (*.dist *.build) do rd %%i /s /q
popd
works great so far, and even that the produced .exe is 10mb + 4mb python38.dll, it's great logistical saver (IMHO), as I can rotate the tool to other teams, depots, without requiring proper python (which is even trickier on windows). It's probably not completely sandboxed (hermetic), but works well so far.
calling autopep8.exe --help even gives the right help.
So great tool (though I've been told about others, like google's subpar, etc.)
- dataflow 5y agoDo you find it increases the maintenance burden? Since now a previously 1-character change requires a massive recompilation, and updates to Python (which happen frequently...) also require recompilation.
- arthurcolle 5y agoyou could just set up a file system listener and then trigger recompiles at some arbitrarily decided-upon interval of time. Doesn't seem like a huge pain otherwise.
- malkia 5y agoI've only had to compile it once, unless we change python drastically and/or want autopep8.py changes (I would think this does not happen often, and if it does it also means we'll have to reformat our code). Granted, my case is really not general one, but nuitka fit well there (like I really wanted to avoid another 'freeze' tool that unpacks python to a temp folder, and calls it from there just to run autopep8.py). That to be said, I was not able to get nuitka working with some of the other popular format lib (I'll need to look again, it takes a bit of setup)
- wenc 5y agoRecompilation is the norm for compiled languages so this doesn’t seem like it would be very onerous or have any kind of substantial effect on maintainability.