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

Support for analyzing multiple local modules (multi-module projects) by using PYTHONPATH #176

Merged
merged 41 commits into from
Apr 25, 2024

Conversation

khatchad
Copy link
Collaborator

@khatchad khatchad commented Mar 26, 2024

* First test.

* Add comment.

* Test 2.

Should fail.

* More tests.

* Add comment.

* Extract local variable refactoring.

* Improve variable name.

* Add logging.

* Decrease logging level.

* Fix bug with determining whether a module is "local."

The old code didn't consider the full path of the module, which is what
is contained in `localModules`. But, it still doesn't do what I think it
should do, which makes me believe that the generated CAst is incorrect.

* Replace slash with dot in test filenames.

* New test.

This one has a sibling script in the module that uses the other sibling.

* Implement `getSignature()` for `com.ibm.wala.cast.python.parser.PythonParser.translateToCAst().PythonScriptEntity<T>`.

No signature currently so return `null`.

* Actually add the test files.

* Fix filename for test.

* Remove redundant log.

* Fix compilation error.

* Only test PYTHONPATH for Jython3.

It's only supported for Jython3.

* Add docs.
@khatchad khatchad added the enhancement New feature or request label Mar 26, 2024
@khatchad khatchad requested a review from msridhar March 26, 2024 14:39
@khatchad khatchad enabled auto-merge (squash) March 26, 2024 14:41
@khatchad khatchad marked this pull request as draft March 26, 2024 20:46
auto-merge was automatically disabled March 26, 2024 20:46

Pull request was converted to draft

Module names don't include a file extension.
We have the full file path, why not use it? I see in 3cf9b35 that this was changed for `FileModule`s, but I cannot understand why.
To debug Maven builds remotely.
This reverts commit 70f01d4. It works
even when the files "don't" exist.
@khatchad
Copy link
Collaborator Author

This is only supported by Jython 3, but http://github.com/wala/ML is still working with Jython 2 due to #42. Thus, I"m unsure whether this should be merged here.

@khatchad
Copy link
Collaborator Author

We can merge it, but the new functionality isn't being tested here until #42 is fixed and both com.ibm.wala.cast.python.ml and com.ibm.wala.cast.python.ml.tests are configured to use Jython 3.

@khatchad khatchad marked this pull request as ready for review March 29, 2024 21:05
@khatchad khatchad enabled auto-merge (squash) March 29, 2024 21:07
@msridhar
Copy link
Member

@khatchad how critically do you need this merged? I probably won't have time to do a real review for a couple of weeks, but I can stamp it if you need it in quickly

@khatchad
Copy link
Collaborator Author

We've been using our fork, so no rush.

* More test files.

* Fix test file.

* Add classes.

* Add test.

* Add test.

* Add test.

* Add test.

* New test.

* New test.

* Fix test code.

* New test.

* New test.

* New test.
@khatchad khatchad marked this pull request as draft April 8, 2024 21:07
auto-merge was automatically disabled April 8, 2024 21:07

Pull request was converted to draft

@khatchad khatchad changed the title Initial support for analyzing multiple local modules (multi-module projects) by using PYTHONPATH Support for analyzing multiple local modules (multi-module projects) by using PYTHONPATH Apr 8, 2024
@khatchad khatchad marked this pull request as ready for review April 8, 2024 21:36
@khatchad khatchad enabled auto-merge (squash) April 8, 2024 21:36
@khatchad khatchad mentioned this pull request Apr 9, 2024
* Remove periods from end of logging statements.

Period is a valid path now with relative imports.

* Fix the resolved relative import path.

* Add test directory to PYTHONPATH.

* Fix a bug with the wrong instance key.

We need the instance key for the node that we are examining in the loop
not one that we are creating constraints for.
khatchad added a commit that referenced this pull request Apr 16, 2024
#181)

Trying to make #176 more readable. Thus, this PR can be merged before
#176, @msridhar. Thanks.

## Changes

- **Fix logs.**
  Module names don't include a file extension.   
- **Add launch configuration.**
  To debug Maven builds remotely.
- **Capitalize constant.**
- **Simplify lambda.**
@msridhar
Copy link
Member

@khatchad with 236 modified files this is rather intimidating to review. Will it be easier once some other PRs land?

@khatchad
Copy link
Collaborator Author

khatchad commented Apr 16, 2024

@khatchad with 236 modified files this is rather intimidating to review. Will it be easier once some other PRs land?

Unfortunately, this is quite a pervasive change. We're basically adding something like a CLASSPATH or a project starting point here. Thus, there's quite a bit of plumbing involved. There are also some metadata changes and plenty of varying tests. I tried to document the other changes as best I could. Hopefully that helps somewhat. Sorry about that.

Copy link
Member

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only did a very superficial review. I have a couple minor comments.

}
}

String yuck = moduleName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

@khatchad khatchad Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was in the original code :). My guess is that @juliandolby was frustrated with the requirement of lambdas to only accepted (effectively) final variables. See this unchanged code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we can leave it :-)

Comment on lines 183 to 201
for (File pathEntry : pythonPath) {
Path modulePath =
localModule
.map(SourceModule::getURL)
.map(URL::getFile)
.map(Path::of)
.orElseThrow(IllegalStateException::new);
LOGGER.finer("Found module path: " + modulePath);

if (modulePath.startsWith(pathEntry.toPath())) {
// Found it.
Path scriptRelativePath = pathEntry.toPath().relativize(modulePath);
LOGGER.finer("Relativized path is: " + scriptRelativePath);

// Remove the file extension if it exists.
moduleName = scriptRelativePath.toString().replaceFirst("\\.py$", "");
LOGGER.fine("Using module name: " + moduleName);
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems a bit duplicated with code earlier in the PR? Is it worth extracting a method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. I'll have a look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little difficult to fully extract this since it's in a loop with a break. I think i can extract some of it at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants