Skip to content

Commit

Permalink
Pull up PYTHONPATH from PythonLoader subclasses refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Apr 3, 2024
1 parent ee55339 commit 5b1e9fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,12 @@
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.python.core.PyObject;

public class Python2Loader extends PythonLoader {

/**
* The <a href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to
* use in the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
protected List<File> pythonPath;

public Python2Loader(IClassHierarchy cha, IClassLoader parent) {
super(cha, parent);
}
Expand Down Expand Up @@ -121,16 +111,4 @@ protected Object eval(CAstOperator op, Object lhs, Object rhs) {
false);
return x;
}

/**
* Gets the <a
* href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to use in
* the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
public List<File> getPythonPath() {
return pythonPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,12 @@

public class Python3Loader extends PythonLoader {

/**
* The <a href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to
* use in the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
protected List<File> pythonPath;

public Python3Loader(IClassHierarchy cha, IClassLoader parent, List<File> pythonPath) {
super(cha, parent);
this.pythonPath = pythonPath;
super(cha, parent, pythonPath);
}

public Python3Loader(IClassHierarchy cha, List<File> pythonPath) {
super(cha);
this.pythonPath = pythonPath;
super(cha, pythonPath);
}

@Override
Expand Down Expand Up @@ -123,16 +112,4 @@ protected Object eval(CAstOperator op, Object lhs, Object rhs) {
false);
return x;
}

/**
* Gets the <a
* href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to use in
* the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
public List<File> getPythonPath() {
return pythonPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.ibm.wala.types.annotations.Annotation;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Pair;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -207,14 +208,33 @@ protected TranslatorToIR initTranslator(Set<Pair<CAstEntity, ModuleEntry>> topLe
final CoreClass iterator =
new CoreClass(PythonTypes.iterator.getName(), PythonTypes.object.getName(), this, null);

/**
* The <a href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to
* use in the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
protected List<File> pythonPath;

public PythonLoader(IClassHierarchy cha, IClassLoader parent) {
super(cha, parent);
}

public PythonLoader(IClassHierarchy cha, IClassLoader parent, List<File> pythonPath) {
super(cha, parent);
this.pythonPath = pythonPath;
}

public PythonLoader(IClassHierarchy cha) {
super(cha);
}

public PythonLoader(IClassHierarchy cha, List<File> pythonPath) {
super(cha);
this.pythonPath = pythonPath;
}

public IClass makeMethodBodyType(
String name,
TypeReference P,
Expand Down Expand Up @@ -411,4 +431,16 @@ public boolean isVolatile() {
}
});
}

/**
* Gets the <a
* href="https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> to use in
* the analysis.
*
* @apiNote PYTHONPATH is currently only supported for Python 3.
* @see https://docs.python.org/3/tutorial/modules.html#the-module-search-path.
*/
public List<File> getPythonPath() {
return pythonPath;
}
}

0 comments on commit 5b1e9fc

Please sign in to comment.