-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc] Support incremental compilation #7887
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |
| from mypyc.namegen import exported_name | ||
| from mypyc.options import CompilerOptions | ||
| from mypyc.errors import Errors | ||
| from mypyc.common import shared_lib_name | ||
| from mypyc.common import BUILD_DIR, shared_lib_name | ||
| from mypyc.ops import format_modules | ||
|
|
||
| from mypyc import emitmodule | ||
|
|
@@ -79,7 +79,8 @@ def fail(message: str) -> NoReturn: | |
|
|
||
|
|
||
| def get_mypy_config(paths: List[str], | ||
| mypy_options: Optional[List[str]]) -> Tuple[List[BuildSource], Options]: | ||
| mypy_options: Optional[List[str]], | ||
| compiler_options: CompilerOptions) -> Tuple[List[BuildSource], Options]: | ||
| """Construct mypy BuildSources and Options from file and options lists""" | ||
| # It is kind of silly to do this but oh well | ||
| mypy_options = mypy_options or [] | ||
|
|
@@ -99,8 +100,8 @@ def get_mypy_config(paths: List[str], | |
| options.show_traceback = True | ||
| # Needed to get types for all AST nodes | ||
| options.export_types = True | ||
| # TODO: Support incremental checking | ||
| options.incremental = False | ||
| # We use mypy incremental mode when doing separate/incremental mypyc compilation | ||
| options.incremental = compiler_options.separate | ||
| options.preserve_asts = True | ||
|
|
||
| for source in sources: | ||
|
|
@@ -184,7 +185,7 @@ def generate_c(sources: List[BuildSource], | |
| # Do the actual work now | ||
| t0 = time.time() | ||
| try: | ||
| result = emitmodule.parse_and_typecheck(sources, options) | ||
| result = emitmodule.parse_and_typecheck(sources, options, groups) | ||
| except CompileError as e: | ||
| for line in e.messages: | ||
| print(line) | ||
|
|
@@ -283,14 +284,17 @@ def write_file(path: str, contents: str) -> None: | |
| want to write, skip writing so as to preserve the mtime | ||
| and avoid triggering recompilation. | ||
| """ | ||
| # We encode it ourselves and open the files as binary to avoid windows | ||
| # newline translation | ||
| encoded_contents = contents.encode('utf-8') | ||
| try: | ||
| with open(path, 'r', encoding='utf-8') as f: | ||
| old_contents = f.read() # type: Optional[str] | ||
| with open(path, 'rb') as f: | ||
| old_contents = f.read() # type: Optional[bytes] | ||
| except IOError: | ||
| old_contents = None | ||
| if old_contents != contents: | ||
| with open(path, 'w', encoding='utf-8') as f: | ||
| f.write(contents) | ||
| if old_contents != encoded_contents: | ||
| with open(path, 'wb') as f: | ||
| f.write(encoded_contents) | ||
|
Member
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. I am not sure if this is relevant, but long time ago we had problems on Windows with incremental mode (see for example #3215). This is why we have some non-trivial logic in and around |
||
|
|
||
| # Fudge the mtime forward because otherwise when two builds happen close | ||
| # together (like in a test) setuptools might not realize the source is newer | ||
|
|
@@ -400,8 +404,12 @@ def mypycify( | |
| """ | ||
|
|
||
| setup_mypycify_vars() | ||
| compiler_options = CompilerOptions(strip_asserts=strip_asserts, | ||
| multi_file=multi_file, verbose=verbose) | ||
| compiler_options = CompilerOptions( | ||
| strip_asserts=strip_asserts, | ||
| multi_file=multi_file, | ||
| verbose=verbose, | ||
| separate=separate is not False, | ||
| ) | ||
|
|
||
| # Create a compiler object so we can make decisions based on what | ||
| # compiler is being used. typeshed is missing some attribues on the | ||
|
|
@@ -413,13 +421,13 @@ def mypycify( | |
| for path in paths: | ||
| expanded_paths.extend(glob.glob(path)) | ||
|
|
||
| build_dir = 'build' # TODO: can this be overridden?? | ||
| build_dir = BUILD_DIR # TODO: can this be overridden?? | ||
| try: | ||
| os.mkdir(build_dir) | ||
| except FileExistsError: | ||
| pass | ||
|
|
||
| sources, options = get_mypy_config(expanded_paths, mypy_options) | ||
| sources, options = get_mypy_config(expanded_paths, mypy_options, compiler_options) | ||
| # We generate a shared lib if there are multiple modules or if any | ||
| # of the modules are in package. (Because I didn't want to fuss | ||
| # around with making the single module code handle packages.) | ||
|
|
||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.