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

Fix os.walk issues in package-data sanity test #80703

Merged
merged 1 commit into from May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/sanity/code-smell/package-data.json
@@ -1,5 +1,6 @@
{
"disabled": true,
"all_targets": true,
"include_symlinks": true,
"output": "path-message"
}
39 changes: 7 additions & 32 deletions test/sanity/code-smell/package-data.py
Expand Up @@ -90,12 +90,8 @@ def assemble_files_to_ship(complete_file_list):

# Manpages
ignore_script = ('ansible-connection', 'ansible-test')
manpages = ['docs/man/man1/ansible.1']
for dirname, dummy, files in os.walk('bin'):
for filename in files:
if filename in ignore_script:
continue
manpages.append('docs/man/man1/%s.1' % filename)
script_names = [os.path.basename(path) for path in complete_file_list if path.startswith('bin/')]
manpages = [f'docs/man/man1/{name}.1' for name in script_names if name not in ignore_script]

# Misc
misc_generated_files = [
Expand Down Expand Up @@ -149,7 +145,7 @@ def clean_repository(file_list):
"""Copy the repository to clean it of artifacts"""
# Create a tempdir that will be the clean repo
with tempfile.TemporaryDirectory() as repo_root:
directories = set((repo_root + os.path.sep,))
directories = {repo_root + os.path.sep}

for filename in file_list:
# Determine if we need to create the directory
Expand Down Expand Up @@ -351,33 +347,12 @@ def check_installed_files_are_wanted(install_dir, to_install_files):
return results


def _find_symlinks():
symlink_list = []
for dirname, directories, filenames in os.walk('.'):
for filename in filenames:
path = os.path.join(dirname, filename)
# Strip off "./" from the front
path = path[2:]
if os.path.islink(path):
symlink_list.append(path)

return symlink_list


def main():
"""All of the files in the repository"""
complete_file_list = []
for path in sys.argv[1:] or sys.stdin.read().splitlines():
complete_file_list.append(path)

# ansible-test isn't currently passing symlinks to us so construct those ourselves for now
for filename in _find_symlinks():
if filename not in complete_file_list:
# For some reason ansible-test is passing us lib/ansible/module_utils/ansible_release.py
# which is a symlink even though it doesn't pass any others
complete_file_list.append(filename)

# We may run this after docs sanity tests so get a clean repository to run in
complete_file_list = sys.argv[1:] or sys.stdin.read().splitlines()

# Limit visible files to those reported by ansible-test.
# This avoids including files which are not committed to git.
with clean_repository(complete_file_list) as clean_repo_dir:
os.chdir(clean_repo_dir)

Expand Down