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

Convert bash scripts to Python #7465

Merged
merged 156 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
6ac0724
initial
Aug 17, 2019
13c37f9
fix lint
Aug 18, 2019
9ae6f2e
fix
Aug 18, 2019
2eca67e
fix
Aug 18, 2019
c9b6f98
conver
Aug 19, 2019
7218092
fix
Aug 19, 2019
9250dcb
fix
Aug 19, 2019
9d33246
convert
Aug 19, 2019
41113da
fix
Aug 19, 2019
4fe2b2d
Merge branch 'develop' into convert_bash_1
Aug 20, 2019
406129e
Merge branch 'develop' into convert_bash_1
Aug 21, 2019
beb3c52
add
Aug 22, 2019
77e21d7
convert
Aug 22, 2019
c5e3c97
fix lint
Aug 22, 2019
a5eebeb
convert
Aug 22, 2019
f9a8586
convert
Aug 22, 2019
afb7068
Merge branch 'develop' into convert_bash_1
Aug 23, 2019
dc1845c
convert
Aug 23, 2019
eee27b9
convert
Aug 24, 2019
a6dc5bb
convert
Aug 24, 2019
e88fd13
address
Aug 24, 2019
c373919
fix path
Aug 24, 2019
06dc081
convert
Aug 24, 2019
6b57f85
Merge branch 'develop' into convert_bash_1
Aug 25, 2019
845a94c
remove files
Aug 25, 2019
4df7247
convert
Aug 25, 2019
d3a2464
fix comment
Aug 25, 2019
275d886
convert
Aug 25, 2019
3482864
convert
Aug 25, 2019
0ab00ec
fix
Aug 25, 2019
cbb09a7
address comments
Aug 25, 2019
d2ed087
convert
Aug 25, 2019
1ced71c
convert
Aug 25, 2019
60510ae
fix lint
Aug 25, 2019
f83f917
update circleci
Aug 25, 2019
fb26396
fix
Aug 25, 2019
d0a9f56
convert
Aug 25, 2019
df0c880
fix
Aug 25, 2019
af66d95
fix
Aug 25, 2019
48c8ce8
fix
Aug 25, 2019
fcbbbb0
fix
Aug 25, 2019
0af2fc4
Merge branch 'develop' into convert_bash_1
Aug 25, 2019
d3f80a3
sync with develop
Aug 25, 2019
740eb7a
fix
Aug 25, 2019
c6ae74b
fix conflicts
Aug 26, 2019
2834e82
use parse known args
Aug 26, 2019
8bbda96
remove user
Aug 26, 2019
cd84f0b
fix pip
Aug 27, 2019
2c03e24
try subprocess on pip install
Aug 27, 2019
cd4a824
fix
Aug 27, 2019
ae51254
fix
Aug 27, 2019
a7e21c5
fix
Aug 27, 2019
e9fd69d
fix
Aug 27, 2019
b26d7dc
fix
Aug 27, 2019
33a10ce
add node path
Aug 27, 2019
8ba23a5
fix
Aug 27, 2019
db7a003
fix lint
Aug 27, 2019
f521c7a
add args
Aug 27, 2019
b6d5878
fix lint
Aug 27, 2019
3086329
merge develo
Aug 27, 2019
b912d6d
add path
Aug 27, 2019
efabda0
address comments
Aug 27, 2019
899228a
address comments
Aug 27, 2019
6044c23
fix
Aug 27, 2019
c28656b
fix
Aug 27, 2019
2d62316
fix
Aug 27, 2019
1e7bcdb
fix
Aug 27, 2019
3a97331
fix frontend
Aug 28, 2019
cfad6b3
fix
Aug 28, 2019
11ae549
fix start
Aug 28, 2019
46eb948
fix lint
Aug 28, 2019
95b6ca9
clear cache
Aug 28, 2019
7130eb7
revert
Aug 28, 2019
13155a5
remove pylint
Aug 28, 2019
86647a8
remove pylint path
Aug 28, 2019
7c47253
add path
Aug 28, 2019
efc69b0
add pylint path
Aug 28, 2019
834bffa
fix
Aug 28, 2019
0186a8a
fix
Aug 28, 2019
326eda8
use vurtual env
Aug 28, 2019
4f4b3c2
fix
Aug 28, 2019
ad9fbae
fix
Aug 28, 2019
34efc74
add url in travis yaml
Aug 28, 2019
2d3d642
test
Aug 28, 2019
dcf6ec3
test
Aug 28, 2019
b532ba0
fix
Aug 28, 2019
f58f27a
test
Aug 28, 2019
93b7cf4
test
Aug 28, 2019
01970a5
test
Aug 28, 2019
eda2856
test
Aug 28, 2019
92d39d5
test
Aug 28, 2019
98b324b
test
Aug 28, 2019
4cc089c
test
Aug 28, 2019
2f2871c
tes
Aug 28, 2019
14d2659
fi
Aug 28, 2019
862490c
fix
Aug 28, 2019
1ec120f
test
Aug 28, 2019
9386c0c
fix conflicts
Aug 29, 2019
11d891d
fix
Aug 29, 2019
07eaf2b
Merge branch 'develop' into convert_bash_1
Aug 30, 2019
ce7d114
fix
Aug 30, 2019
6f04c1b
fix test
Aug 30, 2019
767d97e
fix
Aug 30, 2019
82804cb
fix conflicts
Aug 31, 2019
8e43243
fix
Aug 31, 2019
fabf517
address comments
Aug 31, 2019
8b7bb5a
fix
Aug 31, 2019
057f2e6
fix node
Aug 31, 2019
8003bfe
fix
Aug 31, 2019
25b64ad
remove vagrant
Aug 31, 2019
0492abe
fix
Aug 31, 2019
fd168ab
address comments
Aug 31, 2019
77ddcbc
fix conflicts
Aug 31, 2019
d89c3b0
fix lint
Aug 31, 2019
251669a
fix
Aug 31, 2019
b07b0d9
fix
Aug 31, 2019
03e56b7
address comments
Aug 31, 2019
770cd4f
fix
Aug 31, 2019
fafbde2
fix
Sep 1, 2019
9ec9238
fix
Sep 1, 2019
33f38a7
fix
Sep 1, 2019
35cfe60
fix
Sep 1, 2019
af6ad16
merge develop
Sep 2, 2019
55a1a99
address comments
Sep 2, 2019
c604eae
fix
Sep 2, 2019
90b50d8
fix
Sep 2, 2019
5bdc8b1
fix
Sep 2, 2019
891d088
only one backend_tests.py
Sep 2, 2019
a6e6b28
address comments
Sep 2, 2019
a42a17c
Merge branch 'develop' into convert_bash_1
Sep 2, 2019
28eaabe
fix
Sep 2, 2019
6e9b993
fix
Sep 2, 2019
7bf028d
fix
Sep 2, 2019
f0ebb60
fix
Sep 2, 2019
8fe8d20
fix errors
Sep 2, 2019
b73afbf
address comments
Sep 2, 2019
1b4638b
fix
Sep 2, 2019
64fc6c5
use None and args
Sep 2, 2019
320b65e
fix permission
Sep 2, 2019
127cead
fix
Sep 2, 2019
595be3c
fix conflicts
Sep 2, 2019
6939582
address comments
Sep 2, 2019
80a9599
fix e2e
Sep 3, 2019
5ac03b0
address comments
Sep 3, 2019
9a84e6f
fix
Sep 3, 2019
770c6f3
fix
Sep 3, 2019
d713208
skip e2e
Sep 3, 2019
c3006d2
remove yaml
Sep 3, 2019
2459c84
fix lint
Sep 3, 2019
89f61e6
use single quotes
Sep 4, 2019
07814eb
fix conflicts
Sep 7, 2019
89afe82
fix conflicts
Sep 7, 2019
6967564
test
Sep 7, 2019
6ba9902
fix linr
Sep 7, 2019
943759b
add tests
Sep 8, 2019
911d84a
use triple strings
Sep 8, 2019
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
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
Rishav Chakraborty committed Sep 3, 2019
commit 5ac03b0a2f414b57925daf2e08d735ded32e7fa8
5 changes: 3 additions & 2 deletions core/tests/gae_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def create_test_suites(test_target=None):
top_level_dir=CURR_DIR)])


