From f5fc2960c282530c7192ceba099be36581cb2e8c Mon Sep 17 00:00:00 2001 From: Gguidini Date: Thu, 5 Oct 2023 14:01:39 -0300 Subject: [PATCH 1/5] chore: rename PythonStandardRunner This is lower priority, but it has been pointed out to me that `PythonStandardRunner` is not accurate. There are other test runners available in python after all. So these changes simple rename it to be `PytestStandardRunner` instead. Include changes to default options to the `--runner` option and the config key for the runner. I made that to be backwards compatible tho. --- codecov_cli/commands/labelanalysis.py | 2 +- codecov_cli/runners/__init__.py | 16 ++++++--- ...rd_runner.py => pytest_standard_runner.py} | 6 ++-- ...nner.py => test_pytest_standard_runner.py} | 34 +++++++++---------- tests/runners/test_runners.py | 22 +++++++++--- 5 files changed, 50 insertions(+), 30 deletions(-) rename codecov_cli/runners/{python_standard_runner.py => pytest_standard_runner.py} (97%) rename tests/runners/{test_python_standard_runner.py => test_pytest_standard_runner.py} (90%) diff --git a/codecov_cli/commands/labelanalysis.py b/codecov_cli/commands/labelanalysis.py index 1f8242a8..4d1be008 100644 --- a/codecov_cli/commands/labelanalysis.py +++ b/codecov_cli/commands/labelanalysis.py @@ -44,7 +44,7 @@ required=True, ) @click.option( - "--runner-name", "--runner", "runner_name", help="Runner to use", default="python" + "--runner-name", "--runner", "runner_name", help="Runner to use", default="pytest" ) @click.option( "--max-wait-time", diff --git a/codecov_cli/runners/__init__.py b/codecov_cli/runners/__init__.py index 1c4173ac..aab02935 100644 --- a/codecov_cli/runners/__init__.py +++ b/codecov_cli/runners/__init__.py @@ -5,7 +5,7 @@ import click from codecov_cli.runners.dan_runner import DoAnythingNowRunner -from codecov_cli.runners.python_standard_runner import PythonStandardRunner +from codecov_cli.runners.pytest_standard_runner import PytestStandardRunner from codecov_cli.runners.types import LabelAnalysisRunnerInterface logger = logging.getLogger("codecovcli") @@ -42,9 +42,17 @@ def _load_runner_from_yaml(plugin_dict: typing.Dict) -> LabelAnalysisRunnerInter def get_runner(cli_config, runner_name) -> LabelAnalysisRunnerInterface: - if runner_name == "python": - config_params = cli_config.get("runners", {}).get("python", {}) - return PythonStandardRunner(config_params) + if runner_name == "pytest": + config_params = cli_config.get("runners", {}).get("pytest", {}) + # This is for backwards compatibility with versions <= 0.3.4 + # In which the key for this config was 'python', not 'pytest' + if config_params == {}: + config_params = cli_config.get("runners", {}).get("python", {}) + if config_params: + logger.warning( + "Using 'python' to configure the PytestStandardRunner is deprecated. Please change to 'pytest'" + ) + return PytestStandardRunner(config_params) elif runner_name == "dan": config_params = cli_config.get("runners", {}).get("dan", {}) return DoAnythingNowRunner(config_params) diff --git a/codecov_cli/runners/python_standard_runner.py b/codecov_cli/runners/pytest_standard_runner.py similarity index 97% rename from codecov_cli/runners/python_standard_runner.py rename to codecov_cli/runners/pytest_standard_runner.py index a7552ed6..29a13010 100644 --- a/codecov_cli/runners/python_standard_runner.py +++ b/codecov_cli/runners/pytest_standard_runner.py @@ -15,7 +15,7 @@ logger = logging.getLogger("codecovcli") -class PythonStandardRunnerConfigParams(dict): +class PytestStandardRunnerConfigParams(dict): @property def collect_tests_options(self) -> List[str]: return self.get("collect_tests_options", []) @@ -38,7 +38,7 @@ def coverage_root(self) -> str: return self.get("coverage_root", "./") -class PythonStandardRunner(LabelAnalysisRunnerInterface): +class PytestStandardRunner(LabelAnalysisRunnerInterface): dry_run_runner_options = ["--cov-context=test"] @@ -46,7 +46,7 @@ def __init__(self, config_params: Optional[dict] = None) -> None: super().__init__() if config_params is None: config_params = {} - self.params = PythonStandardRunnerConfigParams(config_params) + self.params = PytestStandardRunnerConfigParams(config_params) def parse_captured_output_error(self, exp: CalledProcessError) -> str: result = "" diff --git a/tests/runners/test_python_standard_runner.py b/tests/runners/test_pytest_standard_runner.py similarity index 90% rename from tests/runners/test_python_standard_runner.py rename to tests/runners/test_pytest_standard_runner.py index 75235009..2ac6780a 100644 --- a/tests/runners/test_python_standard_runner.py +++ b/tests/runners/test_pytest_standard_runner.py @@ -5,14 +5,14 @@ import pytest from pytest import ExitCode -from codecov_cli.runners.python_standard_runner import PythonStandardRunner -from codecov_cli.runners.python_standard_runner import logger as runner_logger -from codecov_cli.runners.python_standard_runner import stdout as pyrunner_stdout +from codecov_cli.runners.pytest_standard_runner import PytestStandardRunner +from codecov_cli.runners.pytest_standard_runner import logger as runner_logger +from codecov_cli.runners.pytest_standard_runner import stdout as pyrunner_stdout from codecov_cli.runners.types import LabelAnalysisRequestResult class TestPythonStandardRunner(object): - runner = PythonStandardRunner() + runner = PytestStandardRunner() def test_init_with_params(self): assert self.runner.params.collect_tests_options == [] @@ -21,10 +21,10 @@ def test_init_with_params(self): config_params = dict( collect_tests_options=["--option=value", "-option"], ) - runner_with_params = PythonStandardRunner(config_params) + runner_with_params = PytestStandardRunner(config_params) assert runner_with_params.params == config_params - @patch("codecov_cli.runners.python_standard_runner.subprocess") + @patch("codecov_cli.runners.pytest_standard_runner.subprocess") def test_execute_pytest(self, mock_subprocess): output = "Output in stdout" return_value = MagicMock(stdout=output.encode("utf-8")) @@ -39,7 +39,7 @@ def test_execute_pytest(self, mock_subprocess): ) assert result == output - @patch("codecov_cli.runners.python_standard_runner.subprocess") + @patch("codecov_cli.runners.pytest_standard_runner.subprocess") def test_execute_pytest_fail_collection(self, mock_subprocess): def side_effect(command, *args, **kwargs): raise CalledProcessError( @@ -58,7 +58,7 @@ def side_effect(command, *args, **kwargs): == "Pytest exited with non-zero code 2.\nThis is likely not a problem with label-analysis. Check pytest's output and options.\nPYTEST OUTPUT:\nProcess running up to here...\nSome error occured" ) - @patch("codecov_cli.runners.python_standard_runner.subprocess") + @patch("codecov_cli.runners.pytest_standard_runner.subprocess") def test_execute_pytest_fail_execution(self, mock_subprocess): def side_effect(command, *args, **kwargs): # In this scenario the regular output AND the stderr message will have been printed @@ -123,7 +123,7 @@ def test_collect_tests(self, mocker): "tests/services/upload/test_upload_service.py::test_do_upload_logic_verbose" ] mock_execute = mocker.patch.object( - PythonStandardRunner, + PytestStandardRunner, "_execute_pytest", return_value="\n".join(collected_test_list), ) @@ -138,13 +138,13 @@ def test_collect_tests_with_options(self, mocker): "tests/services/upload/test_upload_collector.py::test_fix_php_files" ] mock_execute = mocker.patch.object( - PythonStandardRunner, + PytestStandardRunner, "_execute_pytest", return_value="\n".join(collected_test_list), ) config_params = dict(collect_tests_options=["--option=value", "-option"]) - runner_with_params = PythonStandardRunner(config_params) + runner_with_params = PytestStandardRunner(config_params) collected_tests_from_runner = runner_with_params.collect_tests() mock_execute.assert_called_with( @@ -159,7 +159,7 @@ def test_process_label_analysis_result(self, mocker): "present_diff_labels": ["test_in_diff"], "global_level_labels": ["test_global"], } - mock_execute = mocker.patch.object(PythonStandardRunner, "_execute_pytest") + mock_execute = mocker.patch.object(PytestStandardRunner, "_execute_pytest") self.runner.process_labelanalysis_result( LabelAnalysisRequestResult(label_analysis_result) @@ -185,10 +185,10 @@ def test_process_label_analysis_result_diff_coverage_root(self, mocker): "present_diff_labels": ["test_in_diff"], "global_level_labels": ["test_global"], } - mock_execute = mocker.patch.object(PythonStandardRunner, "_execute_pytest") + mock_execute = mocker.patch.object(PytestStandardRunner, "_execute_pytest") config_params = dict(coverage_root="coverage_root/") - runner_with_params = PythonStandardRunner(config_params) + runner_with_params = PytestStandardRunner(config_params) runner_with_params.process_labelanalysis_result( LabelAnalysisRequestResult(label_analysis_result) ) @@ -213,13 +213,13 @@ def test_process_label_analysis_result_with_options(self, mocker): "present_diff_labels": ["test_in_diff"], "global_level_labels": ["test_global"], } - mock_execute = mocker.patch.object(PythonStandardRunner, "_execute_pytest") + mock_execute = mocker.patch.object(PytestStandardRunner, "_execute_pytest") mock_warning = mocker.patch.object(runner_logger, "warning") runner_config = { "execute_tests_options": ["-s", "--cov-report=xml", "--cov=something"] } - runner = PythonStandardRunner(runner_config) + runner = PytestStandardRunner(runner_config) runner.process_labelanalysis_result( LabelAnalysisRequestResult(label_analysis_result) ) @@ -251,7 +251,7 @@ def test_process_label_analysis_skip_all_tests(self, mocker): "present_diff_labels": [], "global_level_labels": [], } - mock_execute = mocker.patch.object(PythonStandardRunner, "_execute_pytest") + mock_execute = mocker.patch.object(PytestStandardRunner, "_execute_pytest") self.runner.process_labelanalysis_result( LabelAnalysisRequestResult(label_analysis_result) diff --git a/tests/runners/test_runners.py b/tests/runners/test_runners.py index 69117101..5e869bf6 100644 --- a/tests/runners/test_runners.py +++ b/tests/runners/test_runners.py @@ -4,22 +4,34 @@ from codecov_cli.runners import _load_runner_from_yaml, get_runner from codecov_cli.runners.dan_runner import DoAnythingNowRunner -from codecov_cli.runners.python_standard_runner import PythonStandardRunner +from codecov_cli.runners.pytest_standard_runner import PytestStandardRunner from tests.factory import FakeRunner class TestRunners(object): def test_get_standard_runners(self): - assert isinstance(get_runner({}, "python"), PythonStandardRunner) + assert isinstance(get_runner({}, "pytest"), PytestStandardRunner) assert isinstance(get_runner({}, "dan"), DoAnythingNowRunner) # TODO: Extend with other standard runners once we create them (e.g. JS) - def test_python_standard_runner_with_options(self): + def test_pytest_standard_runner_with_options_backwards_compatible(self): config_params = dict( collect_tests_options=["--option=value", "-option"], ) - runner_instance = get_runner({"runners": {"python": config_params}}, "python") - assert isinstance(runner_instance, PythonStandardRunner) + runner_instance = get_runner({"runners": {"pytest": config_params}}, "pytest") + assert isinstance(runner_instance, PytestStandardRunner) + assert ( + runner_instance.params.collect_tests_options + == config_params["collect_tests_options"] + ) + assert runner_instance.params.coverage_root == "./" + + def test_pytest_standard_runner_with_options_backwards_compatible(self): + config_params = dict( + collect_tests_options=["--option=value", "-option"], + ) + runner_instance = get_runner({"runners": {"python": config_params}}, "pytest") + assert isinstance(runner_instance, PytestStandardRunner) assert ( runner_instance.params.collect_tests_options == config_params["collect_tests_options"] From dacaf276091a03e572901889d6a83f39008c8654 Mon Sep 17 00:00:00 2001 From: joseph-sentry <136376984+joseph-sentry@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:45:07 +0200 Subject: [PATCH 2/5] Add target arch flag and fix arch grep command --- .github/workflows/build_assets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_assets.yml b/.github/workflows/build_assets.yml index ec4a3058..2b8e0667 100644 --- a/.github/workflows/build_assets.yml +++ b/.github/workflows/build_assets.yml @@ -25,9 +25,9 @@ jobs: pip install --no-deps --no-index --find-links=pip-packages pip-packages/* CMD_BUILD: > STATICCODECOV_LIB_PATH=$(find build/ -maxdepth 1 -type d -name 'lib.*' -print -quit | xargs -I {} sh -c "find {} -type f -name 'staticcodecov*' -print -quit | sed 's|^./||'") && - pyinstaller --add-binary ${STATICCODECOV_LIB_PATH}:. --hidden-import staticcodecov_languages -F codecov_cli/main.py && + pyinstaller --add-binary ${STATICCODECOV_LIB_PATH}:. --hidden-import staticcodecov_languages --target-arch universal2 -F codecov_cli/main.py && mv dist/main dist/codecovcli_macos && - lipo -archs dist/codecovcli_macos | grep -v 'x86_64 arm64' >> /dev/null && exit 1 + lipo -archs dist/codecovcli_macos | grep 'x86_64 arm64' OUT_FILE_NAME: codecovcli_macos ASSET_MIME: application/octet-stream - os: ubuntu-20.04 From f14426f13f5c5170804d2f1f89bdc3a68d8ac115 Mon Sep 17 00:00:00 2001 From: joseph-sentry <136376984+joseph-sentry@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:00:48 +0200 Subject: [PATCH 3/5] Fix windows build --- .github/workflows/build_assets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_assets.yml b/.github/workflows/build_assets.yml index 2b8e0667..0ae1bead 100644 --- a/.github/workflows/build_assets.yml +++ b/.github/workflows/build_assets.yml @@ -45,7 +45,7 @@ jobs: CMD_REQS: > pip install -r requirements.txt CMD_BUILD: > - pyinstaller --add-binary "build\lib.win-amd64-cpython-310\staticcodecov_languages.cp310-win_amd64.pyd;." --hidden-import staticcodecov_languages -F codecov_cli\main.py && + pyinstaller --add-binary "build\lib.win-amd64-cpython-311\staticcodecov_languages.cp311-win_amd64.pyd;." --hidden-import staticcodecov_languages -F codecov_cli\main.py && Copy-Item -Path ".\dist\main.exe" -Destination ".\dist\codecovcli_windows.exe" OUT_FILE_NAME: codecovcli_windows.exe ASSET_MIME: application/vnd.microsoft.portable-executable From 6e916b9735ac4a58928fe61d1749a62f51ab7f05 Mon Sep 17 00:00:00 2001 From: Gguidini Date: Wed, 11 Oct 2023 11:16:16 +0200 Subject: [PATCH 4/5] fix: Try to fix httpx.PoolTimeout error This is an attempt to limit the httpx.PoolTimeout errors when uploading code. Fingers crossed the default limits work better for us. Let it be known that we don't know why the limits were chosen, so we are essentially winging it at this point. --- codecov_cli/services/staticanalysis/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codecov_cli/services/staticanalysis/__init__.py b/codecov_cli/services/staticanalysis/__init__.py index 7a9914a5..ecd347a8 100644 --- a/codecov_cli/services/staticanalysis/__init__.py +++ b/codecov_cli/services/staticanalysis/__init__.py @@ -103,8 +103,7 @@ async def run_analysis_entrypoint( length=len(files_that_need_upload), label="Uploading files", ) as bar: - limits = httpx.Limits(max_keepalive_connections=3, max_connections=5) - async with httpx.AsyncClient(limits=limits) as client: + async with httpx.AsyncClient() as client: all_tasks = [] for el in files_that_need_upload: all_tasks.append(send_single_upload_put(client, all_data, el)) From 8e1cbc97237fb6cdf9dea46d229cf451f3b8a5e9 Mon Sep 17 00:00:00 2001 From: codecov-releaser Date: Wed, 11 Oct 2023 09:32:01 +0000 Subject: [PATCH 5/5] Prepare release 0.3.8 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0276840a..f08fa314 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="codecov-cli", - version="0.3.7", + version="0.3.8", packages=find_packages(exclude=["contrib", "docs", "tests*"]), description="Codecov Command Line Interface", long_description=long_description,