Skip to content

Commit

Permalink
Don't use PYTHONPATH if it is the same as the project path.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Mar 26, 2024
1 parent d08815b commit 935714a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.cuny.hunter.hybridize.core.refactorings;

import static com.google.common.collect.Iterables.concat;
import static edu.cuny.hunter.hybridize.core.utils.Util.getPath;
import static java.lang.Boolean.TRUE;
import static java.util.stream.Collectors.toList;
import static org.eclipse.core.runtime.Platform.getLog;
Expand All @@ -20,6 +21,7 @@
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -66,6 +68,7 @@
import edu.cuny.hunter.hybridize.core.analysis.UndeterminablePythonSideEffectsException;
import edu.cuny.hunter.hybridize.core.descriptors.HybridizeFunctionRefactoringDescriptor;
import edu.cuny.hunter.hybridize.core.messages.Messages;
import edu.cuny.hunter.hybridize.core.utils.Util;
import edu.cuny.hunter.hybridize.core.wala.ml.EclipsePythonProjectTensorAnalysisEngine;
import edu.cuny.hunter.hybridize.core.wala.ml.PythonModRefWithBuiltinFunctions;

Expand Down Expand Up @@ -280,6 +283,18 @@ private RefactoringStatus checkFunctions(IProgressMonitor monitor) throws Operat
for (IProject project : projectToFunctions.keySet()) {
// create the analysis engine for the project.
List<File> pythonPath = getPythonPath(project);
assert pythonPath.stream().allMatch(File::exists) : "PYTHONPATH should exist.";

// if they PYTHONPATH is the same as the project path, don't use it.
if (pythonPath.size() == 1) {
File pythonPathEntry = pythonPath.get(0);
IPath projectPath = getPath(project);
File projectPathFile = projectPath.toFile();

if (pythonPathEntry.equals(projectPathFile))
pythonPath = null;
}

LOG.info("PYTHONPATH for " + project + " is: " + pythonPath + ".");

EclipsePythonProjectTensorAnalysisEngine engine = new EclipsePythonProjectTensorAnalysisEngine(project, pythonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.Refactoring;
Expand Down Expand Up @@ -160,4 +161,13 @@ private static IProject getProject(PythonNode pythonNode) {
IProject project = resource.getProject();
return project;
}

public static IPath getPath(IProject project) {
IPath path = project.getFullPath();

if (!path.toFile().exists())
path = project.getLocation();

return path;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.cuny.hunter.hybridize.core.wala.ml;

import static edu.cuny.hunter.hybridize.core.utils.Util.getPath;
import static org.eclipse.core.runtime.Platform.getLog;

import java.io.File;
Expand All @@ -20,6 +21,8 @@
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.ide.classloader.EclipseSourceDirectoryTreeModule;

import edu.cuny.hunter.hybridize.core.utils.Util;

public class EclipsePythonProjectTensorAnalysisEngine extends PythonTensorAnalysisEngine {

private static final String PYTHON3_INTERPRETER_FQN = "com.ibm.wala.cast.python.util.Python3Interpreter";
Expand Down Expand Up @@ -66,15 +69,6 @@ public EclipsePythonProjectTensorAnalysisEngine(IProject project, List<File> pyt
}
}

private static IPath getPath(IProject project) {
IPath path = project.getFullPath();

if (!path.toFile().exists())
path = project.getLocation();

return path;
}

public IProject getProject() {
return project;
}
Expand Down

0 comments on commit 935714a

Please sign in to comment.