Sitelet https://github.com/appium/python-client/pull/547/files
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [ -z "$PYTHON_BIN_PATH" ]; then
PYTHON_BIN_PATH=$(which python3 || which python || true)
fi

export PYTHON_BIN_PATH

CONFIGURE_DIR=$(dirname "$0")
"$PYTHON_BIN_PATH" "${CONFIGURE_DIR}/script/release.py" "$@"

Expand Down
45 changes: 45 additions & 0 deletions script/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
# limitations under the License.
"""Release script to publish release module to pipy."""

import glob
import io
import os
import shutil
import subprocess
import sys
from typing import List

VERSION_FILE_PATH = os.path.join(os.path.dirname('__file__'), 'appium', 'version.py')
CHANGELOG_PATH = os.path.join(os.path.dirname('__file__'), 'CHANGELOG.rst')

APPIUM_DIR_PATH = os.path.join(os.path.dirname('__file__'), 'appium')
BUILT_APPIUM_DIR_PATH = os.path.join(os.path.dirname('__file__'), 'build', 'lib', 'appium')

MESSAGE_RED = '\033[1;31m{}\033[0m'
MESSAGE_GREEN = '\033[1;32m{}\033[0m'
MESSAGE_YELLOW = '\033[1;33m{}\033[0m'
Expand Down Expand Up @@ -101,6 +108,41 @@ def validate_release_env():
exit("Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7")


def build() -> None:
shutil.rmtree(BUILT_APPIUM_DIR_PATH, ignore_errors=True)
status, output = subprocess.getstatusoutput('{} setup.py install'.format(os.getenv('PYTHON_BIN_PATH')))
if status != 0:
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

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 🙀

for file_path in glob.glob(f"{root_dir}/**/*.py", recursive=True) + glob.glob(f"{root_dir}/**/*.typed", recursive=True)
]


def assert_files_count_in_package() -> None:
original_files = get_py_files_in_dir(APPIUM_DIR_PATH)
built_files = get_py_files_in_dir(BUILT_APPIUM_DIR_PATH)

if len(original_files) != len(built_files):
Comment thread
mykola-mokhnach marked this conversation as resolved.
print(f"The count of files in '{APPIUM_DIR_PATH}' and '{BUILT_APPIUM_DIR_PATH}' were different.")

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

if diff:
print(f"'{APPIUM_DIR_PATH}' has '{diff}' files than {BUILT_APPIUM_DIR_PATH}")
diff = built_files_set.difference(original_files_set)
if diff:
print(f"{BUILT_APPIUM_DIR_PATH} has {diff} files than {APPIUM_DIR_PATH}")

exit(f"Python files in '{BUILT_APPIUM_DIR_PATH}' may differ from '{APPIUM_DIR_PATH}'. "
"Please make sure setup.py is configured properly.")


def main():
validate_release_env()

Expand All @@ -109,6 +151,9 @@ def main():

update_version_file(new_version)

build()
assert_files_count_in_package()

ensure_publication(new_version)

commit_version_code(new_version)
Expand Down