-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setuptools 69 includes type information by default #160
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ tomli | |
|
||
# build and upload | ||
build | ||
setuptools | ||
setuptools >= 69.0.0 | ||
twine | ||
wheel | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,30 +216,24 @@ def is_namespace_package(path: Path) -> bool: | |
return not (path / "__init__.pyi").exists() | ||
|
||
|
||
def find_stub_files(top: str) -> list[str]: | ||
"""Find all stub files for a given package, relative to package root. | ||
def validate_only_stub_files(top: str) -> None: | ||
"""Check all stub files for a given package, relative to package root. | ||
|
||
Raise if we find any unknown file extensions during collection. | ||
Raise if we find any unknown file extensions or invalid names. | ||
""" | ||
result: list[str] = [] | ||
for root, _, files in os.walk(top): | ||
for _, _, files in os.walk(top): | ||
for file in files: | ||
if file.endswith(".pyi"): | ||
name, _ = os.path.splitext(file) | ||
assert ( | ||
name.isidentifier() | ||
), "All file names must be valid Python modules" | ||
result.append(os.path.relpath(os.path.join(root, file), top)) | ||
elif file == "py.typed": | ||
result.append(os.path.relpath(os.path.join(root, file), top)) | ||
if not (name.isidentifier()): | ||
raise ValueError("All file names must be valid Python modules") | ||
elif not file.endswith((".md", ".rst")): | ||
# Allow having README docs, as some stubs have these (e.g. click). | ||
if ( | ||
subprocess.run(["git", "check-ignore", file], cwd=top).returncode | ||
!= 0 | ||
): | ||
raise ValueError(f"Only stub files are allowed, not {file!r}") | ||
return sorted(result) | ||
|
||
|
||
def copy_stubs(base_dir: Path, dst: Path) -> None: | ||
|
@@ -307,18 +301,13 @@ def collect_package_data(base_path: Path) -> PackageData: | |
continue | ||
elif entry.is_file() and entry.suffix == ".pyi": | ||
pkg_name = entry.stem | ||
# Module -> package transformation is done while copying. | ||
stub_files = ["__init__.pyi"] | ||
elif entry.is_dir(): | ||
pkg_name = entry.name | ||
stub_files = find_stub_files(str(entry)) | ||
validate_only_stub_files(str(entry)) | ||
else: | ||
raise ValueError(f"Only stub files are allowed, not {entry.name!r}") | ||
package_data[pkg_name + SUFFIX] = [*stub_files, META] | ||
pkg_data = PackageData(base_path, package_data) | ||
for package in pkg_data.top_level_non_namespace_packages: | ||
pkg_data.add_file(package, "py.typed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, this is the only call of |
||
return pkg_data | ||
package_data[pkg_name + SUFFIX] = [META] | ||
return PackageData(base_path, package_data) | ||
|
||
|
||
def is_ignored_distribution_file(entry: Path) -> bool: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,38 +117,15 @@ def test_collect_package_data() -> None: | |
stubs = Path("data") / "test_typeshed" / "stubs" | ||
pkg_data = collect_package_data(stubs / "singlefilepkg") | ||
assert pkg_data.top_level_packages == ["singlefilepkg-stubs"] | ||
assert pkg_data.package_data == ( | ||
{"singlefilepkg-stubs": ["__init__.pyi", "METADATA.toml", "py.typed"]} | ||
) | ||
assert pkg_data.package_data == ({"singlefilepkg-stubs": ["METADATA.toml"]}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests were checking for strings in |
||
|
||
pkg_data = collect_package_data(stubs / "multifilepkg") | ||
assert pkg_data.top_level_packages == ["multifilepkg-stubs"] | ||
assert pkg_data.package_data == ( | ||
{ | ||
"multifilepkg-stubs": [ | ||
"__init__.pyi", | ||
"a.pyi", | ||
"b.pyi", | ||
os.path.join("c", "__init__.pyi"), | ||
os.path.join("c", "d.pyi"), | ||
os.path.join("c", "e.pyi"), | ||
"METADATA.toml", | ||
"py.typed", | ||
] | ||
} | ||
) | ||
assert pkg_data.package_data == ({"multifilepkg-stubs": ["METADATA.toml"]}) | ||
|
||
pkg_data = collect_package_data(stubs / "nspkg") | ||
assert pkg_data.top_level_packages == ["nspkg-stubs"] | ||
assert pkg_data.package_data == ( | ||
{ | ||
"nspkg-stubs": [ | ||
os.path.join("innerpkg", "__init__.pyi"), | ||
"METADATA.toml", | ||
os.path.join("innerpkg", "py.typed"), | ||
] | ||
} | ||
) | ||
assert pkg_data.package_data == ({"nspkg-stubs": ["METADATA.toml"]}) | ||
|
||
|
||
def test_collect_package_data_bogusfile() -> None: | ||
|
@@ -162,27 +139,14 @@ def test_collect_package_data_bogusfile() -> None: | |
with open(os.path.join(stubs, "singlefilepkg", ".METADATA.toml.swp"), "w"): | ||
pass | ||
pkg_data = collect_package_data(stubs / "singlefilepkg") | ||
assert set(pkg_data.package_data["singlefilepkg-stubs"]) == { | ||
"__init__.pyi", | ||
"py.typed", | ||
"METADATA.toml", | ||
} | ||
assert set(pkg_data.package_data["singlefilepkg-stubs"]) == {"METADATA.toml"} | ||
|
||
with open( | ||
os.path.join(stubs, "multifilepkg", "multifilepkg", ".METADATA.toml.swp"), "w" | ||
): | ||
pass | ||
pkg_data = collect_package_data(stubs / "multifilepkg") | ||
assert set(pkg_data.package_data["multifilepkg-stubs"]) == { | ||
"__init__.pyi", | ||
"a.pyi", | ||
"b.pyi", | ||
"c/__init__.pyi", | ||
"c/d.pyi", | ||
"c/e.pyi", | ||
"py.typed", | ||
"METADATA.toml", | ||
} | ||
assert set(pkg_data.package_data["multifilepkg-stubs"]) == {"METADATA.toml"} | ||
|
||
|
||
def test_uploaded_packages() -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing this, I'd expect this function to crash, as the build directory will have
py.typed
files and the next elif branch checks for unknown files.