def test_add_editable_package(project, working_set, is_dev): # Ensure that correct python version is used. project.environment.python_requires = PySpecSet(">=3.6") actions.do_add(project, is_dev, packages=["demo"]) actions.do_add( project, is_dev, editables=["git+https://github.com/test-root/demo.git#egg=demo"], ) group = ( project.tool_settings["dev-dependencies"]["dev"] if is_dev else project.meta["dependencies"] ) assert "demo" in group[0] assert "-e git+https://github.com/test-root/demo.git#egg=demo" in group[1] locked_candidates = project.locked_repository.all_candidates assert ( locked_candidates["demo"].prepare(project.environment).revision == "1234567890abcdef" ) assert locked_candidates["idna"].version == "2.7" assert "idna" in working_set actions.do_sync(project, no_editable=True) assert not working_set["demo"].link_file
def test_update_all_packages(project, repository, capsys, strategy): actions.do_add(project, packages=["requests", "pytz"]) repository.add_candidate("pytz", "2019.6") repository.add_candidate("chardet", "3.0.5") repository.add_candidate("requests", "2.20.0") repository.add_dependencies( "requests", "2.20.0", [ "certifi>=2017.4.17", "chardet<3.1.0,>=3.0.2", "idna<2.8,>=2.5", "urllib3<1.24,>=1.21.1", ], ) actions.do_update(project, strategy=strategy) locked_candidates = project.locked_repository.all_candidates assert locked_candidates["requests"].version == "2.20.0" assert locked_candidates["chardet"].version == ("3.0.5" if strategy == "all" else "3.0.4") assert locked_candidates["pytz"].version == "2019.6" out, _ = capsys.readouterr() update_num = 3 if strategy == "all" else 2 assert f"{update_num} to update" in out, out actions.do_sync(project) out, _ = capsys.readouterr() assert "All packages are synced to date" in out
def test_update_all_packages(project, repository, capsys): actions.do_add(project, packages=["requests", "pytz"]) repository.add_candidate("pytz", "2019.6") repository.add_candidate("chardet", "3.0.5") repository.add_candidate("requests", "2.20.0") repository.add_dependencies( "requests", "2.20.0", [ "certifi>=2017.4.17", "chardet<3.1.0,>=3.0.2", "idna<2.8,>=2.5", "urllib3<1.24,>=1.21.1", ], ) actions.do_update(project) locked_candidates = project.get_locked_candidates() assert locked_candidates["requests"].version == "2.20.0" assert locked_candidates["chardet"].version == "3.0.5" assert locked_candidates["pytz"].version == "2019.6" out, _ = capsys.readouterr() assert "3 to update" in out actions.do_sync(project) out, _ = capsys.readouterr() assert "All packages are synced to date" in out
def handle(self, project: Project, options: argparse.Namespace) -> None: if not project.meta and click._compat.isatty(sys.stdout): actions.ask_for_import(project) strategy = actions.check_lockfile(project, False) if strategy: if options.check: project.core.ui.echo( "Please run `pdm lock` to update the lock file", err=True) sys.exit(1) if options.lock: project.core.ui.echo("Updating the lock file...", fg="green", err=True) actions.do_lock(project, strategy=strategy, dry_run=options.dry_run) actions.do_sync( project, groups=options.groups, dev=options.dev, default=options.default, no_editable=options.no_editable, no_self=options.no_self, dry_run=options.dry_run, )
def handle(self, project: Project, options: argparse.Namespace) -> None: if not project.meta and click._compat.isatty(sys.stdout): actions.ask_for_import(project) if options.lock: if not project.lockfile_file.exists(): project.core.ui.echo( "Lock file does not exist, trying to generate one...") actions.do_lock(project, strategy="all") elif not project.is_lockfile_compatible(): project.core.ui.echo( "Lock file version is not compatible with PDM, regenerate..." ) actions.do_lock(project, strategy="all") elif not project.is_lockfile_hash_match(): project.core.ui.echo( "Lock file hash doesn't match pyproject.toml, regenerating..." ) actions.do_lock(project, strategy="reuse") actions.do_sync( project, sections=options.sections, dev=options.dev, default=options.default, no_editable=options.no_editable, no_self=options.no_self, )
def test_sync_packages_with_sections(project, working_set): project.add_dependencies({"requests": parse_requirement("requests")}) project.add_dependencies({"pytz": parse_requirement("pytz")}, "date") actions.do_lock(project) actions.do_sync(project, sections=["date"]) assert "pytz" in working_set assert "requests" in working_set assert "idna" in working_set
def handle(self, project: Project, options: argparse.Namespace) -> None: actions.do_sync( project, sections=options.sections, dev=compatible_dev_flag(project, options.dev), default=options.default, dry_run=options.dry_run, clean=options.clean, )
def test_sync_production_packages(project, working_set, is_dev): project.add_dependencies({"requests": parse_requirement("requests")}) project.add_dependencies({"pytz": parse_requirement("pytz")}, "dev", dev=True) actions.do_lock(project) actions.do_sync(project, dev=is_dev) assert "requests" in working_set assert ("pytz" in working_set) == is_dev
def test_sync_packages_with_all_dev(project, working_set): project.add_dependencies({"requests": parse_requirement("requests")}) project.add_dependencies({"pytz": parse_requirement("pytz")}, "date", True) project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl", True) actions.do_lock(project) actions.do_sync(project, dev=True, default=False) assert "requests" not in working_set assert "idna" not in working_set assert "pytz" in working_set assert "pyopenssl" in working_set
def test_sync_clean_packages(project, repository, working_set): for candidate in [ make_distribution("foo", "0.1.0"), make_distribution("chardet", "3.0.1"), make_distribution("idna", "2.7"), ]: working_set.add_distribution(candidate) actions.do_add(project, packages=["requests"], sync=False) actions.do_sync(project, clean=True) assert "foo" not in working_set
def install(project, sections, dev, default, lock): if lock: if not project.lockfile_file.exists(): context.io.echo( "Lock file does not exist, trying to generate one...") actions.do_lock(project, strategy="all") elif not project.is_lockfile_hash_match(): context.io.echo( "Lock file hash doesn't match pyproject.toml, regenerating...") actions.do_lock(project, strategy="reuse") actions.do_sync(project, sections, dev, default, False, False)
def handle(self, project: Project, options: argparse.Namespace) -> None: actions.do_sync( project, sections=options.sections, dev=options.dev, default=options.default, dry_run=options.dry_run, clean=options.clean, no_editable=options.no_editable, no_self=options.no_self, )
def test_sync_packages_with_group_all(project, working_set): project.add_dependencies({"requests": parse_requirement("requests")}) project.add_dependencies({"pytz": parse_requirement("pytz")}, "date") project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl") actions.do_lock(project) actions.do_sync(project, groups=[":all"]) assert "pytz" in working_set assert "requests" in working_set assert "idna" in working_set assert "pyopenssl" in working_set
def test_sync_dry_run(project, working_set): for candidate in [ make_distribution("foo", "0.1.0"), make_distribution("chardet", "3.0.1"), make_distribution("idna", "2.7"), ]: working_set.add_distribution(candidate) actions.do_add(project, packages=["requests"], sync=False) actions.do_sync(project, clean=True, dry_run=True) assert "foo" in working_set assert "requests" not in working_set assert working_set["chardet"].version == "3.0.1"
def handle(self, project: Project, options: argparse.Namespace) -> None: actions.do_sync( project, groups=options.groups, dev=options.dev, default=options.default, dry_run=options.dry_run, clean=options.clean, no_editable=options.no_editable, no_self=options.no_self, reinstall=options.reinstall, )
def handle(self, project: Project, options: argparse.Namespace) -> None: if not project.meta and click._compat.isatty(sys.stdout): actions.ask_for_import(project) if options.lock: if not project.lockfile_file.exists(): stream.echo( "Lock file does not exist, trying to generate one...") actions.do_lock(project, strategy="all") elif not project.is_lockfile_hash_match(): stream.echo( "Lock file hash doesn't match pyproject.toml, regenerating..." ) actions.do_lock(project, strategy="reuse") actions.do_sync(project, options.sections, options.dev, options.default, False, False)
def test_sync_with_index_change(project, index): project.meta["requires-python"] = ">=3.6" project.meta["dependencies"] = ["future-fstrings"] project.write_pyproject() index["future-fstrings"] = """ <html> <body> <h1>future-fstrings</h1> <a href="http://fixtures.test/artifacts/future_fstrings-1.2.0.tar.gz\ #sha256=6cf41cbe97c398ab5a81168ce0dbb8ad95862d3caf23c21e4430627b90844089"> future_fstrings-1.2.0.tar.gz </a> </body> </html> """.encode() actions.do_lock(project) file_hashes = project.lockfile["metadata"]["files"][ "future-fstrings 1.2.0"] assert [e["hash"] for e in file_hashes] == [ "sha256:6cf41cbe97c398ab5a81168ce0dbb8ad95862d3caf23c21e4430627b90844089" ] # Mimic the CDN inconsistences of PyPI simple index. See issues/596. del index["future-fstrings"] actions.do_sync(project, no_self=True)
def test_sync_no_lockfile(project): project.add_dependencies({"requests": parse_requirement("requests")}) with pytest.raises(PdmException): actions.do_sync(project)
def sync(project, sections, dev, default, dry_run, clean): actions.do_sync(project, sections, dev, default, dry_run, clean)
def test_sync_without_self(project, working_set): project.add_dependencies({"requests": parse_requirement("requests")}) actions.do_lock(project) actions.do_sync(project, no_self=True) assert project.meta.name not in working_set