def test_with_compatible_locked_dependencies_with_extras( root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "^1.0")) package_foo_0 = get_package("foo", "1.0.0") package_foo_1 = get_package("foo", "1.0.1") bar_extra_dep = Factory.create_dependency("bar", { "version": "^1.0", "extras": "extra" }) for package_foo in (package_foo_0, package_foo_1): package_foo.add_dependency(bar_extra_dep) repo.add_package(package_foo) bar_deps = {"baz": {"version": "^1.0", "extras": ["extra"]}} add_to_repo(repo, "bar", "1.0.0", bar_deps) add_to_repo(repo, "bar", "1.0.1", bar_deps) add_to_repo(repo, "baz", "1.0.0") add_to_repo(repo, "baz", "1.0.1") check_solver_result( root, provider, result={ "foo": "1.0.0", "bar": "1.0.0", "baz": "1.0.0" }, locked={ "foo": get_package("foo", "1.0.0"), "bar": get_package("bar", "1.0.0"), "baz": get_package("baz", "1.0.0"), }, )
def test_package_with_the_same_name_gives_clear_error_message( root: ProjectPackage, provider: Provider, repo: Repository): pkg_name = "a" root.add_dependency(Factory.create_dependency(pkg_name, "*")) add_to_repo(repo, pkg_name, "1.0.0", deps={pkg_name: "1.0.0"}) error = f"Package '{pkg_name}' is listed as a dependency of itself." check_solver_result(root, provider, error=error)
def test_unlocks_dependencies_if_necessary_to_ensure_that_a_new_dependency_is_satisfied( root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "*")) root.add_dependency(Factory.create_dependency("newdep", "2.0.0")) add_to_repo(repo, "foo", "1.0.0", deps={"bar": "<2.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"baz": "<2.0.0"}) add_to_repo(repo, "baz", "1.0.0", deps={"qux": "<2.0.0"}) add_to_repo(repo, "qux", "1.0.0") add_to_repo(repo, "foo", "2.0.0", deps={"bar": "<3.0.0"}) add_to_repo(repo, "bar", "2.0.0", deps={"baz": "<3.0.0"}) add_to_repo(repo, "baz", "2.0.0", deps={"qux": "<3.0.0"}) add_to_repo(repo, "qux", "2.0.0") add_to_repo(repo, "newdep", "2.0.0", deps={"baz": ">=1.5.0"}) check_solver_result( root, provider, result={ "foo": "2.0.0", "bar": "2.0.0", "baz": "2.0.0", "qux": "1.0.0", "newdep": "2.0.0", }, locked={ "foo": get_package("foo", "2.0.0"), "bar": get_package("bar", "1.0.0"), "baz": get_package("baz", "1.0.0"), "qux": get_package("qux", "1.0.0"), }, )
def _update_with_new_method(self, version): from poetry.config.config import Config from poetry.core.packages.dependency import Dependency from poetry.core.packages.project_package import ProjectPackage from poetry.installation.installer import Installer from poetry.packages.locker import NullLocker from poetry.repositories.installed_repository import InstalledRepository from poetry.utils.env import EnvManager env = EnvManager.get_system_env(naive=True) installed = InstalledRepository.load(env) root = ProjectPackage("poetry-updater", "0.0.0") root.python_versions = ".".join(str(c) for c in env.version_info[:3]) root.add_dependency(Dependency("poetry", version.text)) installer = Installer( self.io, env, root, NullLocker(self.data_dir.joinpath("poetry.lock"), {}), self.pool, Config(), installed=installed, ) installer.update(True) installer.run()
def _add_package_group_dependencies( cls, package: ProjectPackage, group: str | DependencyGroup, dependencies: DependencyConfig, ) -> None: from poetry.core.packages.dependency_group import MAIN_GROUP if isinstance(group, str): if package.has_dependency_group(group): group = package.dependency_group(group) else: from poetry.core.packages.dependency_group import DependencyGroup group = DependencyGroup(group) for name, constraints in dependencies.items(): _constraints = (constraints if isinstance(constraints, list) else [constraints]) for _constraint in _constraints: if name.lower() == "python": if group.name == MAIN_GROUP and isinstance( _constraint, str): package.python_versions = _constraint continue group.add_dependency( cls.create_dependency( name, _constraint, groups=[group.name], root_dir=package.root_dir, )) package.add_dependency_group(group)
def install_plugin(installed: Repository) -> None: package = ProjectPackage("poetry-instance", __version__) plugin = Package("poetry-plugin", "1.2.3") package.add_dependency( Dependency(plugin.name, "^1.2.3", groups=[SelfCommand.ADDITIONAL_PACKAGE_GROUP]) ) content = Factory.create_pyproject_from_package(package) system_pyproject_file = SelfCommand.get_default_system_pyproject_file() system_pyproject_file.write_text(content.as_string(), encoding="utf-8") lock_content = { "package": [ { "name": "poetry-plugin", "version": "1.2.3", "category": "main", "optional": False, "platform": "*", "python-versions": "*", "checksum": [], }, ], "metadata": { "python-versions": "^3.6", "platform": "*", "content-hash": "123456789", "hashes": {"poetry-plugin": []}, }, } system_pyproject_file.parent.joinpath("poetry.lock").write_text( tomlkit.dumps(lock_content), encoding="utf-8" ) installed.add_package(plugin)
def test_deprecation_warning(tester: CommandTester, repo: TestRepository) -> None: plugin = Package("poetry-plugin", "1.2.3") repo.add_package(Package("poetry", __version__)) repo.add_package(plugin) package = ProjectPackage("poetry-instance", __version__) package.add_dependency( Dependency(plugin.name, "^1.2.3", groups=[SelfCommand.ADDITIONAL_PACKAGE_GROUP])) content = Factory.create_pyproject_from_package(package) system_pyproject_file = SelfCommand.get_default_system_pyproject_file() system_pyproject_file.write_text(content.as_string(), encoding="utf-8") dependencies = get_self_command_dependencies(locked=False) assert "poetry-plugin" in dependencies tester.execute("poetry-plugin") assert (tester.io.fetch_error() == "This command is deprecated. Use self remove command instead.\n") dependencies = get_self_command_dependencies() assert "poetry-plugin" not in dependencies assert not dependencies
def test_with_compatible_locked_dependencies_use_latest( root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "*")) root.add_dependency(Factory.create_dependency("baz", "*")) add_to_repo(repo, "foo", "1.0.0", deps={"bar": "1.0.0"}) add_to_repo(repo, "foo", "1.0.1", deps={"bar": "1.0.1"}) add_to_repo(repo, "foo", "1.0.2", deps={"bar": "1.0.2"}) add_to_repo(repo, "bar", "1.0.0") add_to_repo(repo, "bar", "1.0.1") add_to_repo(repo, "bar", "1.0.2") add_to_repo(repo, "baz", "1.0.0") add_to_repo(repo, "baz", "1.0.1") check_solver_result( root, provider, result={ "foo": "1.0.2", "bar": "1.0.2", "baz": "1.0.0" }, locked={ "foo": get_package("foo", "1.0.1"), "bar": get_package("bar", "1.0.1"), "baz": get_package("baz", "1.0.0"), }, use_latest=["foo"], )
def test_simple_dependencies( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("a", "1.0.0")) root.add_dependency(Factory.create_dependency("b", "1.0.0")) add_to_repo(repo, "a", "1.0.0", deps={"aa": "1.0.0", "ab": "1.0.0"}) add_to_repo(repo, "b", "1.0.0", deps={"ba": "1.0.0", "bb": "1.0.0"}) add_to_repo(repo, "aa", "1.0.0") add_to_repo(repo, "ab", "1.0.0") add_to_repo(repo, "ba", "1.0.0") add_to_repo(repo, "bb", "1.0.0") check_solver_result( root, provider, { "a": "1.0.0", "aa": "1.0.0", "ab": "1.0.0", "b": "1.0.0", "ba": "1.0.0", "bb": "1.0.0", }, )
def test_circular_dependency( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("foo", "1.0.0")) add_to_repo(repo, "foo", "1.0.0", deps={"bar": "1.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"foo": "1.0.0"}) check_solver_result(root, provider, {"foo": "1.0.0", "bar": "1.0.0"})
def test_solver_dependency_cache_respects_subdirectories( root: ProjectPackage, provider: Provider, repo: Repository): dependency_one = Factory.create_dependency( "one", { "git": "https://github.com/demo/subdirectories.git", "subdirectory": "one", "platform": "linux", }, ) dependency_one_copy = Factory.create_dependency( "one", { "git": "https://github.com/demo/subdirectories.git", "subdirectory": "one-copy", "platform": "win32", }, ) root.add_dependency(dependency_one) root.add_dependency(dependency_one_copy) cache = DependencyCache(provider) cache.search_for.cache_clear() # ensure cache was never hit for both calls cache.search_for(dependency_one) cache.search_for(dependency_one_copy) assert not cache.search_for.cache_info().hits # increase test coverage by searching for copies # (when searching for the exact same object, __eq__ is never called) packages_one = cache.search_for(deepcopy(dependency_one)) packages_one_copy = cache.search_for(deepcopy(dependency_one_copy)) assert cache.search_for.cache_info().hits == 2 assert cache.search_for.cache_info().currsize == 2 assert len(packages_one) == len(packages_one_copy) == 1 package_one = packages_one[0] package_one_copy = packages_one_copy[0] assert package_one.package.name == package_one_copy.name assert package_one.package.version.text == package_one_copy.package.version.text assert package_one.package.source_type == package_one_copy.source_type == "git" assert (package_one.package.source_resolved_reference == package_one_copy.source_resolved_reference == "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24") assert (package_one.package.source_subdirectory != package_one_copy.source_subdirectory) assert package_one.package.source_subdirectory == "one" assert package_one_copy.package.source_subdirectory == "one-copy" assert package_one.dependency.marker.intersect( package_one_copy.dependency.marker).is_empty()
def test_circular_dependency_on_older_version( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("a", ">=1.0.0")) add_to_repo(repo, "a", "1.0.0") add_to_repo(repo, "a", "2.0.0", deps={"b": "1.0.0"}) add_to_repo(repo, "b", "1.0.0", deps={"a": "1.0.0"}) check_solver_result(root, provider, {"a": "1.0.0"}, tries=2)
def test_disjoint_root_constraints(root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "1.0.0")) root.add_dependency(Factory.create_dependency("foo", "2.0.0")) add_to_repo(repo, "foo", "1.0.0") add_to_repo(repo, "foo", "2.0.0") error = """\ Because myapp depends on both foo (1.0.0) and foo (2.0.0), version solving failed.""" check_solver_result(root, provider, error=error)
def test_no_version_matching_constraint(root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "^1.0")) add_to_repo(repo, "foo", "2.0.0") add_to_repo(repo, "foo", "2.1.3") check_solver_result( root, provider, error=("Because myapp depends on foo (^1.0) " "which doesn't match any versions, version solving failed."), )
def test_shared_dependencies_with_overlapping_constraints( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("a", "1.0.0")) root.add_dependency(Factory.create_dependency("b", "1.0.0")) add_to_repo(repo, "a", "1.0.0", deps={"shared": ">=2.0.0 <4.0.0"}) add_to_repo(repo, "b", "1.0.0", deps={"shared": ">=3.0.0 <5.0.0"}) add_to_repo(repo, "shared", "2.0.0") add_to_repo(repo, "shared", "3.0.0") add_to_repo(repo, "shared", "3.6.9") add_to_repo(repo, "shared", "4.0.0") add_to_repo(repo, "shared", "5.0.0") check_solver_result(root, provider, {"a": "1.0.0", "b": "1.0.0", "shared": "3.6.9"})
def test_rolls_back_leaf_versions_first( root: ProjectPackage, provider: Provider, repo: Repository ): # The latest versions of a and b disagree on c. An older version of either # will resolve the problem. This test validates that b, which is farther # in the dependency graph from myapp is downgraded first. root.add_dependency(Factory.create_dependency("a", "*")) add_to_repo(repo, "a", "1.0.0", deps={"b": "*"}) add_to_repo(repo, "a", "2.0.0", deps={"b": "*", "c": "2.0.0"}) add_to_repo(repo, "b", "1.0.0") add_to_repo(repo, "b", "2.0.0", deps={"c": "1.0.0"}) add_to_repo(repo, "c", "1.0.0") add_to_repo(repo, "c", "2.0.0") check_solver_result(root, provider, {"a": "2.0.0", "b": "1.0.0", "c": "2.0.0"})
def test_diamond_dependency_graph( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("a", "*")) root.add_dependency(Factory.create_dependency("b", "*")) add_to_repo(repo, "a", "2.0.0", deps={"c": "^1.0.0"}) add_to_repo(repo, "a", "1.0.0") add_to_repo(repo, "b", "2.0.0", deps={"c": "^3.0.0"}) add_to_repo(repo, "b", "1.0.0", deps={"c": "^2.0.0"}) add_to_repo(repo, "c", "3.0.0") add_to_repo(repo, "c", "2.0.0") add_to_repo(repo, "c", "1.0.0") check_solver_result(root, provider, {"a": "1.0.0", "b": "2.0.0", "c": "3.0.0"})
def test_complete_package_preserves_source_type(provider: Provider, root: ProjectPackage) -> None: fixtures = Path(__file__).parent.parent / "fixtures" project_dir = fixtures.joinpath("with_conditional_path_deps") for folder in ["demo_one", "demo_two"]: path = (project_dir / folder).as_posix() root.add_dependency(Factory.create_dependency("demo", {"path": path})) complete_package = provider.complete_package( DependencyPackage(root.to_dependency(), root)) requires = complete_package.package.all_requires assert len(requires) == 2 assert {requires[0].source_url, requires[1].source_url} == { project_dir.joinpath("demo_one").as_posix(), project_dir.joinpath("demo_two").as_posix(), }
def test_dependency_does_not_match_root_python_constraint( root: ProjectPackage, provider: Provider, repo: Repository): provider.set_package_python_versions("^3.6") root.add_dependency(Factory.create_dependency("foo", "*")) add_to_repo(repo, "foo", "1.0.0", python="<3.5") error = """\ The current project's Python requirement (>=3.6,<4.0) is not compatible with some of\ the required packages Python requirement: - foo requires Python <3.5, so it will not be satisfied for Python >=3.6,<4.0 Because no versions of foo match !=1.0.0 and foo (1.0.0) requires Python <3.5, foo is forbidden. So, because myapp depends on foo (*), version solving failed.""" check_solver_result(root, provider, error=error)
def test_simple_transitive(root: ProjectPackage, provider: Provider, repo: Repository): # Only one version of baz, so foo and bar will have to downgrade # until they reach it root.add_dependency(Factory.create_dependency("foo", "*")) add_to_repo(repo, "foo", "1.0.0", deps={"bar": "1.0.0"}) add_to_repo(repo, "foo", "2.0.0", deps={"bar": "2.0.0"}) add_to_repo(repo, "foo", "3.0.0", deps={"bar": "3.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"baz": "*"}) add_to_repo(repo, "bar", "2.0.0", deps={"baz": "2.0.0"}) add_to_repo(repo, "bar", "3.0.0", deps={"baz": "3.0.0"}) add_to_repo(repo, "baz", "1.0.0") check_solver_result( root, provider, {"foo": "1.0.0", "bar": "1.0.0", "baz": "1.0.0"}, tries=3 )
def test_backjump_past_failed_package_on_disjoint_constraint( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("a", "*")) root.add_dependency(Factory.create_dependency("foo", ">2.0.0")) add_to_repo(repo, "a", "1.0.0", deps={"foo": "*"}) # ok add_to_repo( repo, "a", "2.0.0", deps={"foo": "<1.0.0"} ) # disjoint with myapp's constraint on foo add_to_repo(repo, "foo", "2.0.0") add_to_repo(repo, "foo", "2.0.1") add_to_repo(repo, "foo", "2.0.2") add_to_repo(repo, "foo", "2.0.3") add_to_repo(repo, "foo", "2.0.4") check_solver_result(root, provider, {"a": "1.0.0", "foo": "2.0.4"})
def test_shared_dependency_where_dependent_version_affects_other_dependencies( root: ProjectPackage, provider: Provider, repo: Repository ): root.add_dependency(Factory.create_dependency("foo", "<=1.0.2")) root.add_dependency(Factory.create_dependency("bar", "1.0.0")) add_to_repo(repo, "foo", "1.0.0") add_to_repo(repo, "foo", "1.0.1", deps={"bang": "1.0.0"}) add_to_repo(repo, "foo", "1.0.2", deps={"whoop": "1.0.0"}) add_to_repo(repo, "foo", "1.0.3", deps={"zoop": "1.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"foo": "<=1.0.1"}) add_to_repo(repo, "bang", "1.0.0") add_to_repo(repo, "whoop", "1.0.0") add_to_repo(repo, "zoop", "1.0.0") check_solver_result( root, provider, {"foo": "1.0.1", "bar": "1.0.0", "bang": "1.0.0"} )
def test_disjoint_root_constraints_path_dependencies(root: ProjectPackage, provider: Provider, repo: Repository): provider.set_package_python_versions("^3.7") fixtures = Path(__file__).parent.parent.parent / "fixtures" project_dir = fixtures.joinpath("with_conditional_path_deps") dependency1 = Factory.create_dependency("demo", {"path": project_dir / "demo_one"}) root.add_dependency(dependency1) dependency2 = Factory.create_dependency("demo", {"path": project_dir / "demo_two"}) root.add_dependency(dependency2) error = ( f"Because myapp depends on both {str(dependency1).replace('*', '1.2.3')} " f"and {str(dependency2).replace('*', '1.2.3')}, version solving failed." ) check_solver_result(root, provider, error=error)
def poetry(tmp_dir: str, config: Config) -> Poetry: poetry = Poetry( CWD / "pyproject.toml", {}, ProjectPackage("simple-project", "1.2.3"), Locker(CWD / "poetry.lock", {}), config, ) return poetry
def test_disjoint_constraints(root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "1.0.0")) root.add_dependency(Factory.create_dependency("bar", "1.0.0")) add_to_repo(repo, "foo", "1.0.0", deps={"shared": "<=2.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"shared": ">3.0.0"}) add_to_repo(repo, "shared", "2.0.0") add_to_repo(repo, "shared", "4.0.0") error = """\ Because bar (1.0.0) depends on shared (>3.0.0) and foo (1.0.0) depends on shared (<=2.0.0),\ bar (1.0.0) is incompatible with foo (1.0.0). So, because myapp depends on both foo (1.0.0) and bar (1.0.0), version solving failed.\ """ check_solver_result(root, provider, error=error) check_solver_result(root, provider, error=error)
def test_solver_dependency_cache_respects_source_type(root: ProjectPackage, provider: Provider, repo: Repository): dependency_pypi = Factory.create_dependency("demo", ">=0.1.0") dependency_git = Factory.create_dependency( "demo", {"git": "https://github.com/demo/demo.git"}, groups=["dev"]) root.add_dependency(dependency_pypi) root.add_dependency(dependency_git) add_to_repo(repo, "demo", "1.0.0") cache = DependencyCache(provider) cache.search_for.cache_clear() # ensure cache was never hit for both calls cache.search_for(dependency_pypi) cache.search_for(dependency_git) assert not cache.search_for.cache_info().hits # increase test coverage by searching for copies # (when searching for the exact same object, __eq__ is never called) packages_pypi = cache.search_for(deepcopy(dependency_pypi)) packages_git = cache.search_for(deepcopy(dependency_git)) assert cache.search_for.cache_info().hits == 2 assert cache.search_for.cache_info().currsize == 2 assert len(packages_pypi) == len(packages_git) == 1 assert packages_pypi != packages_git package_pypi = packages_pypi[0] package_git = packages_git[0] assert package_pypi.package.name == dependency_pypi.name assert package_pypi.package.version.text == "1.0.0" assert package_git.package.name == dependency_git.name assert package_git.package.version.text == "0.1.2" assert package_git.package.source_type == dependency_git.source_type assert package_git.package.source_url == dependency_git.source_url assert (package_git.package.source_resolved_reference == "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24")
def test_no_valid_solution(root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("a", "*")) root.add_dependency(Factory.create_dependency("b", "*")) add_to_repo(repo, "a", "1.0.0", deps={"b": "1.0.0"}) add_to_repo(repo, "a", "2.0.0", deps={"b": "2.0.0"}) add_to_repo(repo, "b", "1.0.0", deps={"a": "2.0.0"}) add_to_repo(repo, "b", "2.0.0", deps={"a": "1.0.0"}) error = """\ Because no versions of b match <1.0.0 || >1.0.0,<2.0.0 || >2.0.0 and b (1.0.0) depends on a (2.0.0), b (!=2.0.0) requires a (2.0.0). And because a (2.0.0) depends on b (2.0.0), b is forbidden. Because b (2.0.0) depends on a (1.0.0) which depends on b (1.0.0), b is forbidden. Thus, b is forbidden. So, because myapp depends on b (*), version solving failed.""" check_solver_result(root, provider, error=error, tries=2)
def test_backjump_to_nearer_unsatisfied_package( root: ProjectPackage, provider: Provider, repo: Repository ): # This ensures it doesn't exhaustively search all versions of b when it's # a-2.0.0 whose dependency on c-2.0.0-nonexistent led to the problem. We # make sure b has more versions than a so that the solver tries a first # since it sorts sibling dependencies by number of versions. root.add_dependency(Factory.create_dependency("a", "*")) root.add_dependency(Factory.create_dependency("b", "*")) add_to_repo(repo, "a", "1.0.0", deps={"c": "1.0.0"}) add_to_repo(repo, "a", "2.0.0", deps={"c": "2.0.0-1"}) add_to_repo(repo, "b", "1.0.0") add_to_repo(repo, "b", "2.0.0") add_to_repo(repo, "b", "3.0.0") add_to_repo(repo, "c", "1.0.0") check_solver_result( root, provider, {"a": "1.0.0", "b": "3.0.0", "c": "1.0.0"}, tries=2 )
def test_no_version_that_matches_combined_constraints(root: ProjectPackage, provider: Provider, repo: Repository): root.add_dependency(Factory.create_dependency("foo", "1.0.0")) root.add_dependency(Factory.create_dependency("bar", "1.0.0")) add_to_repo(repo, "foo", "1.0.0", deps={"shared": ">=2.0.0 <3.0.0"}) add_to_repo(repo, "bar", "1.0.0", deps={"shared": ">=2.9.0 <4.0.0"}) add_to_repo(repo, "shared", "2.5.0") add_to_repo(repo, "shared", "3.5.0") error = """\ Because foo (1.0.0) depends on shared (>=2.0.0 <3.0.0) and no versions of shared match >=2.9.0,<3.0.0,\ foo (1.0.0) requires shared (>=2.0.0,<2.9.0). And because bar (1.0.0) depends on shared (>=2.9.0 <4.0.0),\ bar (1.0.0) is incompatible with foo (1.0.0). So, because myapp depends on both foo (1.0.0) and bar (1.0.0), version solving failed.\ """ check_solver_result(root, provider, error=error)
def generate_system_pyproject(self) -> None: preserved = {} if self.system_pyproject.exists(): content = PyProjectTOML(self.system_pyproject).poetry_config for key in {"group", "source"}: if key in content: preserved[key] = content[key] package = ProjectPackage(name="poetry-instance", version=__version__) package.add_dependency( Dependency(name="poetry", constraint=f"{__version__}")) package.python_versions = ".".join( str(v) for v in self.env.version_info[:3]) content = Factory.create_pyproject_from_package(package=package) for key in preserved: content[key] = preserved[key] self.system_pyproject.write_text(content.as_string(), encoding="utf-8")