def main():
def main(args=None):
"""Runs the tests."""
parsed_args = _PARSER.parse_args(args=args)

for directory in DIRS_TO_ADD_TO_SYS_PATH:
if not os.path.exists(os.path.dirname(directory)):
raise Exception('Directory %s does not exist.' % directory)
Expand All @@ -91,7 +93,6 @@ def main():
import dev_appserver
dev_appserver.fix_sys_path()

parsed_args = _PARSER.parse_args()
suites = create_test_suites(test_target=parsed_args.test_target)

results = [unittest.TextTestRunner(verbosity=2).run(suite)
Expand Down
6 changes: 3 additions & 3 deletions core/tests/gae_suite_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_cannot_add_directory_with_invalid_path(self):
assert_raises_regexp_context_manager = self.assertRaisesRegexp(
Exception, 'Directory invalid_path does not exist.')
with assert_raises_regexp_context_manager, dir_to_add_swap:
gae_suite.main()
gae_suite.main(args=[])

def test_failing_tests(self):

Expand All @@ -57,7 +57,7 @@ def _mock_create_test_suites(**unused_test_target):
'Test suite failed: 1 tests run, 0 errors, 1 failures.')

with create_test_suites_swap, assert_raises_regexp_context_manager:
gae_suite.main()
gae_suite.main(args=[])

def test_no_tests_run_with_invalid_filename(self):

Expand All @@ -72,4 +72,4 @@ def _mock_create_test_suites(**unused_test_target):
Exception, 'No module named invalid_test')

with create_test_suites_swap, assert_raises_regexp_context_manager:
gae_suite.main()
gae_suite.main(args=[])
14 changes: 7 additions & 7 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@
APP_DEV_YAML_FILEPATH = 'app_dev.yaml'
APP_YAML_FILEPATH = 'app.yaml'

_PARSER = argparse.ArgumentParser()
_PARSER = argparse.ArgumentParser(description="""
Creates a third-party directory where all the JS and CSS dependencies are
built and stored. Depending on the options passed to the script, might also
minify third-party libraries and/or generate a build directory.
""")

_PARSER.add_argument(
'--prod_env', action='store_true', default=False, dest='prod_mode')
_PARSER.add_argument(
Expand Down Expand Up @@ -1359,12 +1364,7 @@ def compile_typescript_files_continuously(project_dir):


def main(args=None):
"""The main method of this script.

Creates a third-party directory where all the JS and CSS dependencies are
built and stored. Depending on the options passed to the script, might also
minify third-party libraries and/or generate a build directory.
"""
"""The main method of this script."""
options = _PARSER.parse_args(args=args)
# Regenerate /third_party/generated from scratch.
safe_delete_directory_tree(THIRD_PARTY_GENERATED_DEV_DIR)
Expand Down
6 changes: 3 additions & 3 deletions scripts/build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def mock_compare_file_count(unused_first_dir, unused_second_dir):

with ensure_files_exist_swap, build_using_webpack_swap, (
compile_typescript_files_swap), compare_file_count_swap, args_swap:
build.main()
build.main(args=[])

self.assertEqual(check_function_calls, expected_check_function_calls)

Expand Down Expand Up @@ -950,7 +950,7 @@ def mock_compile_typescript_files_continuously(unused_project_dir):

with ensure_files_exist_swap, (
compile_typescript_files_continuously_swap), args_swap:
build.main()
build.main(args=[])

self.assertEqual(check_function_calls, expected_check_function_calls)

Expand Down Expand Up @@ -982,7 +982,7 @@ def mock_compile_typescript_files(unused_project_dir):

with ensure_files_exist_swap, compile_typescript_files_swap, (
assert_raises_regexp_context_manager), args_swap:
build.main()
build.main(args=[])

self.assertEqual(check_function_calls, expected_check_function_calls)

Expand Down
9 changes: 8 additions & 1 deletion scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import absolute_import # pylint: disable=import-only-modules
from __future__ import unicode_literals # pylint: disable=import-only-modules

import argparse
import os
import shutil

Expand All @@ -24,6 +25,10 @@
CURR_DIR = os.path.abspath(os.getcwd())
OPPIA_TOOLS_DIR = os.path.join(CURR_DIR, '..', 'oppia_tools')

_PARSER = argparse.ArgumentParser(description="""
Deletes temporary and installed files.
""")


def delete_directory_tree(directory_path):
"""Recursively delete an existing directory tree. Does not do anything if
Expand All @@ -48,8 +53,10 @@ def delete_file(filepath):
os.remove(filepath)


def main():
def main(args=None):
"""Runs the script to clean temporary and installed files."""
unused_parsed_args = _PARSER.parse_args(args=args)

delete_directory_tree(OPPIA_TOOLS_DIR)
delete_directory_tree('node_modules/')
delete_directory_tree('third_party/')
Expand Down
8 changes: 4 additions & 4 deletions scripts/create_expression_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from . import setup

_PARSER = argparse.ArgumentParser(description="""
Run this script from the oppia root folder:
python -m scripts.create_expression_parser

The root folder MUST be named 'oppia'.""")
Run this script from the oppia root folder:
python -m scripts.create_expression_parser
The root folder MUST be named 'oppia'.
""")


