def test_get_requires_for_build_missing_optional_hooks(package_test_optional_hooks, distribution): builder = build.ProjectBuilder(package_test_optional_hooks) assert builder.get_requires_for_build(distribution) == set()
def test_python_executable(package_test_flit, value): builder = build.ProjectBuilder(package_test_flit) builder.python_executable = value assert builder.python_executable == value assert builder._hook.python_executable == value
def test_get_requires_for_build_missing_backend(packages_path, distribution): bad_backend_path = os.path.join(packages_path, 'test-bad-backend') builder = build.ProjectBuilder(bad_backend_path) with pytest.raises(build.BuildBackendException): builder.get_requires_for_build(distribution)
def test_missing_requires(mocker, test_no_requires_path): mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True) with pytest.raises(build.BuildException): build.ProjectBuilder(test_no_requires_path)
def test_build_system_typo(mocker, test_typo): mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True) with pytest.warns(build.TypoWarning): build.ProjectBuilder(test_typo)
def test_build_missing_backend(packages_path, distribution, tmpdir): bad_backend_path = os.path.join(packages_path, 'test-bad-backend') builder = build.ProjectBuilder(bad_backend_path) with pytest.raises(build.BuildException): builder.build(distribution, str(tmpdir))
def test_default_backend(mocker, legacy_path): mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True) builder = build.ProjectBuilder(legacy_path) assert builder._build_system == DEFAULT_BACKEND
def test_get_dependencies_missing_backend(packages_path, distribution): bad_backend_path = os.path.join(packages_path, 'test-bad-backend') builder = build.ProjectBuilder(bad_backend_path) with pytest.raises(build.BuildException): builder.get_dependencies(distribution)
def test_get_dependencies_missing_optional_hooks(test_optional_hooks_path, distribution): builder = build.ProjectBuilder(test_optional_hooks_path) assert builder.get_dependencies(distribution) == set()
def test_python_executable(test_flit_path, value): builder = build.ProjectBuilder(test_flit_path) builder.python_executable = value assert builder.python_executable == value assert builder._hook.python_executable == value
def build_package( source_dir: Optional[Path], output_dir: Optional[Path], release: bool = typer.Option( False, help="Create a Github release after packaging"), ): """Package a wordsiv Source module as wheel & sdist See https://github.com/tallpauley/wordsiv-source-packages for examples of what SOURCE_DIR should look like. """ temp_dir = Path.cwd() / ".wordsiv-temp" shutil.rmtree(temp_dir, ignore_errors=True) shutil.copytree(source_dir, temp_dir) with open(temp_dir / "manifest.in", "w+") as f: f.write(MANIFEST_TEMPLATE) with open(temp_dir / "setup.py", "w+") as f: f.write(SETUP_PY_TEMPLATE) pb = build.ProjectBuilder(temp_dir) wheel_file = pb.build("wheel", output_dir) sdist_file = pb.build("sdist", output_dir) if release: with open(source_dir / "meta.json", "r") as f: meta = json.load(f) meta["compatible_models"] = ", ".join( f"`{m}`" for m in meta["compatible_models"]) meta["source_class"] = f"`{meta['source_class']}`" release_description_f = temp_dir / "release.md" with open(release_description_f, "w+") as f: f.write(GITHUB_RELEASE_TEMPLATE.format(**meta)) name_version = f"{meta['name']}-{meta['version']}" # create release subprocess.run([ "gh", "release", "create", "--repo", about.__packages_repo__, name_version, "--title", name_version, "--notes-file", str(release_description_f), ]) subprocess.run([ "gh", "release", "upload", "--repo", about.__packages_repo__, name_version, wheel_file, sdist_file, ]) shutil.rmtree(temp_dir, ignore_errors=True)
def test_missing_backend(mocker, test_no_backend_path): mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True) builder = build.ProjectBuilder(test_no_backend_path) assert builder._build_system == {'requires': [], 'build-backend': DEFAULT_BACKEND['build-backend']}
def test_metadata_invalid_wheel(tmp_dir, test_bad_wheel_path): builder = build.ProjectBuilder(test_bad_wheel_path) with pytest.raises(ValueError, match='Invalid wheel'): builder.metadata_path(tmp_dir)
def test_get_requires_for_build_missing_optional_hooks( test_optional_hooks_path, distribution): builder = build.ProjectBuilder(test_optional_hooks_path) assert builder.get_requires_for_build(distribution) == set()