-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add On Import Translation of Python Files in Include Path #1964
Draft
konradweiss
wants to merge
20
commits into
main
Choose a base branch
from
feature/import-external-interfaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
30c093d
Import over Language Frontend preprocessing
konradweiss d06286b
Add language dependent preprocessing function and file walk
konradweiss 3e4e8df
Add language dependent preprocessing function and file walk
konradweiss 2bf1360
Resolving imports if exactly a file is imported, e.g. import a.b and …
konradweiss 152c004
Resolving imports when not a specific pyi file is imported but a gene…
konradweiss 0f4bb6d
Cut prints, reduce number of files imported reduce runtime be collect…
konradweiss 61c89e8
Adding include paths to be analyzed over include paths, i still need …
konradweiss fc92c87
Spotless fix
konradweiss 7479aec
Adding Dummyfunction to IniFileFrontend
konradweiss cb4e025
Merge branch 'main' into feature/import-external-interfaces
konradweiss e8329f6
Moving component creation outside the loop
konradweiss 4910ec7
Merge branch 'feature/import-external-interfaces' of github.com:Fraun…
konradweiss b29e6bf
Fixed compile error
oxisto a1f9360
Merge branch 'main' into feature/import-external-interfaces
oxisto f552f83
Add context to component
konradweiss d9ff2c0
Add missing function for typescript frontend
konradweiss c14cca7
spotless typescript
konradweiss 3eb715e
Fix typescript error
konradweiss 28ade73
Add dummy implementation for previously not implemented function in T…
konradweiss bb9527f
Set Toplevel to component and add DoNotPersist annotation to it
konradweiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,13 @@ | |
import java.io.PrintWriter | ||
import java.lang.reflect.InvocationTargetException | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.util.* | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.CompletionException | ||
import java.util.concurrent.ExecutionException | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import kotlin.io.path.name | ||
import kotlin.reflect.full.findAnnotation | ||
import org.slf4j.LoggerFactory | ||
|
||
|
@@ -140,15 +142,24 @@ | |
result: TranslationResult, | ||
): Set<LanguageFrontend<*, *>> { | ||
val usedFrontends = mutableSetOf<LanguageFrontend<*, *>>() | ||
|
||
val externalSources: MutableList<File> = mutableListOf() | ||
val importedSources: MutableSet<File> = mutableSetOf() | ||
|
||
ctx.config.includePaths.forEach { externalSources.addAll(extractConfiguredSources(it)) } | ||
|
||
var useParallelFrontends = ctx.config.useParallelFrontends | ||
|
||
for (sc in ctx.config.softwareComponents.keys) { | ||
val component = Component() | ||
component.ctx = ctx | ||
component.name = Name(sc) | ||
result.addComponent(component) | ||
|
||
// Every Component needs to reprocess the sources | ||
var sourceLocations: List<File> = ctx.config.softwareComponents[sc] ?: listOf() | ||
|
||
var useParallelFrontends = ctx.config.useParallelFrontends | ||
// Todo Here we need to dispatch to the correct frontend to do preproccessing | ||
|
||
val list = | ||
sourceLocations.flatMap { file -> | ||
|
@@ -172,6 +183,7 @@ | |
files | ||
} else { | ||
val frontendClass = file.language?.frontend | ||
|
||
val supportsParallelParsing = | ||
file.language | ||
?.frontend | ||
|
@@ -243,6 +255,29 @@ | |
sourceLocations = list | ||
} | ||
|
||
val processedImports: MutableList<String> = mutableListOf() | ||
|
||
sourceLocations | ||
.filter { it.language != null } | ||
.forEach { | ||
val frontend = it.language?.newFrontend(ctx) | ||
importedSources.addAll( | ||
frontend?.gatherExternalSources( | ||
ctx.config.includePaths, | ||
it, | ||
externalSources, | ||
processedImports, | ||
) ?: listOf() | ||
) | ||
} | ||
log.info( | ||
"Extending " + | ||
sourceLocations.size + | ||
" source files by " + | ||
importedSources.size + | ||
" interface files." | ||
) | ||
|
||
usedFrontends.addAll( | ||
if (useParallelFrontends) { | ||
parseParallel(component, result, ctx, sourceLocations) | ||
|
@@ -252,9 +287,43 @@ | |
) | ||
} | ||
|
||
// Distribute all files by there root path prefix, parse them in individual component | ||
// named | ||
// like their rootPath local name | ||
ctx.config.includePaths.forEach { includePath -> | ||
val filesInPath = | ||
importedSources.filter { | ||
it.path.removePrefix(includePath.toString()) != it.path.toString() | ||
} | ||
if (filesInPath.isNotEmpty()) { | ||
val component = Component() | ||
component.ctx = ctx | ||
component.name = Name(includePath.name) | ||
result.addComponent(component) | ||
|
||
ctx.config.topLevels.put(includePath.toString(), includePath.toFile()) | ||
|
||
usedFrontends.addAll( | ||
if (useParallelFrontends) { | ||
parseParallel(component, result, ctx, filesInPath) | ||
} else { | ||
parseSequentially(component, result, ctx, filesInPath) | ||
} | ||
) | ||
} | ||
} | ||
|
||
return usedFrontends | ||
} | ||
|
||
private fun extractConfiguredSources(path: Path): MutableList<File> { | ||
val rootFile = path.toFile() | ||
return if (rootFile.exists()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please refactor this code. Add some |
||
(if (rootFile.isDirectory) rootFile.walkTopDown().toMutableList() | ||
else mutableListOf(rootFile)) | ||
else mutableListOf() | ||
} | ||
|
||
private fun parseParallel( | ||
component: Component, | ||
result: TranslationResult, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please have some doc here? What are these variables used for?