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

Verify package data in setup.py installs all files #59537

Merged
merged 10 commits into from
Jul 24, 2019

Conversation

sivel
Copy link
Member

@sivel sivel commented Jul 24, 2019

SUMMARY

Verify package data in setup.py installs all files

We recently added a new data file and it was not matched by package_data and thus not installed: #59452

This test will help ensure new data files are properly installed, as we have missed several in the past.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

test/sanity/code-smell/package-data.py

ADDITIONAL INFORMATION

before the change to setup.py:

ERROR: Found 1 package-data issue(s) which need to be resolved:
ERROR: lib/ansible/galaxy/data/default/role/tests/inventory:0:0: File not installed
ERROR: The 1 sanity test(s) listed below (out of 1) failed. See error output above for details.

@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2019

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Jul 24, 2019
@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2019

@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2019

@ansibot ansibot added docs This issue/PR relates to or includes documentation. docsite This issue/PR relates to the documentation website. and removed small_patch labels Jul 24, 2019
Copy link
Member

@mattclay mattclay left a comment

Choose a reason for hiding this comment

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

This test needs to be added to https://github.com/ansible/ansible/blob/devel/test/sanity/code-smell/ansible-only.txt since it should not be run on collections.

Also, I don't particularly like having an always running sanity test that runs for 10+ seconds, since it will more than double the time it takes to run sanity tests on a single file.

One option would be to parse package_data from setup.py and check that, rather than performing an actual install. It would be very fast, and nearly as good as performing an actual install. That may be good enough, unless you're aware of scenarios where that is likely to miss something.

for root, dirs, files in os.walk('lib/ansible/'):
for filename in files:
path = os.path.join(root, filename)
if os.path.splitext(path)[-1] not in ('.py', '.pyc', '.pyo'):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if os.path.splitext(path)[-1] not in ('.py', '.pyc', '.pyo'):
if os.path.splitext(path)[1] not in ('.py', '.pyc', '.pyo'):

if fnmatch.fnmatch(path, ignore):
add = False
if add:
non_py_files.append(path[12:])
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer using os.path functions for path manipulation instead of string slicing.

for filename in non_py_files:
path = os.path.join(match.group(1), filename)
if not os.path.exists(path):
print('lib/ansible/%s: File not installed' % filename)
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer os.path.join here.

It's not a big issue though -- we certainly have plenty of other places where string concatenation is done.

@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2019

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jul 24, 2019
@mattclay
Copy link
Member

@sivel I discussed this with @nitzmahone and he pointed out that if entries are not correct in MANIFEST.in then we could miss things by looking only at package_data -- so it seems the only safe thing to do is run the install as you're already doing.

To avoid unnecessary overhead, lets treat this like we do the docs-build sanity test and make it disabled by default. It can be disabled like this:

Then enabled in CI here:

2) options=(--test ansible-doc --test docs-build) ;;

@sivel sivel merged commit 95f4282 into ansible:devel Jul 24, 2019
@ansible ansible locked and limited conversation to collaborators Aug 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. docsite This issue/PR relates to the documentation website. feature This issue/PR relates to a feature request. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants