Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nbb.core/invoked-script fn #317

Merged
merged 16 commits into from
Mar 31, 2023
Merged

Conversation

bolivier
Copy link
Contributor

@bolivier bolivier commented Mar 30, 2023

Introduces nbb.core/invoked-script that outputs an absolute path based on the file passed to nbb, either literally or with -m

The rationale is to be able to use

(if (= *file* (invoked-script))
  :foo
  :bar)

to only run things when the script is invoked, not at a repl.

The tests verify that *file* and (invoked-script) are present and the same when used with -m and passing the plain script.

Please answer the following questions and leave the below in as part of your PR.

script/nbb_tests.clj Outdated Show resolved Hide resolved
@borkdude
Copy link
Collaborator

I don't think we need to set invoked-script for -m. This also doesn't happen in babashka:

borkdude@m1 /tmp $ echo '(ns foo) (defn -main [& args] (prn (System/getProperty "babashka.file")))' > foo.clj
borkdude@m1 /tmp $ bb -cp . -m foo
nil

The reason it's not set is that invoked-script or (System/getProperty "babashka.file") is for causing side effects when the script is directly invoked.

@bolivier
Copy link
Contributor Author

It seems like the same use cases would apply to both situations, no?

@borkdude
Copy link
Collaborator

No, since a -main function doesn't cause any side effects, unless you execute it manually, which is not the case when you invoke nbb with -m.

@borkdude
Copy link
Collaborator

Tests are failing, but the rest looks good to me

@borkdude
Copy link
Collaborator

Tests still fail, I think you need a quote around the vector in require. Perhaps consider running tests locally.

@borkdude
Copy link
Collaborator

Cool! And the last bit, can you update the changelogs? Then I'll merge

@borkdude borkdude merged commit 6a898bf into babashka:main Mar 31, 2023
@borkdude
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants