Skip to content

chore: add checking package file count comparison in release script#547

Merged
KazuCocoa merged 8 commits intoappium:masterfrom
KazuCocoa:check-package-file-count
May 20, 2020
Merged

chore: add checking package file count comparison in release script#547
KazuCocoa merged 8 commits intoappium:masterfrom
KazuCocoa:check-package-file-count

Conversation

@KazuCocoa
Copy link
Copy Markdown
Member

It help to prevent broken package like #542 without any expensive process.

return return_files

original_files = _get_py_files(APPIUM_DIR_PATH)
built_files = _get_py_files(BUILT_APPIUM_DIR_PATH)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we probably don't have to return file names, paths, but only counts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I considered which was better, but wanted to check the list when some packages was missed. The listed error message helped me to see the diff in #542 case. No strong opinion, but I won't write the similar code to get files when error happens for now. (Current count is not so huge like over 100)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

makes sense. In such case I'd consider returning sets instead and only show the actual difference between these sets (using difference helper)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea

@KazuCocoa KazuCocoa changed the title chore: add checking package file count comparison in release script [wip] chore: add checking package file count comparison in release script May 19, 2020

def _get_py_files(root_dir: str) -> List[str]:
def get_py_files_in_dir(root_dir: str) -> List[str]:
_files = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please remove all these starting underscores


return True
diff = set(original_files).difference(set(built_files))
if diff != set():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

simply if diff. Empty set is considered falsy

if diff != set():
print(f"'{APPIUM_DIR_PATH}' has '{diff}' files than {BUILT_APPIUM_DIR_PATH}")
diff = set(built_files).difference(set(original_files))
if diff != set():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⬆️

diff = set(original_files).difference(set(built_files))
if diff != set():
print(f"'{APPIUM_DIR_PATH}' has '{diff}' files than {BUILT_APPIUM_DIR_PATH}")
diff = set(built_files).difference(set(original_files))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

both sets could be precalculated

if not has_same_file_count_original_built():
exit("Python files in 'build/lib/appium' directory may differ from 'appium'. "
"Please make sure setup.py is configured properly.")
compare_file_count_in_package()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd say assert_files_count_in_package

Copy link
Copy Markdown
Collaborator

@ki4070ma ki4070ma left a comment

Choose a reason for hiding this comment

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

You could simplify, but it's ok.

exit(f'Failed to build the package:\n{output}')


def get_py_files_in_dir(root_dir: str) -> List[str]:
Copy link
Copy Markdown
Collaborator

@ki4070ma ki4070ma May 19, 2020

Choose a reason for hiding this comment

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

You can do the same thing as below. (maybe same?)

import glob
import os
files = glob.glob(f'{root_dir}/**/*.py', recursive=True) + glob.glob(f'{root_dir}/**/*.typed', recursive=True)
return [os.path.basename(x) for x in files]

(jfyi) https://docs.python.org/3/library/glob.html

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah, recursive is available in 3

@KazuCocoa KazuCocoa changed the title [wip] chore: add checking package file count comparison in release script chore: add checking package file count comparison in release script May 19, 2020
original_files = get_py_files_in_dir(APPIUM_DIR_PATH)
built_files = get_py_files_in_dir(BUILT_APPIUM_DIR_PATH)

print(len(original_files))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also mention what is printed: f'Original files count: {len(original_files)}'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oops, this is my debugging...

original_files_set = set(original_files)
built_files_set = set(built_files)

diff = original_files_set.difference(built_files_set)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah, often used the way in Ruby. Cool

base_dir_path_count = len(root_dir)
return [_file[base_dir_path_count:] for _file in _files]
return [
file_path[len(root_dir):]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so pythonic 🙀

@KazuCocoa KazuCocoa merged commit e3bd534 into appium:master May 20, 2020
@KazuCocoa KazuCocoa deleted the check-package-file-count branch May 20, 2020 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants