5 ms·
Speaking of this kind of check... recently I have been trying to set up some scripts that could run on Mac with "nothing installed". I had been opting for Pytho
by rtpg 4y ago
Speaking of this kind of check... recently I have been trying to set up some scripts that could run on Mac with "nothing installed". I had been opting for Python (even using `urllib` to avoid having `requests` as an option) and... a good chunk of people ended up hitting weird errors with SSL certs.
I know there are probably other answers (I guess writing binaries in Go?), but given how nice Python is for glue code when it works, I do wish for something like `python --config-file pyproject.toml my-script.py` that would figure out requirements, install those "somewhere", ensure the right python version (installing if necessary) and then run the script in a consistent environment (PYTHONPATH being reset, for example).
I know there's a lot of tools for packaging Python code into their own binaries, but I think we could probably get pretty far with some built-in "install and run" tooling that doesn't start with "decide where to put a virtualenv"
- tyingq 4y ago>trying to set up some scripts that could run on Mac with "nothing installed" Perl still comes with MacOS 12.3. And Perl would be a decent language to bootstrap a working Python with working certificates, etc. Though Apple has said all scripting languages will be removed from the default install eventually. "Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app." >I guess writing binaries in Go? Then you get the fun of signing, or README language to guide the user around adding an exception. They sure are making bootstrapping hard. I wish they would pick at least one stable scripting environment to bundle...lua maybe?
- zbentley 4y agoDoes perl have a built in HTTP client? The author wanted to hit a URL, and if I recall perl didn't support that natively (I last used it professionally in 5.16 though, so I may be out of date). If the state of the art in Perl is still "shell out to curl or whatnot" then that is really not portable or stable compared to Python's included urllib--SSL errors or not.
- tyingq 4y ago>Does perl have a built in HTTP client HTTP::Tiny ships with Perl, including 5.16. I'm not sure if MacOS Perl comes with a working IO::Socket::SSL you would need for https. Edit: See if this works or not: perl -MHTTP::Tiny -E 'say HTTP::Tiny->new->get("https://www.google.com/")->{content}'
- jwilk 4y agoBeware that HTTP::Tiny doesn't verify TLS certs by default.
- mywittyname 4y agoNot sure if this meets your goals or not, but have you looked at Pyinstaller[0]? This was designed to help with the problem of distributing python code with external dependencies included. (my assumption from your comment is that you're targeting "nothing installed" as a way of preventing end users from having to install packages on their external machine). [0] https://pyinstaller.org/en/latest/ https://pyinstaller.org/en/latest/
- rtpg 4y agoMy use case is a... bit different. The idea is I want to be able to distribute scripts, but for those scripts to still be scripts (so that the users can fix issues and send PRs back to the project). But I want the scripts to be run in a more or less fixed environment. Or at the very least a "wipe everything and start over" solution that doesn't mess with other environments. It's OK for me if there is a single binary that is "guaranteed" to work that also needs to be installed (for example "you have to install nix/tox"), similar to people having to install a JVM (which mostly works relative to Python).
- klysm 4y agoI could see M1 causing issues with compiling. How complex is the stuff you are doing? Too much for shell?
- rtpg 4y agoI mean shell scripts are just annoying? You don't have even the basics like dictionaries, argparse and friends don't exist, some weird space can throw everything off (yes I know about shellcheck). Every common action is some different tool that you might or might not correctly use (let's not even get into implementation differences for stuff like `find` between Mac and Linux). And yeah you can use curl for web requests. But when your problem then becomes "make a web request, take a chunk out of that" you're looking at curl _and_ jq. And clean error handling... I know how to write shell scripts, but I think I hit their abstraction ceilings way too early, especially if I'm looking to write something that is maintainable by other people on the team. I know people talk about how every machine will have some shell, but when you think about it a bit more all the "nice" shell utils are not installed by default. All the more power to people who can write clean shell scripts. I try to, but am not good at it. But I know how to write Python (or JS, or Java, or C if someone demanded I do it...)
- microtonal 4y agoSpeaking of this kind of check... recently I have been trying to set up some scripts that could run on Mac with "nothing installed". I had been opting for Python FWIW, Python is not shipped with macOS anymore: https://www.macrumors.com/2022/01/28/apple-removing-python-2-in-macos-12-3/ https://www.macrumors.com/2022/01/28/apple-removing-python-2... At the very least you need Xcode Command Line Tools.
- lambdaba 4y agoNix has the closest thing to this in the form of a shebang you call with the interpreter and any additional package dependencies: https://gist.github.com/travisbhartwell/f972aab227306edfcfea https://gist.github.com/travisbhartwell/f972aab227306edfcfea
- rtpg 4y agoHonestly that might not be the worst idea. Yes, you have to install nix, but you _only_ have to install nix.
- pacaro 4y agoI mean, clearly you could do this with a shell script, but I believe that tcl is installed by default on MacOs, so there's that too, both wish and tclsh are available so you could even have UI (as long as you don't care about accessibility)