-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31f1e1f
commit ab07a03
Showing
19 changed files
with
77 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Exclude entire directories | ||
prune .github/ | ||
prune dev_scripts/ | ||
prune docs/ | ||
prune examples/ | ||
prune tests/ | ||
|
||
# Exclude individual files | ||
exclude .* \ | ||
ADMIN.md CONTRIBUTING.md SECURITY.md \ | ||
CITATION.cff pdm.lock tasks.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,78 @@ | ||
"""Check the content of source code and source distribution. | ||
Binary distribution (wheel) is checked in test workflow. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
import tarfile | ||
from glob import glob | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from monty.tempfile import ScratchDir | ||
|
||
if TYPE_CHECKING: | ||
from pymatgen.util.typing import PathLike | ||
|
||
SRC_DIR = Path(__file__).parent.parent | ||
|
||
|
||
class TestCheckDistribution: | ||
def test_source_code(self): | ||
"""Directly check the source code in the working directory.""" | ||
src_txt_path = SRC_DIR / "src/pymatgen.egg-info/SOURCES.txt" | ||
|
||
import pytest | ||
_check_src_txt_is_complete(SRC_DIR, src_txt_path) | ||
|
||
SRC_TXT_PATH = "src/pymatgen.egg-info/SOURCES.txt" | ||
def test_source_distribution(self): | ||
"""Build the source distribution and verify its contents.""" | ||
|
||
with ScratchDir("."): | ||
# Build the source distribution | ||
subprocess.run(["python", "-m", "build", "--sdist", SRC_DIR, "--outdir", ".", "-C--quiet"], check=True) | ||
|
||
@pytest.mark.skipif( | ||
not os.path.isfile(SRC_TXT_PATH), | ||
reason=f"{SRC_TXT_PATH=} not found. Run `pip install .` to create", | ||
) | ||
def test_egg_sources_txt_is_complete(): | ||
"""Check that all source and data files in pymatgen/ are listed in pymatgen.egg-info/SOURCES.txt.""" | ||
# 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 | ||
|
||
with open(SRC_TXT_PATH, encoding="utf-8") as file: | ||
# Verify source distribution contents | ||
src_txt_path = f"{sdist_dir}/src/pymatgen.egg-info/SOURCES.txt" | ||
_check_src_txt_is_complete(src_dir=sdist_dir, src_txt_path=src_txt_path) | ||
|
||
|
||
def _check_src_txt_is_complete(src_dir: PathLike, src_txt_path: PathLike) -> None: | ||
"""Check that all source code and data files are listed in given SOURCES.txt. | ||
Args: | ||
src_dir (PathLike): Path to the source code directory. | ||
src_txt_path (PathLike): Path to the "SOURCES.txt" file. | ||
""" | ||
src_dir = Path(src_dir) | ||
src_txt_path = Path(src_txt_path) | ||
|
||
assert src_dir.is_dir(), f"{src_dir} is not a directory" | ||
assert src_txt_path.is_file(), f"{src_txt_path} doesn't exist" | ||
|
||
with open(src_txt_path, encoding="utf-8") as file: | ||
sources = file.read() | ||
|
||
# check that all files listed in SOURCES.txt exist | ||
# Check that all files listed in "SOURCES.txt" exist | ||
for src_file in sources.splitlines(): | ||
assert os.path.isfile(src_file), f"{src_file!r} does not exist!" | ||
|
||
# check that all files in pymatgen/ are listed in SOURCES.txt | ||
for ext in ("py", "json*", "yaml", "csv"): | ||
for filepath in glob(f"pymatgen/**/*.{ext}", recursive=True): | ||
unix_path = filepath.replace("\\", "/") | ||
if unix_path.endswith("dao.py"): | ||
continue | ||
assert os.path.isfile(src_dir / src_file), f"{src_file!r} does not exist!" | ||
|
||
# Check that all files in src/pymatgen/ are listed in SOURCES.txt | ||
for ext in ("py", "json", "json.*", "yaml", "csv"): | ||
for filepath in glob(f"{src_dir}/src/pymatgen/**/*.{ext}", recursive=True): | ||
unix_path = os.path.relpath(filepath.replace("\\", "/"), start=src_dir) | ||
|
||
if unix_path not in sources: | ||
raise ValueError( | ||
f"{unix_path} not found in {SRC_TXT_PATH}. check setup.py package_data for " | ||
"outdated inclusion rules." | ||
) | ||
raise ValueError(f"{unix_path} not found in {src_txt_path}, check package data config") |