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

Stop assuming PATH env is defined when extra_paths is set, and then initialize to os.defpath #144

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

consideRatio
Copy link
Member

@consideRatio consideRatio commented Oct 20, 2024

I'm not sure if this is sufficient to resolve issues with using extra_paths together with jupyterhub 5.2.0 where env_keep doesn't include PATH in the Spawner base class any more, but it should probably be an incremental improvement no matter what.

See debugging notes in the littlest jupyterhub distribution when trying to upgrade jupyterhub from 5.1.0 to 5.2.0.

I've not added a test for extra_paths in this project, but it gets tested via tljh though, and via jupyterhub/the-littlest-jupyterhub#1008 I can see that this made a positive difference making tests pass where they previously failed.

@consideRatio
Copy link
Member Author

@minrk I'd like to go for a bugfix release with this PR to make tljh 5.2.0 compatible

Copy link
Member

@minrk minrk left a comment

Choose a reason for hiding this comment

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

Makes sense! One comment about using the standard default path, but go ahead once that's addressed.

),
)
new_path_list = [self._expand_user_vars(p) for p in self.extra_paths]
current_path = env.get("PATH")
Copy link
Member

Choose a reason for hiding this comment

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

If PATH is not defined, probably use os.defpath for the default value (env.get("PATH", os.defpath))

(Not a code suggestion because typed from my phone)

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
current_path = env.get("PATH")
current_path = env.get("PATH", os.defpath)

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be done without being conditional on extra_paths being set non-empty then, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've pushed 3d12e12 making us initialize PATH to os.defpath if unset, independently of if extra_paths has been set truthy or not.

Copy link
Member

Choose a reason for hiding this comment

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

I think this should only be for reading PATH. This is the same effective value if PATH is omitted, so we shouldn't need to add it if we're not setting PATH. It's only relevant when adding to PATH.

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed the comment you made because GitHub UI didn't refresh properly =/

Okay deal! We'll then let this only influence the situation when extra_paths is set and we are reading PATH to prepend extra_paths!

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for helping me with this @minrk!!!

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the path resolution on L159, it uses os.getenv(PATH, os.defpath), i.e. the Hub's PATH, but only for looking up jupyterhub-singleuser itself, and only if $PATH is unspecified for the unit. it doesn't affect the default PATH of the process.

So systemdspawner will find JupyterHub-singleuser if:

  • you specify PATH and jupyterhub-singleuser, or
  • you don't specify PATH at all

But not if you specify PATH to something without singleuser, which seems inconsistent.

I think behavior might be more consistent if we either:

  • never add Hub $PATH to the search for JupyterHub-singleuser (rely on correct PATH config of the systemd unit and/or absolute paths), or
  • always do (singleuser should always be found, with current env as lowest priority fallback, no matter what unit $PATH is)

so behavior is more consistent across config situations.

We could also change the default for unit $PATH to hub $PATH, but this has higher risk of impacting real deployments. It should be quite rare and usually a mistake to leave $PATH undefined in a systemd unit, especially for user servers. Unless the launch command is an initialization script that is responsible for setting up $PATH.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, I think there's an opportunity to clear a few things up and be more consistent, but that's its own task, not needed here. The surprising test failures here just raise the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've opened #146 to not loose track of this discussion.

@consideRatio consideRatio changed the title Stop assuming PATH env is defined when extra_paths is set Initialize unset PATH to os.defpath and stop assuming PATH env is defined when extra_paths is set Oct 20, 2024
@consideRatio consideRatio force-pushed the pr/fix-for-extra-paths branch from c0e3a1a to 3d12e12 Compare October 20, 2024 11:49
@consideRatio consideRatio force-pushed the pr/fix-for-extra-paths branch from 3d12e12 to fbddd86 Compare October 20, 2024 12:20
@consideRatio consideRatio changed the title Initialize unset PATH to os.defpath and stop assuming PATH env is defined when extra_paths is set Stop assuming PATH env is defined when extra_paths is set, and initialize to os.defpath if it happens Oct 20, 2024
@consideRatio consideRatio changed the title Stop assuming PATH env is defined when extra_paths is set, and initialize to os.defpath if it happens Stop assuming PATH env is defined when extra_paths is set, and then initialize to os.defpath Oct 20, 2024
@consideRatio consideRatio merged commit ba131ab into jupyterhub:main Oct 20, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants