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

Expand variables for working directory and adjust Windows default path #212

Merged
merged 6 commits into from
May 21, 2024

Conversation

marcoesters
Copy link
Contributor

Description

This PR fixes two bugs:

  1. Environment variables are permitted for working_dir, but are not expanded. If working_dir is set to, e.g, %USERPROFILE%\workdir on Windows, menuinst would create a literal %USERPROFILE%\workdir path directory instead of %SYSTEMDRIVE%\Users\%USERNAME%\workdir. Expand these variables to create the correct directory name.
  2. The bug reported by %HOMEPATH% does not contain the drive name #211. %HOMEPATH% alone does not contain a drive, which can fail if %HOMEDRIVE% is not C:. This PR uses a default directory that contains the drive name.

The second item is up for debate. The menuinst documentation describes that working_dir defaults to the user's home directory. On Windows, there can be two different interpretations: %USERPROFILE% or %HOMEDRIVE%%HOMEPATH%.

I decided to go with a precedent: os.path.expanduser checks if %USERPROFILE% is set and goes with %HOMEDRIVE%%HOMEPATH% otherwise. pathlib.Path.home() uses the same implementation, so I think menuinst should use the same definition as the Python ecosystem.

Instead of using os.path.expanduser("~"), I am using the names of the variables though to make the shortcuts be resolved at runtime instead of hard-coding the directories.

Closes #211

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label May 16, 2024
@marcoesters marcoesters marked this pull request as ready for review May 16, 2024 21:48
@marcoesters marcoesters requested a review from a team as a code owner May 16, 2024 21:48
@marcoesters marcoesters merged commit da8133f into conda:main May 21, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

%HOMEPATH% does not contain the drive name
3 participants