Skip to content

Commit b4e8714

Browse files
committed
WIP: usability fixes
PullRequest: graalpython/3383
2 parents 72a756a + b4c59ca commit b4e8714

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

graalpython/com.oracle.graal.python.frozen/freeze_modules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,21 +587,21 @@ def write_frozen_lookup(out_file, modules):
587587

588588
def write_frozen_module_file(file, modules):
589589
if os.path.exists(file):
590-
with open(file, "r", encoding="utf-8") as f:
590+
with open(file, "r", encoding="utf-8", newline=os.linesep) as f:
591591
content = f.read()
592592
stat_result = os.stat(file)
593593
atime, mtime = stat_result.st_atime, stat_result.st_mtime
594594
else:
595595
content = None
596596
os.makedirs(os.path.dirname(file), exist_ok=True)
597-
with open(file, "w", encoding="utf-8") as out_file:
597+
with open(file, "w", encoding="utf-8", newline=os.linesep) as out_file:
598598
out_file.write(FROZEN_MODULES_HEADER)
599599
out_file.write("\n\n")
600600
write_frozen_modules_map(out_file, modules)
601601
out_file.write("\n")
602602
write_frozen_lookup(out_file, modules)
603603
out_file.write("}\n")
604-
with open(file, "r", encoding="utf-8") as f:
604+
with open(file, "r", encoding="utf-8", newline=os.linesep) as f:
605605
new_content = f.read()
606606
if new_content == content:
607607
# set mtime to the old one, if we didn't change anything

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
public class GraalPythonMain extends AbstractLanguageLauncher {
6868

69+
private static final boolean IS_WINDOWS = System.getProperty("os.name") != null && System.getProperty("os.name").toLowerCase().contains("windows");
70+
6971
private static final String SHORT_HELP = "usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" +
7072
"Try `python -h' for more information.";
7173

@@ -552,6 +554,25 @@ private String calculateProgramFullPath(String program, Function<Path, Boolean>
552554
return resolvedProgramName.toString();
553555
}
554556

557+
// On windows, the program name may be without the extension
558+
if (IS_WINDOWS) {
559+
String pathExtEnvvar = getEnv("PATHEXT");
560+
if (pathExtEnvvar != null) {
561+
// default extensions are defined
562+
String resolvedStr = resolvedProgramName.toString();
563+
if (resolvedStr.length() <= 3 || resolvedStr.charAt(resolvedStr.length() - 4) != '.') {
564+
// program has no file extension
565+
String[] pathExts = pathExtEnvvar.toLowerCase().split(";");
566+
for (String pathExt : pathExts) {
567+
resolvedProgramName = Path.of(resolvedStr + pathExt);
568+
if (isExecutable.apply(resolvedProgramName)) {
569+
return resolvedProgramName.toString();
570+
}
571+
}
572+
}
573+
}
574+
}
575+
555576
// next start is the char after the separator because we have "path0:path1" and
556577
// 'i' points to ':'
557578
previous = i + 1;
@@ -768,8 +789,7 @@ protected void launch(Builder contextBuilder) {
768789
contextBuilder.option("python.PyCachePrefix", cachePrefix);
769790
}
770791

771-
String osName = System.getProperty("os.name");
772-
if (osName != null && osName.toLowerCase().contains("windows")) {
792+
if (IS_WINDOWS) {
773793
contextBuilder.option("python.PosixModuleBackend", "java");
774794
}
775795

mx.graalpython/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@
982982
"sdk:LAUNCHER_COMMON",
983983
"sdk:JLINE3",
984984
"sdk:MAVEN_DOWNLOADER",
985+
"sdk:NATIVEIMAGE",
985986
],
986987
"description": "GraalPython launcher",
987988
"maven": {

0 commit comments

Comments
 (0)