-
Notifications
You must be signed in to change notification settings - Fork 2
Update supported Python and package versions. #14
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| test | ||
| test_single_version |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,11 +34,17 @@ _INDIRECTIONS_TYPES = [ | |||||
| "data", | ||||||
| ] | ||||||
|
|
||||||
| def _get_direct_deps(repo_ctx): | ||||||
| """Read a pip requirements.in file and return a list of direct dependencies.""" | ||||||
| def _read_and_parse_requirements(repo_ctx, postfix): | ||||||
| """Read a pip requirements file and return a list of dependencies (without version).""" | ||||||
| requirements = [] | ||||||
|
|
||||||
| lines = repo_ctx.read(repo_ctx.attr.requirements_in).split("\n") | ||||||
| # Check if file is existing. If not just return an empty list. | ||||||
| requirements_path_str = str(repo_ctx.path(repo_ctx.attr.requirements_in)) + postfix | ||||||
| requirements_path = repo_ctx.path(requirements_path_str) | ||||||
| if not requirements_path.exists: | ||||||
| return [] | ||||||
|
|
||||||
| lines = repo_ctx.read(requirements_path_str).split("\n") | ||||||
| for line in lines: | ||||||
| line = line.strip() | ||||||
| if not line: | ||||||
|
|
@@ -48,12 +54,38 @@ def _get_direct_deps(repo_ctx): | |||||
| if line.startswith("--"): | ||||||
| continue # Skip possible pip custom configurations. | ||||||
| if "==" not in line: | ||||||
| fail("Line '{}' in '{}' is missing a precise pinning via '=='.".format(line, str(repo_ctx.attr.requirements_in)) + | ||||||
| fail("Line '{}' in '{}' is missing a precise pinning via '=='.".format(line, str(repo_ctx.path(repo_ctx.attr.requirements_in)) + postfix) + | ||||||
| " While this is technically possible it violates our project best practices.") | ||||||
| requirements.append(line.split("==", 1)[0]) | ||||||
|
|
||||||
| return requirements | ||||||
|
|
||||||
| def _get_direct_deps(repo_ctx): | ||||||
| """Read pip requirements files and return a list of direct dependencies. | ||||||
|
|
||||||
| This will try to read the requirements.in file as well as | ||||||
| requirements.in_stable and requirements.in_legacy. In case one of those files | ||||||
| do not exist it will be simply skipped. | ||||||
|
Contributor
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.
Suggested change
|
||||||
|
|
||||||
| Returns: | ||||||
| list[str]: A list of unique direct dependencies found in the requirements files. | ||||||
| """ | ||||||
| requirements = {} | ||||||
|
|
||||||
| for requirement in _read_and_parse_requirements(repo_ctx, ""): | ||||||
| requirements[requirement] = True | ||||||
|
|
||||||
| for requirement in _read_and_parse_requirements(repo_ctx, "_stable"): | ||||||
| requirements[requirement] = True | ||||||
|
|
||||||
| for requirement in _read_and_parse_requirements(repo_ctx, "_legacy"): | ||||||
| requirements[requirement] = True | ||||||
|
|
||||||
| if not requirements: | ||||||
| fail("No direct dependencies found in any requirements file. The created pip hub will be empty.") | ||||||
|
|
||||||
| return list(requirements.keys()) | ||||||
|
Contributor
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. if we anyhow return a list, would be possible to skip the dictionary step and just add the lists returned by |
||||||
|
|
||||||
| def _generate_single_indirection(dep, deps_to_config_map, indirection_type): | ||||||
| """Generate the requested dependency indirection for a given dependency to config map.""" | ||||||
| dep_name = pip_utils.normalize_name(dep) | ||||||
|
|
@@ -141,10 +173,13 @@ This is needed so this custom pip hub can select which rules python pip hub shou | |||||
|
|
||||||
| ``` | ||||||
| deps_to_config_map = { | ||||||
| "@rules_python_pip_hub_3_10": "@your_repo_name//label/to/your:config_setting_3_10", | ||||||
| "@rules_python_pip_hub_3_11": "@your_repo_name//label/to/your:config_setting_3_11", | ||||||
| "@rules_python_pip_hub_3_8": "@your_repo_name//label/to/your:config_setting_3_8", | ||||||
| "@rules_python_pip_hub_3_9": "@your_repo_name//label/to/your:config_setting_3_9", | ||||||
| "@rules_python_pip_hub_3_10": "@your_repo_name//label/to/your:config_setting_3_10", | ||||||
| "@rules_python_pip_hub_3_11": "@your_repo_name//label/to/your:config_setting_3_11", | ||||||
| "@rules_python_pip_hub_3_12": "@your_repo_name//label/to/your:config_setting_3_12", | ||||||
| "@rules_python_pip_hub_3_13": "@your_repo_name//label/to/your:config_setting_3_13", | ||||||
| "@rules_python_pip_hub_3_14": "@your_repo_name//label/to/your:config_setting_3_14", | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "bool_setting") | ||
| load("@bazel_tools_python//bazel/toolchains/python:versions.bzl", "PYTHON_VERSIONS", "unsupported_python_configuration_error") | ||
| load("@bazel_tools_python//bazel/toolchains/python:versions.bzl", "LEGACY_PYTHON_VERSIONS", "PYTHON_VERSIONS", "legacy_python_warning", "unsupported_python_configuration_error") | ||
| load("@rules_python//python:defs.bzl", "py_runtime_pair") | ||
|
|
||
| bool_flag( | ||
|
|
@@ -72,6 +72,14 @@ config_setting( | |
| for version in PYTHON_VERSIONS | ||
| ] | ||
|
|
||
| [ | ||
|
Contributor
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. Would it be possible to issue the warning only if the selected python version is a legacy one? |
||
| legacy_python_warning( | ||
| name = "legacy_python_{}_warning".format(version.replace(".", "_")), | ||
| python_version = version, | ||
| ) | ||
| for version in LEGACY_PYTHON_VERSIONS | ||
| ] | ||
|
|
||
| ############################################# | ||
| # Incorrect toolchain configurations traps. # | ||
| ############################################# | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,22 +44,6 @@ def tearDown(self) -> None: | |
| self.tmp_text_file_path.unlink() | ||
| self.tmp_json_file_path.unlink() | ||
|
|
||
| def test_black_removeprefix(self) -> None: | ||
| """Test black _removeprefix for both text string cases.""" | ||
| would_reformat_message = "would reformat file.py." | ||
| expected_text = "reformat" | ||
| expected_strip_text = "file.py." | ||
|
|
||
| # pylint: disable-next=protected-access | ||
| return_text = black_runner._removeprefix(text=expected_text, prefix=black_runner.WOULD_REFORMAT_MSG) | ||
| # pylint: disable-next=protected-access | ||
| return_strip_text = black_runner._removeprefix( | ||
| text=would_reformat_message, prefix=black_runner.WOULD_REFORMAT_MSG | ||
| ) | ||
|
|
||
| assert return_text == expected_text | ||
| assert return_strip_text == expected_strip_text | ||
|
|
||
| def test_black_output_parser_with_no_issues(self) -> None: | ||
| """Tests black_output_parser function with the results of a file with no issues.""" | ||
| expected_findings = python_tool_common.Findings() | ||
|
|
@@ -85,7 +69,7 @@ def test_black_output_parser_with_issues(self) -> None: | |
| expected_findings = python_tool_common.Findings( | ||
| [ | ||
| python_tool_common.Finding( | ||
| path=pathlib.Path("file.py"), | ||
| path=pathlib.Path(" file.py"), | ||
|
Contributor
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. wa sthis change made on purpose? |
||
| message="Should be reformatted.", | ||
| severity=python_tool_common.Severity.WARN, | ||
| tool="black", | ||
|
|
||
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.
according to
MODULES.bazel