Skip to content

Commit

Permalink
avoid checking SOURCES.txt in sdist
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 25, 2024
1 parent 9909527 commit 4bdb549
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions tests/test_pkg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Check the content of source code and source distribution.
"""Check the content of source code and test build source distribution.
Binary distribution (wheel) is checked in test workflow.
"""

from __future__ import annotations

import subprocess
import tarfile
from glob import glob
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -19,34 +18,19 @@
PROJECT_ROOT = Path(__file__).parent.parent


class TestCheckDistribution:
def test_source_code(self):
"""Directly check the source code in the working directory."""
src_txt_path = PROJECT_ROOT / "src/pymatgen.egg-info/SOURCES.txt"
def test_source_code():
"""Check the source code in the working directory."""
src_txt_path = PROJECT_ROOT / "src/pymatgen.egg-info/SOURCES.txt"

_check_src_txt_is_complete(PROJECT_ROOT, src_txt_path)
_check_src_txt_is_complete(PROJECT_ROOT, src_txt_path)

def test_source_distribution(self):
"""Build the source distribution and verify its contents."""

with ScratchDir("."):
# Build the source distribution
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "build"], check=True)
subprocess.run(["python", "-m", "build", "--sdist", PROJECT_ROOT, "--outdir", ".", "-C--quiet"], check=True)

# Decompress sdist
sdist_file = next(Path(".").glob("*.tar.gz"))
sdist_dir = sdist_file.name.removesuffix(".tar.gz")
with tarfile.open(sdist_file, "r:gz") as tar:
# TODO: remove attr check after only 3.12+
if hasattr(tarfile, "data_filter"):
tar.extractall("", filter="data")
else:
tar.extractall("") # noqa: S202

# Verify source distribution contents
src_txt_path = f"{sdist_dir}/src/pymatgen.egg-info/SOURCES.txt"
_check_src_txt_is_complete(project_root=sdist_dir, src_txt_path=src_txt_path)
def test_build_source_distribution():
"""Test build the source distribution (sdist)."""
with ScratchDir("."):
# Build the source distribution
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "build"], check=True)
subprocess.run(["python", "-m", "build", "--sdist", PROJECT_ROOT, "--outdir", ".", "-C--quiet"], check=True)


def _check_src_txt_is_complete(project_root: PathLike, src_txt_path: PathLike) -> None:
Expand Down

0 comments on commit 4bdb549

Please sign in to comment.