Skip to content

Commit fcbb5c6

Browse files
Merge pull request #61 from cswartzvi/fix_windows_executable_search
Update windows path separator in executable search
2 parents 62ab273 + 6a06912 commit fcbb5c6

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

condax/conda.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def package_name(package_spec: str):
120120
return m.group(0)
121121

122122

123-
def detemine_executables_from_env(
123+
def determine_executables_from_env(
124124
package: str, env_prefix: Optional[Path] = None
125125
) -> Set[Path]:
126126
if env_prefix is None:
@@ -131,24 +131,19 @@ def detemine_executables_from_env(
131131
package_info = json.loads(path.read_text())
132132
if package_info["name"] == name:
133133
logging.debug("Candidate files: %s", package_info["files"])
134-
potential_executables: List[str] = [
135-
fn
136-
for fn in package_info["files"]
137-
if (
138-
fn.startswith("bin/")
139-
or fn.startswith("sbin/")
140-
# They are Windows style path
141-
or (
142-
is_windows()
143-
and (
144-
fn.lower().startswith("scripts\\")
145-
or fn.lower().startswith("library\\mingw-w64\\bin\\")
146-
or re.match(r"library\\.*\\bin\\", fn.lower())
147-
)
148-
)
149-
)
150-
]
151-
# TODO: Handle windows style paths
134+
potential_executables: List[str] = []
135+
for fn in package_info["files"]:
136+
if is_windows():
137+
processed_fn = fn.lower().replace("\\", "/")
138+
if (
139+
processed_fn.startswith("scripts/")
140+
or processed_fn.startswith("library/mingw-w64/bin/")
141+
or re.match(r"library/.*/bin/", processed_fn)
142+
):
143+
potential_executables.append(fn)
144+
else:
145+
if fn.startswith("bin/") or fn.startswith("sbin/"):
146+
potential_executables.append(fn)
152147
break
153148
else:
154149
raise ValueError("Could not determine package files")

condax/core.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def install_package(
178178
if channels is None:
179179
channels = CONFIG.channels
180180
conda.create_conda_environment(package, channels=channels)
181-
executables_to_link = conda.detemine_executables_from_env(package)
181+
executables_to_link = conda.determine_executables_from_env(package)
182182
CONFIG.link_destination.mkdir(parents=True, exist_ok=True)
183183
create_links(
184184
executables_to_link,
@@ -204,7 +204,7 @@ def inject_packages(
204204
conda.install_conda_packages(extra_packages, channels=channels, prefix=prefix)
205205
if include_apps:
206206
for extra_package in extra_packages:
207-
executables_to_link = conda.detemine_executables_from_env(
207+
executables_to_link = conda.determine_executables_from_env(
208208
extra_package, env_prefix=prefix
209209
)
210210
CONFIG.link_destination.mkdir(parents=True, exist_ok=True)
@@ -236,7 +236,7 @@ def exit_if_not_installed(package: str):
236236

237237
def remove_package(package) -> None:
238238
exit_if_not_installed(package)
239-
executables_to_unlink = conda.detemine_executables_from_env(package)
239+
executables_to_unlink = conda.determine_executables_from_env(package)
240240
prefix = conda.conda_env_prefix(package)
241241
remove_links(executables_to_unlink, env_prefix=prefix)
242242
with prefix_metadata(prefix) as metadata:
@@ -268,16 +268,16 @@ def update_package(package: str, link_conflict_action=LinkConflictAction.ERROR)
268268
injected = metadata.injected_packages
269269
injected_with_apps = metadata.injected_packages_with_apps
270270
try:
271-
executables_already_linked |= set(conda.detemine_executables_from_env(package))
271+
executables_already_linked |= set(conda.determine_executables_from_env(package))
272272

273273
conda.update_conda_env(package)
274274
env_prefix = conda.conda_env_prefix(package)
275275
executables_linked_in_updated = set(
276-
conda.detemine_executables_from_env(package)
276+
conda.determine_executables_from_env(package)
277277
)
278278
for p in injected_with_apps:
279279
executables_linked_in_updated |= set(
280-
conda.detemine_executables_from_env(p, env_prefix=env_prefix)
280+
conda.determine_executables_from_env(p, env_prefix=env_prefix)
281281
)
282282

283283
to_create = executables_linked_in_updated - executables_already_linked

tests/test_condax.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_pipx_install_roundtrip(conf):
4343
assert post_install.startswith(conf["link"])
4444

4545
# ensure that the executable installed is on PATH
46-
subprocess.check_call(["jq", "--help"])
46+
subprocess.check_call(["jq", "--help"], shell=True)
4747

4848
# remove the env
4949
remove_package("jq")

0 commit comments

Comments
 (0)