Skip to content

Commit 00092f9

Browse files
committed
Python debugger (WIP)
1 parent 7b7d9c6 commit 00092f9

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/main/java/org/netbeans/modules/python/actions/PythonRun.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.netbeans.api.extexecution.ExecutionService;
1111
import org.netbeans.api.project.Project;
1212
import org.netbeans.modules.python.PythonOutputLine;
13-
import org.netbeans.modules.python.PythonProject;
13+
import org.netbeans.modules.python.project.PythonProject;
1414
import org.netbeans.modules.python.PythonUtility;
1515
import org.openide.LifecycleManager;
1616
import org.openide.awt.StatusDisplayer;
@@ -28,12 +28,28 @@ public class PythonRun {
2828
public static final Logger LOG = Logger.getLogger(PythonRun.class.getName());
2929

3030
@NbBundle.Messages("CTL_Run=Running Python")
31-
static public void runAction(Project owner, DataObject context) {
31+
static public void runAction(Project owner, DataObject context, boolean isDebug) {
3232

3333
ProcessBuilder pb = new ProcessBuilder();
34-
pb.directory(FileUtil.toFile(context.getPrimaryFile().getParent()));
34+
pb.directory(owner != null ? FileUtil.toFile(owner.getProjectDirectory())
35+
: FileUtil.toFile(context.getPrimaryFile().getParent()));
3536
PythonUtility.manageRunEnvs(pb);
3637

38+
List<String> argList = getRunArgs(owner, context, isDebug);
39+
pb.command(argList);
40+
41+
ExecutionService service = ExecutionService.newService(() -> pb.start(),
42+
PythonUtility.getExecutorDescriptor(
43+
new PythonOutputLine(), () -> {
44+
StatusDisplayer.getDefault().setStatusText(Bundle.CTL_Run());
45+
LifecycleManager.getDefault().saveAll();
46+
}, () -> {
47+
}, true, true), String.format("%s%s%s", "Run (", context.getPrimaryFile().getNameExt(), ")"));
48+
49+
service.run();
50+
}
51+
52+
public static List<String> getRunArgs(Project owner, DataObject context, boolean isDebug) {
3753
String[] params = {};
3854
List<String> argList = new ArrayList<>();
3955
try {
@@ -45,7 +61,7 @@ static public void runAction(Project owner, DataObject context) {
4561
.split(" ");
4662
}
4763
}
48-
if (owner != null && PythonUtility.isPoetry((PythonProject) owner)) {
64+
if (owner != null && PythonUtility.isPoetry((PythonProject) owner) && !isDebug) {
4965
argList.addAll(Arrays.asList(PythonUtility
5066
.getProjectPythonExe(context
5167
.getPrimaryFile()), "-m", "poetry", "run", "python",
@@ -58,22 +74,13 @@ static public void runAction(Project owner, DataObject context) {
5874
}
5975

6076
argList.addAll(Arrays.asList(params));
61-
pb.command(argList);
6277

6378
LOG.info(() -> Arrays.toString(argList.toArray()));
79+
return argList;
6480

6581
} catch (IOException ex) {
6682
Exceptions.printStackTrace(ex);
6783
}
68-
69-
ExecutionService service = ExecutionService.newService(() -> pb.start(),
70-
PythonUtility.getExecutorDescriptor(
71-
new PythonOutputLine(), () -> {
72-
StatusDisplayer.getDefault().setStatusText(Bundle.CTL_Run());
73-
LifecycleManager.getDefault().saveAll();
74-
}, () -> {
75-
}, true, true), String.format("%s%s%s", "Run (", context.getPrimaryFile().getNameExt(), ")"));
76-
77-
service.run();
84+
return null;
7885
}
7986
}

0 commit comments

Comments
 (0)