def main(args=None):
Expand Down
5 changes: 3 additions & 2 deletions scripts/install_chrome_on_travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import python_utils

_PARSER = argparse.ArgumentParser(description="""
This script should only be ran by Travis to install and provide a constant
version of Chrome.""")
This script should only be ran by Travis to install and provide a constant
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This script should only be ran by Travis to install and provide a constant
This script should only be run by Travis to install and provide a constant

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, shouldn't these lines ideally be indented by two? I think you can use single quote strings instead of """ as we typically use the latter for docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and used single quotes

Copy link
Contributor

@brianrodri brianrodri Sep 4, 2019

Choose a reason for hiding this comment

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

The description is exceptional since it typically has a ton of information to give. Also, indents show up in the command line and makes the output look weird.

I'm fine with this case since it's just one sentence, but I think it'd be a better idea to use triple-quotes for >1 paragraph descriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested with single quotes and the indent does not get messed up. So should I still revert the last commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also isn't it better to have a use only one type of quotes throughout all descriptions, just to maintain consistency

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, having the description break at 80-characters is a nice plus too for very long sentences (which will not happen here).

I vote for triple-quote strings and no indentations, what do you think @nithusha21?

version of Chrome.
""")


def main(args=None):
Expand Down
3 changes: 2 additions & 1 deletion scripts/install_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
}

_PARSER = argparse.ArgumentParser(description="""
Installation script for Oppia third-party libraries.""")
Installation script for Oppia third-party libraries.
""")


def download_files(source_url_root, target_dir, source_filenames):
Expand Down
10 changes: 6 additions & 4 deletions scripts/install_third_party_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
# pylint: enable=wrong-import-position

_PARSER = argparse.ArgumentParser(description="""
Installation script for Oppia third-party libraries.""")
Installation script for Oppia third-party libraries.
""")

_PARSER.add_argument(
'--nojsrepl',
Expand Down Expand Up @@ -108,7 +109,7 @@ def pip_install(package, version, install_path):
install_path])


def install_skulpt(args):
def install_skulpt(parsed_args):
"""Download and install Skulpt. Skulpt is built using a Python script
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
included within the Skulpt repository (skulpt.py). This script normally
requires GitPython, however the patches to it below
Expand All @@ -118,7 +119,6 @@ def install_skulpt(args):
warning saying its dist command will not work properly without GitPython,
but it does actually work due to the patches.
"""
parsed_args = _PARSER.parse_args(args=args)
no_skulpt = parsed_args.nojsrepl or parsed_args.noskulpt

python_utils.PRINT('Checking whether Skulpt is installed in third_party')
Expand Down Expand Up @@ -228,6 +228,8 @@ def ensure_pip_library_is_installed(package, version, path):

def main(args=None):
"""Install third-party libraries for Oppia."""
parsed_args = _PARSER.parse_args(args=args)

setup.main(args=[])
setup_gae.main(args=[])
pip_dependencies = [
Expand Down Expand Up @@ -257,7 +259,7 @@ def main(args=None):
# 374076889.
subprocess.call([common.NPM_PATH, 'dedupe'])

install_skulpt(args)
install_skulpt(parsed_args)

# Install pre-commit script.
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
python_utils.PRINT('Installing pre-commit hook for git')
Expand Down
11 changes: 8 additions & 3 deletions scripts/release_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@

Log = collections.namedtuple('Log', ['sha1', 'author', 'email', 'message'])

_PARSER = argparse.ArgumentParser()
_PARSER = argparse.ArgumentParser(description="""
Script that simplifies releases by collecting various information.
Should be run from the oppia root dir.
""")

_PARSER.add_argument(
'--personal_access_token',
help=(
Expand Down Expand Up @@ -293,14 +297,15 @@ def _check_storage_models(current_release):
return [item for item in diff_list if item.startswith('core/storage')]


def main():
def main(args=None):
"""Collects necessary info and dumps it to disk."""
parsed_args = _PARSER.parse_args(args=args)

branch_name = _get_current_branch()
if not re.match(r'release-\d+\.\d+\.\d+$', branch_name):
raise Exception(
'This script should only be run from the latest release branch.')

parsed_args = _PARSER.parse_args()
if parsed_args.personal_access_token is None:
python_utils.PRINT(
'No personal access token provided, please set up a personal '
Expand Down
12 changes: 6 additions & 6 deletions scripts/run_backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@


_PARSER = argparse.ArgumentParser(description="""
Run this script from the oppia root folder:

python -m scripts.run_backend_tests

