|
5 | 5 | import pytest
|
6 | 6 | import tomli_w
|
7 | 7 | from path import Path
|
| 8 | +from jaraco.path import build as path_build |
8 | 9 |
|
9 | 10 | from setuptools.config.pyprojecttoml import (
|
10 | 11 | read_configuration,
|
|
82 | 83 |
|
83 | 84 |
|
84 | 85 | def create_example(path, pkg_root):
|
85 |
| - pyproject = path / "pyproject.toml" |
| 86 | + files = { |
| 87 | + "pyproject.toml": EXAMPLE, |
| 88 | + "README.md": "hello world", |
| 89 | + "_files": { |
| 90 | + "file.txt": "", |
| 91 | + }, |
| 92 | + } |
| 93 | + packages = { |
| 94 | + "pkg": { |
| 95 | + "__init__.py": "", |
| 96 | + "mod.py": "class CustomSdist: pass", |
| 97 | + "__version__.py": "VERSION = (3, 10)", |
| 98 | + "__main__.py": "def exec(): print('hello')", |
| 99 | + }, |
| 100 | + } |
| 101 | + |
| 102 | + assert pkg_root # Meta-test: cannot be empty string. |
86 | 103 |
|
87 |
| - files = [ |
88 |
| - f"{pkg_root}/pkg/__init__.py", |
89 |
| - "_files/file.txt", |
90 |
| - ] |
91 |
| - if pkg_root != ".": # flat-layout will raise error for multi-package dist |
92 |
| - # Ensure namespaces are discovered |
93 |
| - files.append(f"{pkg_root}/other/nested/__init__.py") |
94 |
| - |
95 |
| - for file in files: |
96 |
| - (path / file).parent.mkdir(exist_ok=True, parents=True) |
97 |
| - (path / file).touch() |
98 |
| - |
99 |
| - pyproject.write_text(EXAMPLE) |
100 |
| - (path / "README.md").write_text("hello world") |
101 |
| - (path / f"{pkg_root}/pkg/mod.py").write_text("class CustomSdist: pass") |
102 |
| - (path / f"{pkg_root}/pkg/__version__.py").write_text("VERSION = (3, 10)") |
103 |
| - (path / f"{pkg_root}/pkg/__main__.py").write_text("def exec(): print('hello')") |
| 104 | + if pkg_root == ".": |
| 105 | + files = {**files, **packages} |
| 106 | + # skip other files: flat-layout will raise error for multi-package dist |
| 107 | + else: |
| 108 | + # Use this opportunity to ensure namespaces are discovered |
| 109 | + files[pkg_root] = {**packages, "other": {"nested": {"__init__.py": ""}}} |
| 110 | + |
| 111 | + path_build(files, prefix=path) |
104 | 112 |
|
105 | 113 |
|
106 | 114 | def verify_example(config, path, pkg_root):
|
|
0 commit comments