Skip to content

Commit

Permalink
oops I branched from the wrong one
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 25, 2024
1 parent 31f1e1f commit ab07a03
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 49 deletions.
11 changes: 11 additions & 0 deletions MANIFEST.in
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
28 changes: 1 addition & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ requires = [
# https://numpy.org/devdocs/dev/depending_on_numpy.html#build-time-dependency
"numpy>=2.1.0",
"setuptools>=65.0.0",
"setuptools-scm>=8", # include all Git tracked files as package data file
]
build-backend = "setuptools.build_meta"

Expand Down Expand Up @@ -122,37 +123,10 @@ feff_plot_cross_section = "pymatgen.cli.feff_plot_cross_section:main"
feff_plot_dos = "pymatgen.cli.feff_plot_dos:main"
get_environment = "pymatgen.cli.get_environment:main"

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
where = ["src"]
include = ["pymatgen", "pymatgen.*"]

[tool.setuptools.package-data]
"pymatgen.analysis" = ["*.csv", "*.json", "*.yaml"]
"pymatgen.analysis.chemenv" = [
"coordination_environments/coordination_geometries_files/*.json",
"coordination_environments/coordination_geometries_files/*.txt",
"coordination_environments/strategy_files/ImprovedConfidenceCutoffDefaultParameters.json",
]
"pymatgen.analysis.structure_prediction" = ["*.yaml", "data/*.json"]
"pymatgen.analysis.diffraction" = ["*.json"]
"pymatgen.analysis.magnetism" = ["default_magmoms.yaml"]
"pymatgen.analysis.solar" = ["am1.5G.dat"]
"pymatgen.entries" = ["*.json.gz", "*.yaml", "data/*.json"]
"pymatgen.core" = ["*.json"]
"pymatgen" = ["py.typed"]
"pymatgen.io.vasp" = ["*.json", "*.json.bz2", "*.json.gz", "*.yaml"]
"pymatgen.io.feff" = ["*.yaml"]
"pymatgen.io.cp2k" = ["*.yaml"]
"pymatgen.io.lobster" = ["lobster_basis/*.yaml"]
"pymatgen.command_line" = ["*"]
"pymatgen.util" = ["*.json", "structures/*.json"]
"pymatgen.vis" = ["*.yaml"]
"pymatgen.io.lammps" = ["CoeffsDataType.yaml", "templates/*.template"]
"pymatgen.symmetry" = ["*.json", "*.sqlite", "*.yaml"]

[tool.pdm.dev-dependencies]
lint = ["mypy>=1.10.0", "pre-commit>=3.7.1", "ruff>=0.4.9"]
test = ["pytest-cov>=5.0.0", "pytest-split>=0.9.0", "pytest>=8.2.2"]
Expand Down
File renamed without changes.
Empty file added src/pymatgen/analysis/py.typed
Empty file.
Empty file added src/pymatgen/apps/py.typed
Empty file.
Empty file added src/pymatgen/cli/py.typed
Empty file.
Empty file.
Empty file added src/pymatgen/core/py.typed
Empty file.
Empty file.
Empty file added src/pymatgen/entries/py.typed
Empty file.
Empty file added src/pymatgen/ext/py.typed
Empty file.
Empty file added src/pymatgen/io/py.typed
Empty file.
Empty file.
Empty file added src/pymatgen/phonon/py.typed
Empty file.
Empty file added src/pymatgen/symmetry/py.typed
Empty file.
Empty file.
Empty file added src/pymatgen/util/py.typed
Empty file.
Empty file added src/pymatgen/vis/py.typed
Empty file.
87 changes: 65 additions & 22 deletions tests/test_pkg.py
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")

0 comments on commit ab07a03

Please sign in to comment.