IMPORTANT: Only one of --test_path and --test_target should be specified""")
Run this script from the oppia root folder:
python -m scripts.run_backend_tests
IMPORTANT: Only one of --test_path and --test_target should be specified.
""")

_EXCLUSIVE_GROUP = _PARSER.add_mutually_exclusive_group()
_EXCLUSIVE_GROUP.add_argument(
Expand Down Expand Up @@ -310,6 +309,8 @@ def _get_test_target_classes(path):

def main(args=None):
"""Run the tests."""
parsed_args = _PARSER.parse_args(args=args)

setup.main(args=[])
setup_gae.main(args=[])

Expand All @@ -321,7 +322,6 @@ def main(args=None):
import dev_appserver
dev_appserver.fix_sys_path()

parsed_args = _PARSER.parse_args(args=args)
if parsed_args.generate_coverage_report:
python_utils.PRINT(
'Checking whether coverage is installed in %s'
Expand Down
36 changes: 16 additions & 20 deletions scripts/run_e2e_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
from . import setup_gae

_PARSER = argparse.ArgumentParser(description="""
Run this script from the oppia root folder:

python -m scripts.run_e2e_tests

The root folder MUST be named 'oppia'.

Note: You can replace 'it' with 'fit' or 'describe' with 'fdescribe' to run
a single test or test suite.""")
Run this script from the oppia root folder:
python -m scripts.run_e2e_tests
The root folder MUST be named 'oppia'.
Note: You can replace 'it' with 'fit' or 'describe' with 'fdescribe' to run
a single test or test suite.
""")

_PARSER.add_argument(
'--skip_install',
Expand Down Expand Up @@ -103,12 +101,13 @@ def cleanup():

def main(args=None):
"""Runs the end to end tests."""
parsed_args = _PARSER.parse_args(args=args)

setup.main(args=[])
setup_gae.main(args=[])
if os.environ.get('TRAVIS'):
install_chrome_on_travis.main(args=[])

parsed_args = _PARSER.parse_args(args=args)
install_third_party_libs.maybe_install_dependencies(
parsed_args.skip_install, parsed_args.run_minified_tests)

Expand Down Expand Up @@ -174,21 +173,18 @@ def main(args=None):
# info logs to stderr so we discard them.
# TODO(jacob): Find a webdriver or selenium argument that controls log
# level.
background_processes = []
background_processes.append(subprocess.Popen([
os.path.join(common.NODE_MODULES_PATH, '.bin', 'webdriver-manager'),
'start', '2>/dev/null']))
subprocess.Popen(
'(%s start 2>/dev/null)&'
% os.path.join(common.NODE_MODULES_PATH, '.bin', 'webdriver-manager'),
shell=True)
# Start a demo server.
background_processes.append(subprocess.Popen(
'python %s/dev_appserver.py --host=0.0.0.0 --port=%s '
subprocess.Popen(
'(python %s/dev_appserver.py --host=0.0.0.0 --port=%s '
'--clear_datastore=yes --dev_appserver_log_level=critical '
'--log_level=critical --skip_sdk_update_check=true %s' % (
'--log_level=critical --skip_sdk_update_check=true %s)&' % (
common.GOOGLE_APP_ENGINE_HOME,
python_utils.UNICODE(PORT_NUMBER_FOR_GAE_SERVER),
app_yaml_filepath), shell=True))

for process in background_processes:
process.wait()
app_yaml_filepath), shell=True)

# Wait for the servers to come up.
while not common.is_port_open(
Expand Down
17 changes: 8 additions & 9 deletions scripts/run_frontend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
from . import setup_gae

_PARSER = argparse.ArgumentParser(description="""
Run this script from the oppia root folder:

python -m scripts.run_frontend_tests

The root folder MUST be named 'oppia'.

Note: You can replace 'it' with 'fit' or 'describe' with 'fdescribe' to run
a single test or test suite.""")
Run this script from the oppia root folder:
python -m scripts.run_frontend_tests
The root folder MUST be named 'oppia'.
Note: You can replace 'it' with 'fit' or 'describe' with 'fdescribe' to run
a single test or test suite.
""")

_PARSER.add_argument(
'--skip_install',
Expand All @@ -51,10 +49,11 @@

def main(args=None):
"""Runs the frontend tests."""
parsed_args = _PARSER.parse_args(args=args)

setup.main(args=[])
setup_gae.main(args=[])

parsed_args = _PARSER.parse_args(args=args)
install_third_party_libs.maybe_install_dependencies(
parsed_args.skip_install, parsed_args.run_minified_tests)
common.print_each_string_after_two_new_lines([
Expand Down
Loading