diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 523b81e9394..f9e2d27bf16 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: check-docstring-first - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.11.0 + rev: 23.12.0 hooks: - id: black exclude: tests/([^/]*/)*fixtures/ @@ -32,6 +32,6 @@ repos: - id: validate_manifest - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 + rev: v0.1.8 hooks: - id: ruff diff --git a/src/poetry/installation/chef.py b/src/poetry/installation/chef.py index 4d5546969dd..c97ae727e41 100644 --- a/src/poetry/installation/chef.py +++ b/src/poetry/installation/chef.py @@ -35,13 +35,11 @@ class ChefBuildError(ChefError): ... class ChefInstallError(ChefError): def __init__(self, requirements: Collection[str], output: str, error: str) -> None: - message = "\n\n".join( - ( - f"Failed to install {', '.join(requirements)}.", - f"Output:\n{output}", - f"Error:\n{error}", - ) - ) + message = "\n\n".join(( + f"Failed to install {', '.join(requirements)}.", + f"Output:\n{output}", + f"Error:\n{error}", + )) super().__init__(message) self._requirements = requirements diff --git a/src/poetry/mixology/incompatibility.py b/src/poetry/mixology/incompatibility.py index 70ac39b3580..26bf72e79ba 100644 --- a/src/poetry/mixology/incompatibility.py +++ b/src/poetry/mixology/incompatibility.py @@ -255,13 +255,13 @@ def _try_requires_both( if this_positive.dependency != other_positive.dependency: return None - this_negatives = " or ".join([ - self._terse(term) for term in self._terms if not term.is_positive() - ]) + this_negatives = " or ".join( + [self._terse(term) for term in self._terms if not term.is_positive()] + ) - other_negatives = " or ".join([ - self._terse(term) for term in other.terms if not term.is_positive() - ]) + other_negatives = " or ".join( + [self._terse(term) for term in other.terms if not term.is_positive()] + ) buffer = [self._terse(this_positive, allow_every=True) + " "] is_dependency = isinstance(self.cause, DependencyCause) and isinstance( @@ -355,9 +355,9 @@ def _try_requires_through( buffer.append("requires ") buffer.append( - " or ".join([ - self._terse(term) for term in latter.terms if not term.is_positive() - ]) + " or ".join( + [self._terse(term) for term in latter.terms if not term.is_positive()] + ) ) if latter_line is not None: diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index b139b5c8e7a..dc39ee11469 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -347,12 +347,10 @@ def _search_for_file(self, dependency: FileDependency) -> Package: if dependency.base is not None: package.root_dir = dependency.base - package.files = [ - { - "file": dependency.path.name, - "hash": "sha256:" + get_file_hash(dependency.full_path), - } - ] + package.files = [{ + "file": dependency.path.name, + "hash": "sha256:" + get_file_hash(dependency.full_path), + }] return package diff --git a/tests/console/commands/self/test_show_plugins.py b/tests/console/commands/self/test_show_plugins.py index 63928bbc214..880f821e790 100644 --- a/tests/console/commands/self/test_show_plugins.py +++ b/tests/console/commands/self/test_show_plugins.py @@ -147,12 +147,10 @@ def mock_metadata_entry_points( @pytest.mark.parametrize("entry_point_name", ["poetry-plugin", "not-package-name"]) @pytest.mark.parametrize( "entry_point_values_by_group", - [ - { - ApplicationPlugin.group: ["FirstApplicationPlugin"], - Plugin.group: ["FirstPlugin"], - } - ], + [{ + ApplicationPlugin.group: ["FirstApplicationPlugin"], + Plugin.group: ["FirstPlugin"], + }], ) def test_show_displays_installed_plugins( app: PoetryTestApplication, @@ -170,15 +168,13 @@ def test_show_displays_installed_plugins( @pytest.mark.parametrize( "entry_point_values_by_group", - [ - { - ApplicationPlugin.group: [ - "FirstApplicationPlugin", - "SecondApplicationPlugin", - ], - Plugin.group: ["FirstPlugin", "SecondPlugin"], - } - ], + [{ + ApplicationPlugin.group: [ + "FirstApplicationPlugin", + "SecondApplicationPlugin", + ], + Plugin.group: ["FirstPlugin", "SecondPlugin"], + }], ) def test_show_displays_installed_plugins_with_multiple_plugins( app: PoetryTestApplication, @@ -199,12 +195,10 @@ def test_show_displays_installed_plugins_with_multiple_plugins( ) @pytest.mark.parametrize( "entry_point_values_by_group", - [ - { - ApplicationPlugin.group: ["FirstApplicationPlugin"], - Plugin.group: ["FirstPlugin"], - } - ], + [{ + ApplicationPlugin.group: ["FirstApplicationPlugin"], + Plugin.group: ["FirstPlugin"], + }], ) def test_show_displays_installed_plugins_with_dependencies( app: PoetryTestApplication, diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py index 3e0ee145ecd..f45f12ad9f7 100644 --- a/tests/console/commands/test_show.py +++ b/tests/console/commands/test_show.py @@ -2026,21 +2026,19 @@ def test_url_dependency_is_not_outdated_by_repository_package( assert isinstance(poetry.locker, TestLocker) poetry.locker.mock_lock_data({ - "package": [ - { - "name": "demo", - "version": "0.1.0", - "description": "Demo package", - "optional": False, - "platform": "*", - "python-versions": "*", - "checksum": [], - "source": { - "type": "url", - "url": demo_url, - }, - } - ], + "package": [{ + "name": "demo", + "version": "0.1.0", + "description": "Demo package", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + "source": { + "type": "url", + "url": demo_url, + }, + }], "metadata": { "python-versions": "*", "platform": "*", diff --git a/tests/installation/test_chooser.py b/tests/installation/test_chooser.py index c2027dcbd29..0a27b5c7afe 100644 --- a/tests/installation/test_chooser.py +++ b/tests/installation/test_chooser.py @@ -275,12 +275,12 @@ def test_chooser_chooses_distributions_that_match_the_package_hashes( chooser = Chooser(pool, env) package = Package("isort", "4.3.4") - files = [ - { - "hash": "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8", - "filename": "isort-4.3.4.tar.gz", - } - ] + files = [{ + "hash": ( + "sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8" + ), + "filename": "isort-4.3.4.tar.gz", + }] if source_type == "legacy": package = Package( package.name, @@ -308,12 +308,12 @@ def test_chooser_chooses_yanked_if_no_others( chooser = Chooser(pool, env) package = Package("black", "21.11b0") - files = [ - { - "filename": "black-21.11b0-py3-none-any.whl", - "hash": "sha256:0b1f66cbfadcd332ceeaeecf6373d9991d451868d2e2219ad0ac1213fb701117", - } - ] + files = [{ + "filename": "black-21.11b0-py3-none-any.whl", + "hash": ( + "sha256:0b1f66cbfadcd332ceeaeecf6373d9991d451868d2e2219ad0ac1213fb701117" + ), + }] if source_type == "legacy": package = Package( package.name, @@ -385,12 +385,12 @@ def test_chooser_throws_an_error_if_package_hashes_do_not_match( chooser = Chooser(pool, env) package = Package("isort", "4.3.4") - files = [ - { - "hash": "sha256:0000000000000000000000000000000000000000000000000000000000000000", - "filename": "isort-4.3.4.tar.gz", - } - ] + files = [{ + "hash": ( + "sha256:0000000000000000000000000000000000000000000000000000000000000000" + ), + "filename": "isort-4.3.4.tar.gz", + }] if source_type == "legacy": package = Package( package.name, @@ -419,11 +419,11 @@ def test_chooser_md5_remote_fallback_to_sha256_inline_calculation( source_reference="foo", source_url="https://foo.bar/simple/", ) - package.files = [ - { - "hash": "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad", - "filename": "demo-0.1.0.tar.gz", - } - ] + package.files = [{ + "hash": ( + "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad" + ), + "filename": "demo-0.1.0.tar.gz", + }] res = chooser.choose_for(package) assert res.filename == "demo-0.1.0.tar.gz" diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 609ec749566..17aeba7b8fd 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -372,9 +372,9 @@ def test_execute_shows_skipped_operations_if_verbose( executor.verbose() assert ( - executor.execute([ - Uninstall(Package("clikit", "0.2.3")).skip("Not currently installed") - ]) + executor.execute( + [Uninstall(Package("clikit", "0.2.3")).skip("Not currently installed")] + ) == 0 ) @@ -626,12 +626,12 @@ def test_executor_should_not_write_pep610_url_references_for_cached_package( io: BufferedIO, ) -> None: link_cached = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl" - package.files = [ - { - "file": "demo-0.1.0-py2.py3-none-any.whl", - "hash": "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a", - } - ] + package.files = [{ + "file": "demo-0.1.0-py2.py3-none-any.whl", + "hash": ( + "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a" + ), + }] mocker.patch( "poetry.installation.executor.Executor._download", return_value=link_cached @@ -653,12 +653,12 @@ def test_executor_should_write_pep610_url_references_for_wheel_files( url = (fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl").resolve() package = Package("demo", "0.1.0", source_type="file", source_url=url.as_posix()) # Set package.files so the executor will attempt to hash the package - package.files = [ - { - "file": "demo-0.1.0-py2.py3-none-any.whl", - "hash": "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a", - } - ] + package.files = [{ + "file": "demo-0.1.0-py2.py3-none-any.whl", + "hash": ( + "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a" + ), + }] executor = Executor(tmp_venv, pool, config, io) executor.execute([Install(package)]) @@ -687,12 +687,12 @@ def test_executor_should_write_pep610_url_references_for_non_wheel_files( url = (fixture_dir("distributions") / "demo-0.1.0.tar.gz").resolve() package = Package("demo", "0.1.0", source_type="file", source_url=url.as_posix()) # Set package.files so the executor will attempt to hash the package - package.files = [ - { - "file": "demo-0.1.0.tar.gz", - "hash": "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad", - } - ] + package.files = [{ + "file": "demo-0.1.0.tar.gz", + "hash": ( + "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad" + ), + }] executor = Executor(tmp_venv, pool, config, io) executor.execute([Install(package)]) @@ -796,12 +796,12 @@ def test_executor_should_write_pep610_url_references_for_wheel_urls( source_url="https://files.pythonhosted.org/demo-0.1.0-py2.py3-none-any.whl", ) # Set package.files so the executor will attempt to hash the package - package.files = [ - { - "file": "demo-0.1.0-py2.py3-none-any.whl", - "hash": "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a", - } - ] + package.files = [{ + "file": "demo-0.1.0-py2.py3-none-any.whl", + "hash": ( + "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a" + ), + }] executor = Executor(tmp_venv, pool, config, io) operation = Install(package) @@ -890,12 +890,12 @@ def mock_get_cached_archive_func( source_url="https://files.pythonhosted.org/demo-0.1.0.tar.gz", ) # Set package.files so the executor will attempt to hash the package - package.files = [ - { - "file": "demo-0.1.0.tar.gz", - "hash": "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad", - } - ] + package.files = [{ + "file": "demo-0.1.0.tar.gz", + "hash": ( + "sha256:9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad" + ), + }] executor = Executor(tmp_venv, pool, config, io) operation = Install(package) diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index be9aa175c59..b903348c4d9 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -696,16 +696,14 @@ def test_run_whitelist_add( ) -> None: locker.locked(True) locker.mock_lock_data({ - "package": [ - { - "name": "A", - "version": "1.0", - "optional": False, - "platform": "*", - "python-versions": "*", - "checksum": [], - } - ], + "package": [{ + "name": "A", + "version": "1.0", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + }], "metadata": { "python-versions": "*", "platform": "*", @@ -1295,16 +1293,14 @@ def test_run_with_prereleases( ) -> None: locker.locked(True) locker.mock_lock_data({ - "package": [ - { - "name": "A", - "version": "1.0a2", - "optional": False, - "platform": "*", - "python-versions": "*", - "checksum": [], - } - ], + "package": [{ + "name": "A", + "version": "1.0a2", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + }], "metadata": { "python-versions": "*", "platform": "*", @@ -1337,16 +1333,14 @@ def test_run_update_all_with_lock( ) -> None: locker.locked(True) locker.mock_lock_data({ - "package": [ - { - "name": "A", - "version": "1.0", - "optional": True, - "platform": "*", - "python-versions": "*", - "checksum": [], - } - ], + "package": [{ + "name": "A", + "version": "1.0", + "optional": True, + "platform": "*", + "python-versions": "*", + "checksum": [], + }], "metadata": { "python-versions": "*", "platform": "*", diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index fb9581037f4..0ee6431d15c 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -404,9 +404,9 @@ def test_relative_submodules_with_ssh( ) # construct fake git config - fake_config = ConfigFile({ - (b"remote", b"origin"): {b"url": ssh_source_url.encode("utf-8")} - }) + fake_config = ConfigFile( + {(b"remote", b"origin"): {b"url": ssh_source_url.encode("utf-8")}} + ) # trick Git into thinking remote.origin is an ssh url mock_get_config = mocker.patch.object(repo_with_unresolved_submodules, "get_config") mock_get_config.return_value = fake_config diff --git a/tests/publishing/test_publisher.py b/tests/publishing/test_publisher.py index 04e4a745c5a..ace0893edd6 100644 --- a/tests/publishing/test_publisher.py +++ b/tests/publishing/test_publisher.py @@ -29,9 +29,9 @@ def test_publish_publishes_to_pypi_by_default( uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry._config = config - poetry.config.merge({ - "http-basic": {"pypi": {"username": "foo", "password": "bar"}} - }) + poetry.config.merge( + {"http-basic": {"pypi": {"username": "foo", "password": "bar"}}} + ) publisher = Publisher(poetry, NullIO()) publisher.publish(None, None, None) @@ -80,9 +80,9 @@ def test_publish_raises_error_for_undefined_repository( ) -> None: poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry._config = config - poetry.config.merge({ - "http-basic": {"my-repo": {"username": "foo", "password": "bar"}} - }) + poetry.config.merge( + {"http-basic": {"my-repo": {"username": "foo", "password": "bar"}}} + ) publisher = Publisher(poetry, NullIO()) with pytest.raises(RuntimeError): diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index 29e12394dce..8de5f34a76d 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -2959,18 +2959,16 @@ def test_solver_can_solve_with_legacy_repository_using_proper_python_compatible_ check_solver_result( transaction, - [ - { - "job": "install", - "package": Package( - "isort", - "4.3.4", - source_type="legacy", - source_url=repo.url, - source_reference=repo.name, - ), - } - ], + [{ + "job": "install", + "package": Package( + "isort", + "4.3.4", + source_type="legacy", + source_url=repo.url, + source_reference=repo.name, + ), + }], ) @@ -3053,18 +3051,16 @@ def test_solver_chooses_from_correct_repository_if_forced( ops = check_solver_result( transaction, - [ - { - "job": "install", - "package": Package( - "tomlkit", - "0.5.2", - source_type="legacy", - source_url=repo.url, - source_reference=repo.name, - ), - } - ], + [{ + "job": "install", + "package": Package( + "tomlkit", + "0.5.2", + source_type="legacy", + source_url=repo.url, + source_reference=repo.name, + ), + }], ) assert ops[0].package.source_url == "http://legacy.foo.bar" diff --git a/tests/puzzle/test_transaction.py b/tests/puzzle/test_transaction.py index 03ad5f2b2cf..f17660b9425 100644 --- a/tests/puzzle/test_transaction.py +++ b/tests/puzzle/test_transaction.py @@ -149,36 +149,32 @@ def test_it_should_not_remove_installed_packages_that_are_in_result() -> None: def test_it_should_update_installed_packages_if_sources_are_different() -> None: transaction = Transaction( [Package("a", "1.0.0")], - [ - ( - Package( - "a", - "1.0.0", - source_url="https://github.com/demo/demo.git", - source_type="git", - source_reference="main", - source_resolved_reference="123456", - ), - 1, - ) - ], + [( + Package( + "a", + "1.0.0", + source_url="https://github.com/demo/demo.git", + source_type="git", + source_reference="main", + source_resolved_reference="123456", + ), + 1, + )], installed_packages=[Package("a", "1.0.0")], ) check_operations( transaction.calculate_operations(synchronize=True), - [ - { - "job": "update", - "from": Package("a", "1.0.0"), - "to": Package( - "a", - "1.0.0", - source_url="https://github.com/demo/demo.git", - source_type="git", - source_reference="main", - source_resolved_reference="123456", - ), - } - ], + [{ + "job": "update", + "from": Package("a", "1.0.0"), + "to": Package( + "a", + "1.0.0", + source_url="https://github.com/demo/demo.git", + source_type="git", + source_reference="main", + source_resolved_reference="123456", + ), + }], ) diff --git a/tests/repositories/test_legacy_repository.py b/tests/repositories/test_legacy_repository.py index e8db812e3c8..3577836d420 100644 --- a/tests/repositories/test_legacy_repository.py +++ b/tests/repositories/test_legacy_repository.py @@ -422,12 +422,12 @@ def test_get_package_retrieves_packages_with_no_hashes() -> None: package = repo.package("jupyter", Version.parse("1.0.0")) - assert [ - { - "file": "jupyter-1.0.0.tar.gz", - "hash": "sha256:d9dc4b3318f310e34c82951ea5d6683f67bed7def4b259fafbfe4f1beb1d8e5f", - } - ] == package.files + assert [{ + "file": "jupyter-1.0.0.tar.gz", + "hash": ( + "sha256:d9dc4b3318f310e34c82951ea5d6683f67bed7def4b259fafbfe4f1beb1d8e5f" + ), + }] == package.files @pytest.mark.parametrize( diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 28181381549..90bced13f27 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1308,12 +1308,14 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( if "VIRTUAL_ENV" in os.environ: del os.environ["VIRTUAL_ENV"] - config.merge({ - "virtualenvs": { - "path": str(tmp_path / "virtualenvs"), - "in-project": True, + config.merge( + { + "virtualenvs": { + "path": str(tmp_path / "virtualenvs"), + "in-project": True, + } } - }) + ) mocker.patch("shutil.which", side_effect=lambda py: f"/usr/bin/{py}") mocker.patch( @@ -1665,17 +1667,15 @@ def test_build_environment_called_build_script_specified( with build_environment(extended_without_setup_poetry, project_env) as env: assert env == ephemeral_env - assert env.executed == [ # type: ignore[attr-defined] - [ - str(sys.executable), - str(env.pip_embedded), - "install", - "--disable-pip-version-check", - "--ignore-installed", - "--no-input", - *extended_without_setup_poetry.pyproject.build_system.requires, - ] - ] + assert env.executed == [[ # type: ignore[attr-defined] + str(sys.executable), + str(env.pip_embedded), + "install", + "--disable-pip-version-check", + "--ignore-installed", + "--no-input", + *extended_without_setup_poetry.pyproject.build_system.requires, + ]] def test_build_environment_not_called_without_build_script_specified(