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 support for scie base value placeholders. #137

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

jsirois
Copy link
Collaborator

@jsirois jsirois commented Sep 6, 2023

Both the lift manifest scie.lift.base field and the SCIE_BASE env
var now have their values expanded, accepting all placeholders except
for the {scie.lift} which depends on the fully evaluated value of the
scie base.

In order to make OS-convention-friendly values feasible, a new
{scie.user.cache_dir=<fallback>} placeholder is added that expands to
the OS-appropriate user cache dir when defined and <fallback> when
not.

Both the lift manifest `scie.lift.base` field and the `SCIE_BASE` env
var now have their values expanded, accepting all placeholders except
for the `{scie.lift}` which depends on the fully evaluated value of the
scie base.

In order to make OS-convention-friendly values feasible, a new
`{scie.user.cache_dir=<fallback>}` placeholder is added that expands to
the OS-appropriate user cache dir when defined and `<fallback>` when
not.
@jsirois
Copy link
Collaborator Author

jsirois commented Sep 6, 2023

Although this is not needed by Pants (yet), this was prompted by a-scie/lift#41. In the event Pants switches from a Mac (and Windows) unfriendly ~/.cache/pants dir, then this will be useful to get a proper custom cache dir appropriate to the OS.

structure in the form of `{scie.user.cache_dir=<fallback>}`. Typically, this placeholder will expand
to `~/Library/Caches` on macOS, `~\AppData\Local` on Windows and `~/.cache` on all other Unix
systems unless over-ridden via OS-specific means or else unavailable for some reason, in which case
the supplied `<fallback>` is used.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've been mis-reading this a few times.

unless over-ridden via OS-specific means or else unavailable for some reason, in which case the supplied <fallback> is used.

Using Linux as an example:

Without SCIE_BASE we default to ~/.cache, and if that is unavailable - we use the fallback (if provided)?

With SCIE_BASE=/tmp/myfolder, we attempt to use /tmp/myfolder, and if that is unavailable, we use fallback (if provided)?

Am I understanding this correctly?

Copy link
Collaborator Author

@jsirois jsirois Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but your example is off. What you describe is true if and only if the custom base value (specified via config or env var) uses the {scie.user.cache_dir=<fallback>} placeholder in it's value string somewhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the notes below:

{scie.user.cache_dir=<fallback>}: The default user cache dir or <fallback> if there is none.

So, this "fallback" is always provided, either as a default value or custom?

This was how I assumed it would work, but I think the wording above threw me for a loop maybe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must fill in a value in place of fallback. See the test: #137 (comment)

If you don't supply a fallback that's a hard error. The dirs::cache_dir() API is fallible. I'm not sure why, but that implies calculating a value can fail; this is exactly why I force you to supply a fallback value when using the placeholder.

let lift = Lift {
name: "test".to_string(),
description: None,
base: Some(tempdir.path().to_path_buf()),
base: Some(
PathBuf::from("{scie.user.cache_dir={scie.env.USER_CACHE_DIR=/tmp/nce}}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sureshjoshi this is the new test section to expand and study to see the placeholder in use.

@jsirois
Copy link
Collaborator Author

jsirois commented Sep 6, 2023

@sureshjoshi if you can supply alternate words for the doc portions of this change that make the new placeholder use more clear, I'd be happy to avoid confusing more people going forward.

@sureshjoshi
Copy link
Collaborator

Nah, that's okay - I think I just have a fuzzy brain this morning.

@jsirois
Copy link
Collaborator Author

jsirois commented Sep 6, 2023

Alright, thanks @sureshjoshi. I'll land this and get a release out before I disappear until about next week this time. I'll see if I can get out a quick science release that upgrades the default scie-jump and has expanded docs for the base lift manifest field over there.

@jsirois jsirois merged commit 71d2a9d into a-scie:main Sep 6, 2023
@jsirois jsirois deleted the base/placeholders branch September 6, 2023 15:50
@jsirois
Copy link
Collaborator Author

jsirois commented Sep 6, 2023

Hrm, ok. I forgot science uses latest scie-jump by default unless you pin a version; so I won't be doing a new science release - it's good to go.

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