def test_save_action_additional_extensions(default_file): # Given the file exists existing_config(default_file) # When the new config is saved with new extensions opts = dict(author="author", email="email", license="MPL-2.0", my_extension1_opt=5) extensions = [ make_extension("MyExtension1"), make_extension("MyExtension2"), make_extension("MyExtension3", persist=False), ] config.save({}, { **opts, "save_config": default_file, "extensions": extensions }) # The old ones are kept and the new ones are added, # unless they specify persist=False parsed = info.read_setupcfg(default_file).to_dict()["pyscaffold"] print(default_file.read_text()) expected = {"namespace", "tox", "cirrus", "my_extension1", "my_extension2"} assert templates.parse_extensions(parsed["extensions"]) == expected assert parsed["namespace"] == "my_namespace.my_sub_namespace" # Extension related opts are also saved assert int(parsed["my_extension1_opt"]) == 5
def test_handover_setup_requires(tmpfolder, existing_config): # Given an existing setup.cfg with setup_requires # when we update it opts = {"project_path": tmpfolder, "pretend": False} update.handover_setup_requires({}, opts) cfg = info.read_setupcfg(existing_config) # then setup_requirements should not be included assert "setup_requires" not in str(cfg["options"])
def _install_bdist(self): setupcfg = info.read_setupcfg(self.pkg_path) requirements = deps.split( setupcfg["options"]["install_requires"].value) self.run("pip", "install", *requirements) with chdir("/"): # Because of the way bdist works, the tar.gz will contain # the whole path to the current venv, starting from the # / directory ... untar(self.dist_file, "--force-local")
def test_add_dependencies(tmpfolder): # Given an existing setup.cfg Path(tmpfolder, "setup.cfg").write_text("[options]\n") # when we update it opts = {"project_path": tmpfolder, "pretend": False} update.add_dependencies({}, opts) # then we should see the dependencies in install_requires cfg = info.read_setupcfg(Path(tmpfolder, "setup.cfg")) assert "install_requires" in str(cfg["options"]) assert "importlib-metadata" in str(cfg["options"]["install_requires"])
def test_update_setup_cfg(tmpfolder): # Given an existing setup.cfg Path(tmpfolder, "setup.cfg").write_text("[metadata]\n\n[pyscaffold]\n") # when we update it opts = {"project_path": tmpfolder, "pretend": False} update.update_setup_cfg({}, opts) cfg = info.read_setupcfg(Path(tmpfolder, "setup.cfg")) # then it should show the most update pyscaffold version assert cfg["pyscaffold"]["version"].value == __version__ # and some configuration keys should be present assert "options" in cfg
def test_handover_setup_requires_no_pyproject(tmpfolder, existing_config): # Given an existing setup.cfg with outdated setup_requires and pyscaffold version, # when we update it without no_pyproject opts = { "project_path": tmpfolder, "pretend": False, "isolated_build": False } update.handover_setup_requires({}, opts) cfg = info.read_setupcfg(existing_config) # then setup_requirements is left alone assert cfg["options"]["setup_requires"]
def test_cli_with_save_config(default_file, tmpfolder): # Given a global config file does not exist assert not default_file.exists() # when the CLI is invoked with --save-config cli.main("proj -l MPL-2.0 --namespace ns --cirrus --save-config".split()) # then the file will be created accordingly assert default_file.exists() parsed = info.read_setupcfg(default_file).to_dict() assert parsed["metadata"]["license"] == "MPL-2.0" assert parsed["pyscaffold"]["namespace"] == "ns" assert "cirrus" in parsed["pyscaffold"]["extensions"] # and since the config extension has persist = False, it will not be stored assert "config" not in parsed["pyscaffold"]["extensions"]
def test_migrate_setup_requires(tmpfolder, existing_config): # When a project with setup.cfg :: setup_requires is updated opts = {"project_path": tmpfolder, "pretend": False} _, opts = update.handover_setup_requires({}, opts) update.update_pyproject_toml({}, opts) # then the minimal dependencies are added pyproject = info.read_pyproject(tmpfolder) deps = " ".join(pyproject["build-system"]["requires"]) assert "setuptools_scm" in deps # old dependencies are migrated from setup.cfg assert "somedep>=3.8" in deps setupcfg = info.read_setupcfg(existing_config) assert "setup_requires" not in setupcfg["options"] # but pyscaffold is not included. assert "pyscaffold" not in deps
def test_update_setup_cfg(tmpfolder): # Given an existing setup.cfg proj = Path(tmpfolder, "proj") proj.mkdir(parents=True, exist_ok=True) (proj / "setup.cfg").write_text("[metadata]\n\n[pyscaffold]\n") # when we update it extensions = [ Object(name="cirrus", persist=True), Object(name="no", persist=False) ] opts = {"project_path": proj, "extensions": extensions} _, opts = actions.get_default_options({}, opts) update.update_setup_cfg({}, opts) cfg = info.read_setupcfg(proj / "setup.cfg") # then it should show the most update pyscaffold version assert cfg["pyscaffold"]["version"].value == __version__ assert "cirrus" in cfg["pyscaffold"]["extensions"].value assert "no" not in cfg["pyscaffold"]["extensions"].value # and some configuration keys should be present assert "options" in cfg
def test_replace_find_with_find_namespace(tmpfolder): # Given an old setup.cfg based on packages find: config = """\ [options] zip_safe = False packages = find: [options.packages.find] where = src exclude = tests """ Path(tmpfolder, "setup.cfg").write_text(dedent(config)) # when we update it opts = {"project_path": tmpfolder, "pretend": False} update.replace_find_with_find_namespace({}, opts) # then we should see find_namespace instead cfg = info.read_setupcfg(Path(tmpfolder, "setup.cfg")) assert cfg["options"]["packages"].value == "find_namespace:" assert "options.packages.find" in cfg assert cfg["options.packages.find"]["where"].value == "src" assert cfg["options.packages.find"]["exclude"].value.strip() == "tests"