Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make anomalib PEP 561 compliant for mypy #1038

Merged

Conversation

WenjingKangIntel
Copy link
Contributor

@WenjingKangIntel WenjingKangIntel commented Apr 25, 2023

Description

  • Provide a summary of the modification as well as the issue that has been resolved. List any dependencies that this modification necessitates.
    This PR aims to make anomalib PEP 561 compliant for mypy:
  1. Add py.typed file in package directory.
  2. Include py.typed in MANIFEST.in.
    reference:
    https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages

If we have a test_mypy.py for testing with the following content:
from anomalib.config import get_configurable_parameters, update_nncf_config
Before this PR, when running: mypy test_pep561.py, it will generate the following error.

test_pep561.py:1: error: Skipping analyzing "anomalib.config": module is installed, but missing library stubs or py.typed marker  [import]
test_pep561.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

After this PR, it will have the following output:
Success: no issues found in 1 source file
This shows that this PR can make anomalib PEP 561 compliant for mypy.

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which refactors the code base)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • I have added a summary of my changes to the CHANGELOG (not for minor changes, docs and tests).

Copy link
Contributor

@samet-akcay samet-akcay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the contribution!

Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we need to also include a line in setup.py. Something like

 package_data={"anomalib": ["py.typed"]},

@WenjingKangIntel
Copy link
Contributor Author

Do you think we need to also include a line in setup.py. Something like

 package_data={"anomalib": ["py.typed"]},

Hi, Vaidya,
From the link:
https://setuptools.pypa.io/en/latest/userguide/datafiles.html#summary
package_data specifies additional patterns to match files that may or may not be matched by MANIFEST.in. The results turn out the content in MANIFEST.in is matched.

Some more information about:
https://packaging.python.org/en/latest/guides/using-manifest-in/
all files specified by the package_data and data_files setup() arguments and the commands in MANIFEST.in (if such a file exists) are executed in order to add and remove further files to and from the sdist.

Conclusion:
Please double check. From my understanding, adding "py.typed" to package_data is not needed.

@ashwinvaidya17
Copy link
Collaborator

Do you think we need to also include a line in setup.py. Something like

 package_data={"anomalib": ["py.typed"]},

Hi, Vaidya, From the link: https://setuptools.pypa.io/en/latest/userguide/datafiles.html#summary package_data specifies additional patterns to match files that may or may not be matched by MANIFEST.in. The results turn out the content in MANIFEST.in is matched.

Some more information about: https://packaging.python.org/en/latest/guides/using-manifest-in/ all files specified by the package_data and data_files setup() arguments and the commands in MANIFEST.in (if such a file exists) are executed in order to add and remove further files to and from the sdist.

Conclusion: Please double check. From my understanding, adding "py.typed" to package_data is not needed.

I tried using both python -m build and python setup.py sdist bdist_wheel to generate distribution package. When I use python -m build, the py.typed file is present in the distribution however, if I use python setup.py ... then this file is missing. So, when we upload to pip, the inclusion of this file depends on what method the pip uploader uses to generate the distribution. Not sure what's the standard approach to generate distributions. @samet-akcay any thoughts on this?

@samet-akcay
Copy link
Contributor

Do you think we need to also include a line in setup.py. Something like

 package_data={"anomalib": ["py.typed"]},

Hi, Vaidya, From the link: https://setuptools.pypa.io/en/latest/userguide/datafiles.html#summary package_data specifies additional patterns to match files that may or may not be matched by MANIFEST.in. The results turn out the content in MANIFEST.in is matched.
Some more information about: https://packaging.python.org/en/latest/guides/using-manifest-in/ all files specified by the package_data and data_files setup() arguments and the commands in MANIFEST.in (if such a file exists) are executed in order to add and remove further files to and from the sdist.
Conclusion: Please double check. From my understanding, adding "py.typed" to package_data is not needed.

I tried using both python -m build and python setup.py sdist bdist_wheel to generate distribution package. When I use python -m build, the py.typed file is present in the distribution however, if I use python setup.py ... then this file is missing. So, when we upload to pip, the inclusion of this file depends on what method the pip uploader uses to generate the distribution. Not sure what's the standard approach to generate distributions. @samet-akcay any thoughts on this?

Maybe we could verify this by uploading to test-pypi?
https://packaging.python.org/en/latest/guides/using-testpypi/

This enables PEP 561 compliance for mypy via adding py.typed and MANIFEST.in.

Fixes openvinotoolkit#1015

Signed-off-by: Yuan, Jinjie <jinjie.yuan@intel.com>
Signed-off-by: Kang Wenjing <wenjing.kang@intel.com>
@samet-akcay
Copy link
Contributor

We could merge this once the CI passes.

@samet-akcay samet-akcay merged commit d81dbb5 into openvinotoolkit:main Apr 27, 2023
@ORippler
Copy link
Contributor

ORippler commented May 11, 2023

I just did an install of anomalib==0.5.0 from pypi via pip and py.typed was not present in the anomalib folder, so it's not yet fully compliant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Make anomalib PEP 561 compliant for mypy
4 participants