ofek / userpath

Cross-platform tool for adding locations to the user PATH, no elevated privileges required!
MIT License
151 stars 20 forks source link

`userpath.in_current_path(os.getcwd())` always returns True on Windows. #45

Closed Vuizur closed 11 months ago

Vuizur commented 1 year ago

It does this even if the current working directory is not in PATH. (Feel free to correct me if this is intended behaviour.)

Thanks a lot for developing this library!

Vuizur commented 1 year ago

It looks like this would fix it. I could open a PR if you agree:

def location_in_path(location, path):
    return normpath(location) in (normpath(p) for p in path.split(os.pathsep) if p != '')

The PATH ends with ; - the split function returns "" as the last item of the array, which is then normalized using normpath to the user's current path.