Repository: py-pdf/pypdf
Pull request: MAINT: Add tests to source distributions
closes #2864

Problem statement:
Please include tests in pypi distfile
## Explanation

I'm packaging pypdf for pkgsrc. We have standardized on using the pypi source tar.gz files.
When updating packages, I like to run the test suite to make sure the software works fine.
The tests are currently not included, please include them in the pypi source file to allow this.

Thank you!

Hints from issue discussion:
Thanks for the report - I honestly have not been aware that we are not even distributing the tests itself in our sdists. Nevertheless, I am not sure what would be the best approach here either for the PDF files itself - these currently originate from the repository itself (11.3 MB), the *sample-files* repository (14.5 MB) and downloaded from the internet (290 MB).
Hm, perhaps include the `tests/` directory (including the scripts) in the tarball, and provide the sample-files and downloads as one or two separate distfiles?
PyPI does not allow distributing (pure) data files. In my opinion, bundling the *resources* and *tests* directory inside the sdist should be doable. For the *sample-files* repository, I am not sure, but there are not much changes and I consider it easy enough to download the archive from the git commit from GitHub. The remaining 290 MB will most likely never be distributed by us, as they can be downloaded with a single command or skipped entirely - depending on how your build machines are handling network requests.
The reason why I excluded tests is to make pypdf small so that downloads in CI are fast.

I don't want to include tests in wheels. For source distribution, I don't have a strong opinion.


It is rather uncommon to bundle tests in the binary wheels, but for the sdists its rather usual. The request is about the "source tar.gz files", thus the sdists which should match your opinion.
@0-wiz-0
For ecological reason (preventing multiple copy of the data) I would have prefered that you get the source directly from github : just the /tests will not be sufficient to run the tests and the amount of data is quite important as @stefan6419846 said.

If you maintain your request, can you please propose a PR that will add tests to .tar.gz but keep .whl unchanged
We explicitly ignore the test directory at the moment: https://github.com/py-pdf/pypdf/blob/dcd15aaf50faa16a0b361d834e10ebe7c56dfc97/pyproject.toml#L65 Removing it from there might already fix the issue (we do not have to care about the JSON file in my opinion, as `make_release.py` is never distributed and thus the corresponding tests are always skipped). To bundle the *resources* directory, we would have to remove it from the same list, but adapt `MANIFEST.in` as well to include these files.
> Removing it from there might already fix the issue (we do not have to care about the JSON file in my opinion, as `make_release.py` is never distributed and thus the corresponding tests are always skipped). To bundle the _resources_ directory, we would have to remove it from the same list, but adapt `MANIFEST.in` as well to include these files.

Maybe I'm wrong but if we juste remove it, wouldn't the tests folder be added to the whl ?
Line 65 is in the 'sdist' section, so I'd assume it only affects the source distribution.

I can not see any sectIon about wheel.
From what I've read flit seems to output  both tar.gz and whl by default at the same time.

Commit message: add  include

Patch to review:
diff --git a/pyproject.toml b/pyproject.toml
index 87175fd40..336a4106b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -61,7 +61,8 @@ tests_dir = "tests/"
 package = "./pypdf"
 
 [tool.flit.sdist]
-exclude = [".github/*", "docs/*", "resources/*", "sample-files/*", "sample-files/.github/*", "sample-files/.gitignore", "sample-files/.pre-commit-config.yaml",  "requirements/*", "tests/*", ".flake8", ".gitignore", ".gitmodules", ".pylintrc", "tox.ini", "make_release.py", "mutmut-test.sh", ".pre-commit-config.yaml", ".gitblame-ignore-revs", "Makefile", "mutmut_config.py"]
+exclude = [".github/*", "docs/*", "sample-files/.github/*", "sample-files/.gitignore", "sample-files/.pre-commit-config.yaml",  "requirements/*", ".flake8", ".gitignore", ".gitmodules", ".pylintrc", "tox.ini", "make_release.py", "mutmut-test.sh", ".pre-commit-config.yaml", ".gitblame-ignore-revs", "Makefile", "mutmut_config.py"]
+include = ["resources/", "tests/", "sample-files/"]
 
 [tool.pytest.ini_options]
 addopts = "--disable-socket"


Code review comments:
diff_hunk: @@ -62,6 +62,7 @@ package = "./pypdf"
 
 [tool.flit.sdist]
 exclude = [".github/*", "docs/*", "sample-files/.github/*", "sample-files/.gitignore", "sample-files/.pre-commit-config.yaml",  "requirements/*", ".flake8", ".gitignore", ".gitmodules", ".pylintrc", "tox.ini", "make_release.py", "mutmut-test.sh", ".pre-commit-config.yaml", ".gitblame-ignore-revs", "Makefile", "mutmut_config.py"]
+include = ["resources/", "tests/", "sample-files/"]
path: pyproject.toml
text: @user1:
I recommend to not include the sample files here - they can be downloaded regularly as an archive and do not change very often. Otherwise, this adds additional bloat and would require adapting the PyPI workflow.

```suggestion
include = ["resources/", "tests/"]
```