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

MAINT: Possible redundant code in util.which() #1454

Open
refack opened this issue Jan 3, 2025 · 2 comments
Open

MAINT: Possible redundant code in util.which() #1454

refack opened this issue Jan 3, 2025 · 2 comments

Comments

@refack
Copy link

refack commented Jan 3, 2025

IIUC most of

asv/asv/util.py

Lines 200 to 232 in 4c31eda

__tracebackhide__ = operator.methodcaller('errisinstance', OSError)
if os.path.sep in filename:
locations = ['']
elif paths is not None:
locations = paths
else:
locations = os.environ.get("PATH", "").split(os.pathsep)
if WIN:
# On windows, an entry in %PATH% may be quoted
locations = [path[1:-1] if len(path) > 2 and path[0] == path[-1] == '"' else path
for path in locations]
if WIN:
filenames = [filename + ext for ext in ('.exe', '.bat', '.com', '')]
else:
filenames = [filename]
candidates = []
for location in locations:
for filename in filenames:
candidate = os.path.join(location, filename)
if os.path.isfile(candidate) or os.path.islink(candidate):
candidates.append(candidate)
if len(candidates) == 0:
if paths is None:
loc_info = 'PATH'
else:
loc_info = os.pathsep.join(locations)
raise OSError(f"Could not find '{filename}' in {loc_info}")
return candidates[0]
cloud be replaced with a call to shutil.which. Just need the raise semantics and temporarily fudging os.envison['PATH'] == locations.

Is there any lore about this specific implementation?

@HaoZeke
Copy link
Member

HaoZeke commented Jan 5, 2025

None that I can think of, but most likely just historical baggage, shutil.which was added in 3.3 and asv used to support 2.7 for a long time.

A PR would be most welcome :)

@HaoZeke HaoZeke changed the title Possible redundant code in util.which() MAINT: Possible redundant code in util.which() Jan 5, 2025
@refack
Copy link
Author

refack commented Jan 6, 2025

A PR would be most welcome :)

On it 😊

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

No branches or pull requests

2 participants