Skip to content

add option to respect platform's cache directories #251

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jesteria
Copy link

@jesteria jesteria commented Feb 14, 2024

…Rather than use a static path like ~/.cache/ (via --root) or ~/.shiv (the default).

The added shiv build option --platform-root will enable runtime determination of the platform- and executable-appropriate cache directory:

  1. If the archive is understood to be globally-installed on the platform, and a known system-wide cache (such as /var/cache/) is already populated or writable by the current user, then this will be used.

  2. If the platform is understood to feature a user-dedicated cache (such as ~/.cache/) – or specifies one via environment variable (such as XDG_CACHE_HOME) – then this will be used.

  3. Otherwise, ~/.shiv will be used.

And, in cases (1) and (2), the cache root directory will be named according to the name of the archive – not referencing the toolset which created it (namely shiv) – for example...

Linux:

  • /var/cache/cowsay/cowsay_3.03/site-packages/
  • ~/.cache/cowsay/cowsay_3.03/site-packages/

Darwin / OS X:

  • /Library/Caches/cowsay/cowsay_3.03/site-packages/
  • ~/Library/Caches/cowsay/cowsay_3.03/site-packages/

Windows:

  • ~/AppData/Local/cowsay/cowsay_3.03/site-packages/

I'll note that I've followed the shiv issues on this and understand that this might not be of interest to pull – particularly now that an alternative root can be specified at build time via --root.

However, it's my impression that this functionality enables a shiv-built executable to do a significantly better job meeting the installation platform's expectations, at least on the systems I'm targeting, (and as a bonus without additional build-time configurations). As such, this is the functionality I'd prefer, by a long shot; and, I'd guess there's a not-insignificant number out there who would appreciate this, as well. Adding this as an "opt-in" feature – only enabled by build flag – seems appropriate, to me.

Cheers.


See also: #141, #142.

…~/.shiv

shiv build option `--platform-root` will enable runtime determination of
platform- and executable-appropriate cache directory:

1. If the archive is understood to be globally-installed on the platform,
   and a known system-wide cache (such as `/var/cache/`) is already
   populated or writable by the current user, then this will be used.

2. If a platform is understood to feature a user-dedicated cache (such
   as `~/.cache/`) -- or specifies one via environment variable (such as
   `XDG_CACHE_HOME`) -- then this will be used.

3. Otherwise, `~/.shiv` will be used.

And, in cases (1) and (2), the cache root directory will be named
according to the name of the archive -- *not* referencing the toolset
which created it (namely shiv) -- for example...

Linux:

  * /var/cache/cowsay/cowsay_3.03/site-packages/
  * ~/.cache/cowsay/cowsay_3.03/site-packages/

Darwin / OS X:

  * /Library/Caches/cowsay/cowsay_3.03/site-packages/
  * ~/Library/Caches/cowsay/cowsay_3.03/site-packages/

Windows:

  * ~/AppData/Local/cowsay/cowsay_3.03/site-packages/
@jesteria jesteria changed the title add option to abide by XDG cache directory specification *dynamically* add option to respect platform's cache directories Feb 28, 2024
@jesteria
Copy link
Author

Update: In appreciation of #242 this has been expanded to a --platform-root option, which attempts to respect the expectations of OS X and Windows, (rather than merely those of Linux or XDG).

Importantly, I think, this changeset additionally:

  • considers whether the executable has been globally installed and a system-wide cache is available (e.g. installed as /usr/bin/cowsay and /var/cache/cowsay/ is populated or writable)
  • when writing to a platform-customary location, uses the name of the executable archive rather than the name "shiv" (e.g. /var/cache/cowsay/ or ~/.cache/cowsay/)

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.

1 participant