Skip to content

Make finding home directory more general - #10570

Merged
taldcroft merged 2 commits into
astropy:masterfrom
dstansby:home-finding
Aug 23, 2020
Merged

taldcroft merged 2 commits into
astropy:masterfrom
dstansby:home-finding

Conversation

@dstansby

Copy link
Copy Markdown
Contributor

In sunpy we are seeing CI failures due to astropy not being able to find the home directory on macos: https://dev.azure.com/sunpy/sunpy/_build/results?buildId=8869&view=logs&jobId=6e7bd578-a810-548b-8fbf-8fa6b1a2d4f6&j=8b26c057-390d-57e7-9a94-ed463b57befe&t=7cf2f17d-5054-541f-491b-2e6078562aef

This seems to be because the 'HOME' environment variable isn't set. This PR makes finding home more lenient by trying to use os.path.expanduser('~') as a backup if the 'HOME' environment variable isn't set. This is in line with what IPython now do, which according to the comments this function is based on
https://github.com/ipython/ipython/blob/f8c9ea7db42d9830f16318a4ceca0ac1c3688697/IPython/utils/path.py#L190

@astropy-bot astropy-bot Bot added the config label Jul 15, 2020
Comment thread astropy/config/paths.py
else:
raise OSError('Could not find unix home directory to search for '
'astropy config dir')
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this entire function be effectively replaced by os.expanduser('~')? This claims to be applicable for all platforms so it seems best to delegate to this core library function. I guess it isn't clear if all the custom logic below for Windows is reflected in that function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at the code for expanduser it takes a very different approach and uses the pwd module (password database) to get the home directory if HOME is not defined. That seems at first glance reliable, maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it could - I took the current approach to maintain any previous behaviour, but in ipython they just use os.expanduser. If there's openess to changing it I'm happy to modify in that direction?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recall that @embray had good Windows knowledge back in the day. Git blame confirms that some of the code came from @embray. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not exactly sure what you're asking me, but IIRC using os.expanduser on Windows is reasonable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 if there is consensus that os.expanduser('~') is a reasonable approach to take then I will change the PR and see if CI is happy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@embray - my question is whether we can replace the entire _get_home code with a single line return os.expanduser('~'). Are all those special cases on Windows still necessary or are they a relic of how things were 10 years ago?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there any chance this change can be merged (to fix the issues we are having in sunpy, whilst definitely maintaining back-compat), and discussion about whether to replace the whole function with os.path.expanduser('~') moved to a new issue?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, good plan, sorry for the delay. Can you open that issue? For merging this needs a bugfix changelog entry indicating fix of problems in MacOS with no HOME dir var. I can't see any reason not to backport to LTS, so put it in the 4.0.2 section.

@pllim pllim added this to the v4.2 milestone Jul 15, 2020
@pllim

pllim commented Jul 15, 2020

Copy link
Copy Markdown
Member

Not sure why CI not kicking off properly. Maybe a change log under "API change" in 4.2? Is there a way to add a test?

@taldcroft

Copy link
Copy Markdown
Member

@pllim - do you agree this could be called a bug fix and go to LTS 4.0.2?

@taldcroft

taldcroft commented Aug 19, 2020 •

Copy link
Copy Markdown
Member

For testing, maybe a test could temporarily unset HOME to exercise the new functionality? (Or whatever configuration is needed to force getting into that branch).

@pllim pllim added Bug and removed Enhancement labels Aug 19, 2020
@pllim pllim modified the milestones: v4.2, v4.0.2 Aug 19, 2020
@pllim

pllim commented Aug 19, 2020

Copy link
Copy Markdown
Member

Milestone moved. Needs a change log. Thanks! 😄

@dstansby

Copy link
Copy Markdown
Contributor Author

👍 changelog added

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For code coverage I'm not sure how you can get that expanduser() call to fail to exercise the exception handling. So I'm going to call this good enough. Thanks @dstansby!

@taldcroft
taldcroft merged commit 6f3946b into astropy:master Aug 23, 2020
@dstansby
dstansby deleted the home-finding branch August 24, 2020 09:45
astrofrog pushed a commit that referenced this pull request Oct 6, 2020
Make finding home directory more general
astrofrog pushed a commit that referenced this pull request Oct 6, 2020
Make finding home directory more general
eteq pushed a commit to eteq/astropy that referenced this pull request Oct 12, 2020
Make finding home directory more general
eteq pushed a commit that referenced this pull request Oct 13, 2020
Make finding home directory more general
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants