4 ms·
That’s just a basic Unix thing. Any file starting #!/some/path just means for the shell to invoke that command and pass the contents of the file on stdin.
by TylerE 1y ago
That’s just a basic Unix thing.
Any file starting #!/some/path just means for the shell to invoke that command and pass the contents of the file on stdin.
- ameliaquining 1y agoMost languages currently do not support this in a way that lets you specify dependencies from a package manager. And some don't support it at all; most C and C++ toolchains, for example, don't have a way to compile and run a single source file in a single command.
- tracker1 1y agoExactly, that alone makes it far more useful/portable in practice than a lot of other languages for this type of thing. A python file can have a shebang, but it'll need a bunch of other files around it for module references, etc. Not to mention initialization/setup, etc. The fact that dependencies are referenced in the file and automatically handled at runtime (first or repeated) is a really nice feature to have... it's expressly why I started using Deno over other options for this.
- epage 1y agoThere are at least workarounds for a surprising number of languages: https://dbohdan.com/scripts-with-dependencies https://dbohdan.com/scripts-with-dependencies Read up on the details of each one when proposing the design for Cargo script to see what we could learn.
- ameliaquining 1y agoI would argue that third-party tools don't really cut it, because a lot of the value is being able to include a script inline in, e.g., an email or chat message, and that's undermined if the recipient has to download and install a separate tool. (uv gets half credit because adoption is rapidly rising and it has a shot at becoming a de facto standard, but I'll only award full credit to Python when pip supports this.) They're good for exploring the design space, though.
- epage 1y agoFully agree. I had a section in the Cargo RFC devoted to why a first class solution is important, see https://rust-lang.github.io/rfcs/3502-cargo-script.html#first-vs-third-party https://rust-lang.github.io/rfcs/3502-cargo-script.html#firs...
- tracker1 1y agoI know this... my point was in that Rust didn't have this feature 5-8 years ago when I first started reading/learning about it. A lot of languages haven't had an active scripting-capable usage that can do this until fairly recently. C# even has it in .Net 10, though I'm not sure about dependency handling in that case. I like and was commenting that rust has the cargo frontmatter instead of a separate cargo file, same for deno in that it can reference the repo/url directly instead of requiring a separate modules file/folder (like node package.json/node_modules) or even with python. You can reference the modules you need directly.
- ameliaquining 1y agoA bunch of third-party Python package manager clients, most famously uv, support this now. They all use the same front-matter format (PEP 723). Unfortunately, pip (the first-party package manager client that's usually distributed with Python) doesn't support it yet: https://github.com/pypa/pip/issues/12891 https://github.com/pypa/pip/issues/12891
- tracker1 1y agoInteresting... I'm not really involved in much/any Python development, but cool to know there are options out there. I've mostly just run existing projects as needed.
- kibwen 1y agoTo be precise, Rust files have supported shebangs since well before 1.0, there just wasn't really any built-in tool to point the shebang at. The new stuff in the relevant RFC is actually about Cargo, not Rust; the "Cargo frontmatter" syntax doesn't need to be added to Rust, it can just be stripped by Cargo before it hands off the file to rustc.
- epage 1y agoT-lang and T-cargo still decided to add frontmatter to Rust, see https://rust-lang.github.io/rfcs/3503-frontmatter.html https://rust-lang.github.io/rfcs/3503-frontmatter.html
- wpollock 1y agoNot quite. The shell ignores a she-bang line; it's the kernel that reads it. I have an explanation here: <https://wpollock.com/Unix/ShellScriptingIntro.htm#shebang https://wpollock.com/Unix/ShellScriptingIntro.htm#shebang>