3 ms·
A zipapp is not a hack, it's an official feature of the python stdlib (as shown in the parent comment), and is made for the specific use case of grouping severa
by BiteCode_dev 5y ago
A zipapp is not a hack, it's an official feature of the python stdlib (as shown in the parent comment), and is made for the specific use case of grouping several files into one module for ease of sharing.
All of this works fine with python 2.7 as long as you put the rest of your code in your main() entry point, which you should do anyway. So an f-string would cause no problem.
Also, "informative stack trace" is only informative to another dev, and an experienced one at that, given how many juniors I encounter that can't read a traceback.
Indeed, you script users may not be devs, and for those, a traceback would be confusing. For this reason, a script should only output a traceback in dev mode, but in production, if the dev flag is not set (-X dev), you should never see a traceback. It's a good practice to suppress it with sys.excepthook, and log it into a file instead.
Using a syntax error like you do for this purpose IS the big hack.
Now I'm not against a hack. I can see the value of it for your own scripts, of things that you code quick and dirty style. After all, I don't always want to have a clean entry point and more than one file.
- tyingq 5y agoCan you trap initial parse errors with sys.excepthook? I don't think you can, at least not in a single file script.
- BiteCode_dev 5y agoIt is not necessary, as I indicated before, if you isolate your entry point, you will not run into syntax errors (unless you publish broken code).
- tyingq 5y agoWell, where broken code is code that assumes /usr/bin/python would be python3.
- BiteCode_dev 5y agoAgain, not a problem if you isolate your entry point. Python will not parse the incompatible code since it's never imported. You keep repeating the same thing a if you ignored this essential part.
- tyingq 5y ago>You keep repeating the same thing a if you ignored this essential part. Well, yes, and you keep insisting that everything is fine, as-is. There was a missed opportunity here.