Repository: Lightning-AI/pytorch-lightning
Pull request: MANIFEST.in and setup.py clean-up
## What does this PR do?

- Do not include tests, pl_examples, and benchmarks in the generated wheel (`python setup.py bdist_wheel`)
- Prune the MANIFEST.in definition for the source distribution (`python setup.py sdist`)
- Copy the MNIST implementation from our tests into pl_examples
- Removed `check-manifest` use as it contradicts the output of `bdist_wheel`:


```console
warning: no previously-included files found matching '.yapfignore'
warning: no previously-included files found matching '*.yaml'
warning: no previously-included files found matching 'Makefile'
warning: no previously-included files matching '*.py' found under directory 'requirements'
no previously-included directories found matching 'docs'
no previously-included directories found matching 'dockers'
no previously-included directories found matching 'legacy'
no previously-included directories found matching 'benchmarks'
no previously-included directories found matching 'notebooks'
no previously-included directories found matching 'pl_examples'
no previously-included directories found matching 'tests'
```

Credit to @flying-sheep for finding the solution in #7596
Closes #7596
Fixes #10335 

Resources:
- https://setuptools.readthedocs.io/en/latest/userguide/package_discovery.html#using-find-or-find-packages
- https://packaging.python.org/guides/using-manifest-in

Manually tested that everything is correctly included/excluded.

Part of https://github.com/PyTorchLightning/internal-dev/issues/132

## Before submitting
- [x] Was this discussed/approved via a GitHub issue? (not for typos and docs)
- [x] Did you read the [contributor guideline](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/.github/CONTRIBUTING.md), **Pull Request** section?
- [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
- [n/a] Did you make sure to update the documentation with your changes? (if necessary)
- [ ] Did you write any new necessary tests? (not for typos and docs)
- [x] Did you verify new and existing tests pass locally with your changes?
- [n/a] Did you update the [CHANGELOG](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/CHANGELOG.md)? (not for typos, docs, test updates, or internal minor changes/refactorings)

## PR review

 - [x] Is this pull request ready for review? (if not, please submit in draft mode)
 - [x] Check that all items from **Before submitting** are resolved
 - [x] Make sure the title is self-explanatory and the description concisely explains the PR
 - [x] Add labels and milestones (and optionally projects) to the PR so it can be classified

cc @borda @justusschock @awaelchli @akihironitta

Problem statement:
package "tests" in Python path?
## 🐛 Bug

PyTorch Lightning install its tests into "test" in the Python path. I would venture that this is not ideal.

### To Reproduce

Install PyTorch Lightning
```
import pathlib
import pytorch_lightning
print(list((pathlib.Path(pytorch_lightning.__file__).parent.parent / 'tests').glob('*')))
```

This is with git a checkout from today.

Hints from issue discussion:

Commit message: Remove check-manifest

Patch to review:
diff --git a/.github/workflows/ci_pkg-install.yml b/.github/workflows/ci_pkg-install.yml
index 12f3976d078e4..2cf64f39a28b7 100644
--- a/.github/workflows/ci_pkg-install.yml
+++ b/.github/workflows/ci_pkg-install.yml
@@ -26,12 +26,11 @@ jobs:
 
       - name: Prepare env
         run: |
-          pip install check-manifest "twine==3.2" setuptools wheel
+          pip install "twine==3.2" setuptools wheel
 
       - name: Create package
         run: |
-          check-manifest
-          # python setup.py check --metadata --strict
+          python setup.py check --metadata --strict
           python setup.py sdist bdist_wheel
 
       - name: Check package
diff --git a/MANIFEST.in b/MANIFEST.in
index 1b97e27a98abe..4ed189c4dd0c9 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -11,67 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-
-# Manifest syntax https://docs.python.org/2/distutils/sourcedist.html
-graft wheelhouse
-
-recursive-exclude __pycache__  *.py[cod] *.orig
-
-# Include the README and CHANGELOG
-include *.md
-
-# Include the license file
-include LICENSE
-
-exclude *.sh
-exclude *.svg
-recursive-include pytorch_lightning *.py
-
-# Include marker file for PEP 561
-include pytorch_lightning/py.typed
-
-# include examples
-recursive-include pl_examples *.py *.md *.sh *.txt *.toml
-
-# exclude tests from package
-recursive-exclude tests *
-recursive-exclude site *
-exclude tests
-
-# Exclude the documentation files
-recursive-exclude docs *
-exclude docs
-recursive-include docs/source/_static/images/logos/ *
-recursive-include docs/source/_static/images/general/ pl_overview* tf_* tutorial_* PTL101_*
-
-# Include the Requirements
+include pytorch_lightning/py.typed  # marker file for PEP 561
+include CHANGELOG.md
 recursive-include requirements *.txt
-recursive-exclude requirements *.sh *.py
 include requirements.txt
-include pyproject.toml
-
-# Exclude build configs
-exclude *.yml
-exclude *.yaml
-exclude *.toml
-exclude *.jsonnet
-exclude .yapfignore
-
-# Exclude pyright config
-exclude .pyrightconfig.json
-
-# Exclude submodules
-exclude .gitmodules
-exclude _notebooks
-
-# Exclude Makefile
-exclude Makefile
-
-prune .git
-prune .github
-prune .circleci
-prune temp*
-prune test*
-prune benchmark*
-prune dockers
-prune legacy
diff --git a/setup.py b/setup.py
index beebd807c7107..e6d623c90445e 100755
--- a/setup.py
+++ b/setup.py
@@ -76,10 +76,10 @@ def _load_py_module(fname, pkg="pytorch_lightning"):
     url=about.__homepage__,
     download_url='https://github.com/PyTorchLightning/pytorch-lightning',
     license=about.__license__,
-    packages=find_packages(exclude=['tests', 'tests/*', 'benchmarks', 'legacy', 'legacy/*']),
+    packages=find_packages(exclude=['tests*', 'pl_examples*', 'benchmarks*']),
+    include_package_data=True,
     long_description=long_description,
     long_description_content_type='text/markdown',
-    include_package_data=True,
     zip_safe=False,
     keywords=['deep learning', 'pytorch', 'AI'],
     python_requires='>=3.6',


Code review comments:
diff_hunk: @@ -32,8 +32,6 @@
     from torchvision import transforms
 if _TORCHVISION_MNIST_AVAILABLE:
     from torchvision.datasets import MNIST
-else:
-    from tests.helpers.datasets import MNIST
path: pl_examples/basic_examples/autoencoder.py
text: @user1:
I think the 3 or 4 are fine, but I would prefer 4.

@user2:
I think the best is 4)

@user3:
I would be against 3). This is nothing related to PL itself.
I also think 4) is best.