Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix and other updates #173

Merged
merged 8 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class PythonModuleParser extends PythonParser<ModuleEntry> {

private static final Logger logger = Logger.getLogger(PythonModuleParser.class.getName());
private static final Logger LOGGER = Logger.getLogger(PythonModuleParser.class.getName());

private final Set<String> localModules = HashSetFactory.make();

Expand All @@ -60,9 +60,9 @@ protected PythonParser<ModuleEntry>.CAstVisitor makeVisitor(
return new CAstVisitor(context, parser) {

@Override
public CAstNode visitImportFrom(ImportFrom arg0) throws Exception {
public CAstNode visitImportFrom(ImportFrom importFrom) throws Exception {
Optional<String> s =
arg0.getInternalModuleNames().stream()
importFrom.getInternalModuleNames().stream()
.map(
n -> {
return n.getInternalId();
Expand All @@ -73,14 +73,22 @@ public CAstNode visitImportFrom(ImportFrom arg0) throws Exception {
});
if (s.isPresent()) {
String moduleName = s.get();
if (!localModules.contains(moduleName + ".py")) {
LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + ".");

if (!isLocalModule(moduleName)) {
LOGGER.finer("Module: " + moduleName + ".py" + " isn't local.");
moduleName = s.get() + "/__init__";
}
if (localModules.contains(moduleName + ".py")) {
} else LOGGER.finer("Module: " + moduleName + ".py" + " is local.");

LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + ".");

if (isLocalModule(moduleName)) {
LOGGER.finer("Module: " + moduleName + ".py" + " is local.");

String yuck = moduleName;
return Ast.makeNode(
CAstNode.BLOCK_STMT,
arg0.getInternalNames().stream()
importFrom.getInternalNames().stream()
.map(a -> a.getInternalName())
.map(
n ->
Expand All @@ -94,10 +102,10 @@ public CAstNode visitImportFrom(ImportFrom arg0) throws Exception {
Ast.makeConstant(yuck),
Ast.makeConstant(n))))
.collect(Collectors.toList()));
}
} else LOGGER.finer("Module: " + moduleName + ".py" + " isn't local.");
}

return super.visitImportFrom(arg0);
return super.visitImportFrom(importFrom);
}
};
}
Expand All @@ -121,7 +129,7 @@ public void accept(ModuleEntry f) {
accept(sm);
});
} else {
logger.fine(() -> "**CLS: " + scriptName((SourceModule) f));
LOGGER.fine(() -> "**CLS: " + scriptName((SourceModule) f));
localModules.add(scriptName((SourceModule) f));
}
}
Expand Down Expand Up @@ -158,4 +166,8 @@ public static void main(String[] args) throws Exception {
protected Reader getReader() throws IOException {
return new InputStreamReader(fileName.getInputStream());
}

private boolean isLocalModule(String moduleName) {
return localModules.stream().anyMatch(lm -> lm.endsWith(moduleName + ".py"));
}
}
1 change: 1 addition & 0 deletions com.ibm.wala.cast.python.test/logging.properties
4 changes: 2 additions & 2 deletions logging.ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ handlers= java.util.logging.ConsoleHandler
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level= INFO
.level= WARNING

############################################################
# Handler specific properties.
Expand All @@ -40,7 +40,7 @@ handlers= java.util.logging.ConsoleHandler
#java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.level = WARNING
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Example to customize the SimpleFormatter output format
Expand Down
Loading