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
feat(install): add support for --unsafe
install flag
#1008
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Rajdeep Malakar <rajdeepm.dev@gmail.com>
Signed-off-by: Rajdeep Malakar <rajdeepm.dev@gmail.com>
Signed-off-by: Rajdeep Malakar <rajdeepm.dev@gmail.com>
Signed-off-by: Rajdeep Malakar <rajdeepm.dev@gmail.com>
…ts nested package caches from failing)
Changed the |
const found = value.match(/^\s*exec pkgx \+([^ ]+)/)?.[1] | ||
const found = value.match(/^\s*pkgx \+([^ ]+)/)?.[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be dangerous, since it would catch a script with #!/usr/bin/env pkgx +python ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some other way of detecting both normal and unsafe packages? We can use special regex to match maybe both exec pkgx
OR some other unsafe-specific (non-pkgx
) match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this instance. at least, you could search for ${pkgstr}.env
. that should be unique to your shim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, stat ~/.local/cache/pkgx/envs/${pkgstr}.env
, and if it exists, and that has pkgx
in it, consider it to be installed via PKGX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if instead, unsafe installations contain a specific line (like PKGX_UNSAFE=1
) and check that? Unlike safe (normal) installations, we have full control over how the scripts are gonna be, and there's no backwards compatibility requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i meant that the script should contain the string ${pkgstr}.env
, since they source it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that could be done. Probably with regex as well.
@@ -89,6 +91,9 @@ export default function(input: string[]): Args { | |||
case 'update': | |||
flags.update = true | |||
break | |||
case 'unsafe': | |||
flags.unsafe = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could simplify ENV handling by moving it here; i don't know if we do that otherwise (as with, say, verbosity or debug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No other option uses ENV yet. So, it would have been overkill, probably. Maybe I can follow-up with a PR adding ENV options for other flags (PKGX_VERBOSITY
etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth starting a discussion about, definitely. experience teaches us that there are sometimes unwritten design principles at play; though, in general, providing for either flag or env control allows a wider variety of use-cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so we should prioritise flags, right? So, if a flag is unset, only then it'll check the env. If that's fine, I'll do a PR for that after this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think either being set means we do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about PKGX_UNSAFE_INSTAL=0
? It means false, so we shouldn't consider it to be set. And if it's this, we should check for the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think if either --unsafe or PKGX_UNSAFE_INSTALL != 0, then we do an unsafe install. PKGX_UNSAFE_INSTALL=0 should basically do nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, the env should take priority?
Then, it needs to be like:
function is_unsafe(unsafe: boolean): boolean {
const env = Deno.env.get("PKGX_UNSAFE_INSTALL");
if (env) {
// If present, it takes priority
return parseInt(env) ? true : false;
} else {
// Otherwise, check flag
return unsafe;
}
}
@jhheider It seems to be okay, but I'm not in PC rn (it's 1:02AM here lol). Can you try it now please, if possible? |
bugs in the script, but i can add a commit to fix them. |
but the speed looks good:
|
Thanks. Sucks to be without laptop/PC, lol. Anyways, thanks again. |
Is that right after doing the install, or after doing an initial run? It caches only at the first run, so subsequent runs should be faster than the first one. And the first one might interfere with the rest. |
No, I mean if either is set, it should be on. Which is the way you have it, I believe. Setting the envvar to zero shouldn't do anything. |
By shouldn't do anything, do you mean it should ignore that? So, if that's set, regardless of its value, it should do an unsafe install? |
If yes, it gets simpler: function is_unsafe(unsafe: boolean): boolean {
return Deno.env.get("PKGX_UNSAFE_INSTALL") || unsafe;
} |
No. If it's non-zero, or the --unsafe flag is passed, it should do an unsafe install. If the envvar is zero, it has no effect one way or the other. |
The default behaviour (without any env or flag) is to install normally. So,
if the env is set to 0, it should do that? Sorry for sounding like an idiot.
…On Wed, 15 May, 2024, 8:14 pm Jacob Heider, ***@***.***> wrote:
So, if that's set, regardless of its value, it should do an unsafe install?
No. If it's non-zero, or the --unsafe flag is passed, it should do an
unsafe install. If the envvar is zero, it has no effect one way or the
other.
—
Reply to this email directly, view it on GitHub
<#1008 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATXDOIZKEBPBKQ6ZCQFUVFDZCNYEJAVCNFSM6AAAAABHSDC4DWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJSG42DCNRYHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Exactly. Setting it 0 is the same as not setting it. So, it doesn't affect behavior. If it's set to 0 and the flag is passed it's unsafe. If it's 0 and no flag, then safe. Set to 0 is a no-op. |
So, this: function is_unsafe(unsafe: boolean): boolean {
const env = parseInt(Deno.env.get("PKGX_UNSAFE_INSTALL") || "0") ? true : false;
return env || unsafe;
} With this, there are six possible combinations:
|
@jhheider implemented it, is it okay? If so, can you please test that the env works as expected? (It probably does, but still a test is a good idea) |
right, i don't think that changed anything. your original implementation checked the truth value of the env || the flag. so, it should still be working correctly. |
looks like good work |
closes #997
closes #991
This PR adds support for the
--unsafe
install flag to PKGX, which, as proposed by @jhheider (thanks!), creates additional env stubs for a package on the first run, making subsequent runs make use of the already installed binaries, thus making it faster[1].The stub
As for the stub, it makes it a bit different, for instance, here's a "safe"
node
wrapper (installed normally):And here's the "unsafe" (as in experimental)
node
wrapper:Additional changes
Additionally, this PR also makes the following behavioural changes to PKGX:
pkgx uninstall
now also removes the env stub of the packagepkgx install
now checks forpkgx
(instead ofexec pkgx
) in a script to consider it as installed by PKGX (because unsafe installations don't useexec pkgx
)Usage
To do an unsafe installation, there are two options:
--unsafe
flag (e.gpkgx install --unsafe node
)PKGX_UNSAFE_INSTALL
environmental variable.In the presence of either, the
--unsafe
flag takes precedence.Caveats
This approach doesn't come without any caveat. It's necessary to document them upon having such a functionality.
As per my knowledge, these are the known issues:
Most (if not all) of them error correctly and offer (potentially) helpful error messages.
[1]