Sitelet https://github.com/appium/python-client/pull/547
Skip to content

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

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

KazuCocoa merged 8 commits into
appium: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.

Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
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

Comment thread script/release.py Outdated
Comment thread script/release.py
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
Comment thread script/release.py Outdated
@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
Comment thread script/release.py Outdated

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

Comment thread script/release.py Outdated

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

Comment thread script/release.py Outdated
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.

⬆️

Comment thread script/release.py Outdated
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

Comment thread script/release.py Outdated
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

@ki4070ma ki4070ma left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread script/release.py
exit(f'Failed to build the package:\n{output}')


def get_py_files_in_dir(root_dir: str) -> List[str]:

@ki4070ma ki4070ma May 19, 2020 •

Copy link
Copy Markdown
Collaborator

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
Comment thread script/release.py Outdated
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...

Comment thread script/release.py
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

Comment thread script/release.py
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