Skip to content

Commit 9637af5

Browse files
committed
Fix Poetry Project Creation
Proper Fix for Python 2.7 Redirecting sdtErr to stdOut Skip Python 2 Debugging for now
1 parent c7db319 commit 9637af5

18 files changed

+48
-43
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@
749749
<properties>
750750
<dev.name>albilu</dev.name>
751751
<netbeans.release.version>RELEASE170</netbeans.release.version>
752-
<next.version>0.5</next.version>
752+
<next.version>0.6</next.version>
753753
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
754754
</properties>
755755
</project>

src/main/java/org/netbeans/modules/python/PythonSources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public SourceGroup[] getSourceGroups(String type) {
4545
return new SourceGroup[0];
4646
}
4747
try {
48-
Properties prop = PythonUtility.getProperties(project);
48+
Properties prop = PythonUtility.getProperties(project, false);
4949
String tfo = prop.getProperty("nbproject.test.dir", "tests");
5050
ProjectInformation information = ProjectUtils.getInformation(project);
5151
FileObject fo = StringUtils.equalsAny(tfo, "", "tests") ? project.getProjectDirectory()

src/main/java/org/netbeans/modules/python/PythonUtility.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public static String getCommandOutput(String[] cmd, FileObject projectDir) throw
156156
if (projectDir != null) {
157157
p.directory(FileUtil.toFile(projectDir));
158158
}
159-
return IOUtils.toString(p.start().getInputStream(), StandardCharsets.UTF_8).strip();
159+
return IOUtils.toString(p.redirectErrorStream(true).start().getInputStream(),
160+
StandardCharsets.UTF_8).strip();
160161
}
161162

