Skip to content

Commit ad5edeb

Browse files
committed
Style fixes
1 parent 0134c8a commit ad5edeb

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_os.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
*graalpython.lib-python.3.test.test_os.PathTConverterTests.test_path_t_converter
101101
*graalpython.lib-python.3.test.test_os.PathTConverterTests.test_path_t_converter_and_custom_class
102102
*graalpython.lib-python.3.test.test_os.Pep383Tests.test_statvfs
103-
*graalpython.lib-python.3.test.test_os.PidTests.test_getppid
104103
*graalpython.lib-python.3.test.test_os.PidTests.test_waitpid_windows
105104
*graalpython.lib-python.3.test.test_os.PosixUidGidTests.test_setegid
106105
*graalpython.lib-python.3.test.test_os.PosixUidGidTests.test_seteuid
@@ -157,6 +156,8 @@
157156
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_fstat
158157
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_fstatvfs
159158
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_isatty
159+
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_lseek
160+
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_read
160161
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_readv
161162
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_tcgetpgrp
162163
*graalpython.lib-python.3.test.test_os.TestInvalidFD.test_tcsetpgrpt

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public void postInitialize(PythonCore core) {
272272
super.postInitialize(core);
273273

274274
// fill the environ dictionary with the current environment
275+
// TODO we should probably use PosixSupportLibrary to get environ
275276
Map<String, String> getenv = System.getenv();
276277
PDict environ = core.factory().createDict();
277278
String pyenvLauncherKey = "__PYVENV_LAUNCHER__";
@@ -289,8 +290,7 @@ public void postInitialize(PythonCore core) {
289290
Object k = posixLib.createPathFromString(posixSupport, pyenvLauncherKey);
290291
Object v = posixLib.createPathFromString(posixSupport, value);
291292
posixLib.setenv(posixSupport, k, v, true);
292-
} catch (PosixException e) {
293-
// TODO handle error
293+
} catch (PosixException ignored) {
294294
}
295295
} else {
296296
value = entry.getValue();
@@ -419,7 +419,7 @@ private void execv(VirtualFrame frame, PosixPath path, Object argv, SequenceStor
419419
for (int i = 0; i < args.length; ++i) {
420420
opaqueArgs[i] = toOpaquePathNode.execute(frame, args[i]);
421421
}
422-
//TODO ValueError "execv() arg 2 first element cannot be empty"
422+
// TODO ValueError "execv() arg 2 first element cannot be empty"
423423

424424
auditNode.audit("os.exec", path.originalObject, argv, PNone.NONE);
425425

@@ -1868,10 +1868,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
18681868
}
18691869

18701870
@Specialization
1871-
int system(VirtualFrame frame, PBytes command,
1872-
@Cached BytesNodes.ToBytesNode toBytesNode,
1873-
@Cached SysModuleBuiltins.AuditNode auditNode,
1874-
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
1871+
int system(PBytes command,
1872+
@Cached BytesNodes.ToBytesNode toBytesNode,
1873+
@Cached SysModuleBuiltins.AuditNode auditNode,
1874+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
18751875
// Unlike in other posix builtins, we go through str -> bytes -> byte[] -> String
18761876
// conversions for emulated backend because the bytes version after fsencode conversion
18771877
// is subject to sys.audit.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import static java.lang.Math.multiplyExact;
6262

6363
import java.io.BufferedReader;
64-
import java.io.File;
6564
import java.io.IOException;
6665
import java.io.InputStream;
6766
import java.io.InputStreamReader;
@@ -98,7 +97,6 @@
9897
import java.util.concurrent.TimeUnit;
9998
import java.util.logging.Level;
10099

101-
import com.oracle.truffle.api.TruffleLanguage.Env;
102100
import org.graalvm.nativeimage.ImageInfo;
103101
import org.graalvm.nativeimage.ProcessProperties;
104102
import org.graalvm.polyglot.io.ProcessHandler.Redirect;
@@ -129,6 +127,7 @@
129127
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
130128
import com.oracle.truffle.api.TruffleFile;
131129
import com.oracle.truffle.api.TruffleFile.Attributes;
130+
import com.oracle.truffle.api.TruffleLanguage.Env;
132131
import com.oracle.truffle.api.TruffleLogger;
133132
import com.oracle.truffle.api.dsl.Cached;
134133
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -251,6 +250,10 @@ public final class EmulatedPosixSupport extends PosixResources {
251250
public EmulatedPosixSupport(PythonContext context) {
252251
this.context = context;
253252
setEnv(context.getEnv());
253+
}
254+
255+
@Override
256+
public void postInitialize() {
254257
environ.putAll(System.getenv());
255258
}
256259

@@ -1835,19 +1838,26 @@ public int system(Object commandObj) {
18351838
return -1;
18361839
}
18371840
LOGGER.fine(() -> "os.system: " + cmd);
1838-
String[] command = new String[]{shell[0], shell[1], cmd};
1841+
1842+
String[] command;
1843+
String osProperty = System.getProperty("os.name");
1844+
if (osProperty != null && osProperty.toLowerCase(Locale.ENGLISH).startsWith("windows")) {
1845+
command = new String[]{"cmd.exe", "/c", cmd};
1846+
} else {
1847+
command = new String[]{(environ.getOrDefault("SHELL", "sh")), "-c", cmd};
1848+
}
18391849
Env env = context.getEnv();
18401850
try {
1841-
ProcessBuilder pb = new ProcessBuilder(command);
1842-
pb.directory(new File(env.getCurrentWorkingDirectory().getPath()));
1851+
TruffleProcessBuilder pb = context.getEnv().newProcessBuilder(command);
1852+
pb.directory(env.getCurrentWorkingDirectory());
18431853
PipePump stdout = null, stderr = null;
18441854
boolean stdsArePipes = !context.getOption(PythonOptions.TerminalIsInteractive);
18451855
if (stdsArePipes) {
1846-
pb.redirectInput(ProcessBuilder.Redirect.PIPE);
1847-
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
1848-
pb.redirectError(ProcessBuilder.Redirect.PIPE);
1856+
pb.redirectInput(Redirect.PIPE);
1857+
pb.redirectOutput(Redirect.PIPE);
1858+
pb.redirectError(Redirect.PIPE);
18491859
} else {
1850-
pb.inheritIO();
1860+
pb.inheritIO(true);
18511861
}
18521862
Process proc = pb.start();
18531863
if (stdsArePipes) {
@@ -1868,13 +1878,7 @@ public int system(Object commandObj) {
18681878
}
18691879
}
18701880

1871-
private static final String[] shell;
1872-
static {
1873-
String osProperty = System.getProperty("os.name");
1874-
shell = osProperty != null && osProperty.toLowerCase(Locale.ENGLISH).startsWith("windows") ? new String[]{"cmd.exe", "/c"}
1875-
: new String[]{(System.getenv().getOrDefault("SHELL", "sh")), "-c"};
1876-
}
1877-
1881+
// TODO merge with ProcessWrapper
18781882
static class PipePump extends Thread {
18791883
private static final int MAX_READ = 8192;
18801884
private final InputStream in;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/LoggingPosixSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ final String ctermid(@CachedLibrary("this.delegate") PosixSupportLibrary lib) th
698698

699699
@ExportMessage
700700
final void setenv(Object name, Object value, boolean overwrite,
701-
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
701+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
702702
logEnter("setenv", "%s, %s, %b", name, value, overwrite);
703703
try {
704704
lib.setenv(delegate, name, value, overwrite);
@@ -723,7 +723,7 @@ final int forkExec(Object[] executables, Object[] args, Object cwd, Object[] env
723723

724724
@ExportMessage
725725
final void execv(Object pathname, Object[] args,
726-
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
726+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
727727
logEnter("execv", "%s, %s", pathname, args);
728728
try {
729729
lib.execv(delegate, pathname, args);
@@ -734,7 +734,7 @@ final void execv(Object pathname, Object[] args,
734734

735735
@ExportMessage
736736
final int system(Object command,
737-
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
737+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
738738
logEnter("system", "%s", command);
739739
return logExit("system", "%d", lib.system(delegate, command));
740740
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ public void execv(Object pathname, Object[] args,
10911091

10921092
@ExportMessage
10931093
public int system(Object command,
1094-
@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
1094+
@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
10951095
return invokeNode.callInt(this, PosixNativeFunction.call_system, pathToCString(command));
10961096
}
10971097

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixSupport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ public abstract class PosixSupport {
4646
public void setEnv(@SuppressWarnings("unused") Env env) {
4747
// nop
4848
}
49+
50+
public void postInitialize() {
51+
}
4952
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ public void initialize() {
459459

460460
public void patch(Env newEnv) {
461461
setEnv(newEnv);
462+
posixSupport.postInitialize();
462463
setupRuntimeInformation(true);
463464
core.postInitialize();
464465
importSiteIfForced();

0 commit comments

Comments
 (0)