-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make static checks generated file more stable accross the board (#29080)
There were couple of problems with static checks generating source files including generated stubs in the common.sql package: * black formatting was implemented in multiple separate scripts making it harded to fix problems in all of them * generated stub files were not formatted with is_pyi=True and black had no way to figure it out because it was working on strings * black formatting was not consistently applied in all places * EOL at the end of generated stub file was missing, leading to EOL fixer adding them after generation leading to multiple pre-commit passes needed * there was (already unused) deprecated dev dict generator that used its own black formatting. There were also couple of problems with the files generated by stubgen itself: * Union was missing in the generated stubs (this is a known issue with stubgen: python/mypy#12929 * Intellij complained on Incomplete import from _typeshed missing This PR fixes all the problems: * black formatting is now consistenly extracted and applied everywhere * when needed, is_pyi flag is passed to black so that it knows that .pyi file is being fomratted * EOL is added at the end of file when the file is generated * Union is added to the generated stub * noqa is added to _typeshed import * the dict generator is removed As the end result, generated stub files are fully importable (no errors reported by IntelliJ IDE) and consistently formatted every time. (cherry picked from commit 129f082)
- Loading branch information
1 parent
14fdfc0
commit 4e2af12
Showing
10 changed files
with
105 additions
and
306 deletions.
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from functools import lru_cache | ||
from pathlib import Path | ||
|
||
from black import Mode, TargetVersion, format_str, parse_pyproject_toml | ||
|
||
sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported | ||
|
||
from common_precommit_utils import AIRFLOW_BREEZE_SOURCES_PATH # isort: skip # noqa E402 | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def black_mode(is_pyi: bool = Mode.is_pyi) -> Mode: | ||
config = parse_pyproject_toml(os.fspath(AIRFLOW_BREEZE_SOURCES_PATH / "pyproject.toml")) | ||
target_versions = {TargetVersion[val.upper()] for val in config.get("target_version", ())} | ||
|
||
return Mode( | ||
target_versions=target_versions, | ||
line_length=config.get("line_length", Mode.line_length), | ||
is_pyi=is_pyi, | ||
) | ||
|
||
|
||
def black_format(content: str, is_pyi: bool = Mode.is_pyi) -> str: | ||
return format_str(content, mode=black_mode(is_pyi=is_pyi)) |
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.