162163
public static String getPythonStdLibPath(String path) throws IOException {
@@ -262,10 +263,10 @@ public static ImageIcon getPynguinIcon() {
262263

263264
}
264265

265-
public static Properties getProperties(@NonNull Project project) throws IOException {
266+
public static Properties getProperties(@NonNull Project project, boolean isCreating) throws IOException {
266267

267268
Properties prop = new Properties();
268-
if (OpenProjects.getDefault().isProjectOpen(project)) {
269+
if (OpenProjects.getDefault().isProjectOpen(project) || isCreating) {
269270
File file = createProperties(project);
270271
prop.load(new FileInputStream(file));
271272
}
@@ -274,12 +275,7 @@ public static Properties getProperties(@NonNull Project project) throws IOExcept
274275
}
275276

276277
public static String getVersion(String projectPythonExe) throws IOException {
277-
String commandOutput = getCommandOutput(new String[]{projectPythonExe, "--version"}, null);
278-
//Python 2 print CLI output to stderr instead of stdout causing the version to not be retrieved
279-
if (commandOutput.isEmpty() && projectPythonExe.contains("python2")) {
280-
commandOutput = "Python 2";
281-
}
282-
return commandOutput;
278+
return getCommandOutput(new String[]{projectPythonExe, "--version"}, null);
283279
}
284280

285281
public static ImageIcon getErrorIcon() {
@@ -491,7 +487,7 @@ public static void manageRunEnvs(ProcessBuilder pb) {
491487

492488
public static String getVenv(PythonProject get) {
493489
try {
494-
return getProperties(get).getProperty("nbproject.virtualmanager", "venv");
490+
return getProperties(get, false).getProperty("nbproject.virtualmanager", "venv");
495491
} catch (IOException ex) {
496492
Exceptions.printStackTrace(ex);
497493
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.netbeans.api.extexecution.ExecutionService;
1212
import org.netbeans.api.project.Project;
1313
import org.netbeans.modules.python.PythonOutputLine;
14-
import org.netbeans.modules.python.project.PythonProject;
1514
import org.netbeans.modules.python.PythonUtility;
15+
import org.netbeans.modules.python.project.PythonProject;
1616
import org.openide.LifecycleManager;
1717
import org.openide.awt.StatusDisplayer;
1818
import org.openide.filesystems.FileObject;
@@ -43,7 +43,7 @@ public static void runAction(Project owner, FileObject context) {
4343
String[] params = {};
4444
List<String> argList = new ArrayList<>();
4545
if (owner != null) {
46-
Properties prop = PythonUtility.getProperties(owner);
46+
Properties prop = PythonUtility.getProperties(owner, false);
4747
if (!prop.getProperty("nbproject.build.params", "").isEmpty()) {
4848
params = prop.getProperty("nbproject.build.params", "")
4949
.split(" ");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void actionPerformed(ActionEvent ev) {
5151
try {
5252
String[] params = {};
5353
List<String> argList = new ArrayList<>();
54-
Properties prop = PythonUtility.getProperties(context);
54+
Properties prop = PythonUtility.getProperties(context, false);
5555
params = prop.getProperty("nbproject.pdoc.params", "-o docs")
5656
.split(" ");
5757
List<String> asList1 = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void runAction(DataObject context) {
4848
try {
4949
Project owner = FileOwnerQuery.getOwner(primaryFile);
5050
if (owner != null) {
51-
Properties prop = PythonUtility.getProperties(owner);
51+
Properties prop = PythonUtility.getProperties(owner, false);
5252
if (!prop.getProperty("nbproject.test.generator.params", "")
5353
.isEmpty()) {
5454
params = prop.getProperty("nbproject.test.generator.params", "")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
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.project.PythonProject;
1413
import org.netbeans.modules.python.PythonUtility;
14+
import org.netbeans.modules.python.project.PythonProject;
1515
import org.openide.LifecycleManager;
1616
import org.openide.awt.StatusDisplayer;
1717
import org.openide.filesystems.FileUtil;
@@ -55,7 +55,7 @@ public static List<String> getRunArgs(Project owner, DataObject context, boolean
5555
try {
5656
//Project owner = FileOwnerQuery.getOwner(context.getPrimaryFile());
5757
if (owner != null) {
58-
Properties prop = PythonUtility.getProperties(owner);
58+
Properties prop = PythonUtility.getProperties(owner, false);
5959
if (!prop.getProperty("nbproject.run.params", "").isEmpty()) {
6060
params = prop.getProperty("nbproject.run.params", "")
6161
.split(" ");

src/main/java/org/netbeans/modules/python/debugger/PythonDebugger.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public static void startDebugger(Project owner, DataObject dob, boolean singleFi
6464
try {
6565
List<String> runArgs = PythonRun.getRunArgs(owner, dob, true);
6666

67+
if (runArgs.isEmpty() || runArgs.get(0).contains("Python 2")) {
68+
DialogDisplayer.getDefault().notify(
69+
new NotifyDescriptor.Message("Python 2 Debugging not supported at the moment",
70+
NotifyDescriptor.INFORMATION_MESSAGE));
71+
return;
72+
}
73+
6774
String sessionName = owner != null && !singleFile ? ProjectUtils
6875
.getInformation(owner).getDisplayName()
6976
: dob.getPrimaryFile().getNameExt();
@@ -100,7 +107,7 @@ public static void startDebugger(Project owner, DataObject dob, boolean singleFi
100107
: FileUtil.toFile(dob.getPrimaryFile().getParent()));
101108
PythonUtility.manageRunEnvs(pb);
102109

103-
Process process = pb.start();
110+
Process process = pb.redirectErrorStream(true).start();
104111
createHandle = ProgressHandle.createHandle(String.format("%s (%s)",
105112
Bundle.CTL_SessionName(), sessionName));
106113
createHandle.start();

src/main/java/org/netbeans/modules/python/debugger/pdb/PdbClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public String sendCommandAndGetResponse(String cmd) throws IOException {
119119
}
120120

121121
public String getStreamResponse(boolean first) throws IOException {
122+
//FIXME Something wrong with Python 2.7 reader.
123+
//Not supporting for now
122124
StringBuilder content = new StringBuilder();
123125
int value = reader.read();
124126
while (value != -1) {

src/main/java/org/netbeans/modules/python/project/PythonProject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public void invokeAction(String string, Lookup lkp)
498498
case ActionProvider.COMMAND_RUN:
499499
try {
500500
Properties prop = PythonUtility.getProperties(/*FileOwnerQuery
501-
.getOwner(projectDir)*/project);
501+
.getOwner(projectDir)*/project, false);
502502
Object get = prop.getProperty("nbproject.run.script");
503503
PythonRun.runAction(project, get != null
504504
? DataObject.find(FileUtil.toFileObject(new File(get
@@ -540,7 +540,7 @@ public void invokeAction(String string, Lookup lkp)
540540
case ActionProvider.COMMAND_DEBUG:
541541
try {
542542
Properties prop = PythonUtility.getProperties(/*FileOwnerQuery
543-
.getOwner(projectDir)*/project);
543+
.getOwner(projectDir)*/project, false);
544544
Object get = prop.getProperty("nbproject.run.script");
545545
PythonDebugger.startDebugger(project, get != null
546546
? DataObject.find(FileUtil.toFileObject(new File(get
@@ -579,7 +579,7 @@ public boolean isActionEnabled(String command, Lookup lookup)
579579
case ActionProvider.COMMAND_RUN:
580580
Properties prop = null;
581581
try {
582-
prop = PythonUtility.getProperties(/*FileOwnerQuery.getOwner(projectDir)*/project);
582+
prop = PythonUtility.getProperties(/*FileOwnerQuery.getOwner(projectDir)*/project, false);
583583
} catch (IOException ex) {
584584
Exceptions.printStackTrace(ex);
585585
}

0 commit comments

Comments
 (0)