Skip to content

Commit

Permalink
added fix to google module installing without __init__.py files causi…
Browse files Browse the repository at this point in the history
…ng linter fails
  • Loading branch information
jayam04 committed Apr 6, 2024
1 parent 8c540d5 commit 45fd210
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
39 changes: 24 additions & 15 deletions scripts/install_third_party_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ def compile_protobuf_files(proto_files_paths: List[str]) -> None:
r'^import (\w*_pb2 as)', r'from proto_files import \1')


def fix_google_module(correct_google_path):
"""Fixes the google module by creating __init__.py files in the
correct google module directory.
Args:
correct_google_path: str. The path to the correct google module.
"""
print(
'Checking that all google library modules contain __init__.py files...')
for path_list in os.walk(correct_google_path):
root_path = path_list[0]
if not root_path.endswith('__pycache__'):
with utils.open_file(
os.path.join(root_path, '__init__.py'), 'a'):
# If the file doesn't exist, it is created. If it does exist,
# this open does nothing.
pass


def main() -> None:
"""Install third-party libraries for Oppia."""
if feconf.OPPIA_IS_DOCKERIZED:
Expand Down Expand Up @@ -210,22 +229,12 @@ def main() -> None:
common.GOOGLE_APP_ENGINE_SDK_HOME, 'google', 'pyglib'),
os.path.join(correct_google_path, 'pyglib'))

# The following for loop populates all of the google modules with
# the correct __init__.py files if they do not exist. This solves the bug
# mentioned below where namespace packages sometimes install modules without
# __init__.py files (python requires modules to have __init__.py files in
# in order to recognize them as modules and import them):
# Following function populates google module with __init__.py files. This
# solves the bug mentioned below where namespace packages sometimes install
# modules without __init__.py files (python requires modules to have
# __init__.py files in order to recognize them as modules and import them):
# https://github.com/googleapis/python-ndb/issues/518
print(
'Checking that all google library modules contain __init__.py files...')
for path_list in os.walk(correct_google_path):
root_path = path_list[0]
if not root_path.endswith('__pycache__'):
with utils.open_file(
os.path.join(root_path, '__init__.py'), 'a'):
# If the file doesn't exist, it is created. If it does exist,
# this open does nothing.
pass
fix_google_module(correct_google_path)

if common.is_windows_os():
tweak_yarn_executable()
Expand Down
3 changes: 3 additions & 0 deletions scripts/linters/run_lint_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ def main(args: Optional[List[str]] = None) -> None:

if not feconf.OPPIA_IS_DOCKERIZED:
install_third_party_libs.main()
else:
install_third_party_libs.fix_google_module(
'/app/oppia/third_party/python_libs/google')

print('Starting Linter....')

Expand Down

0 comments on commit 45fd210

Please sign in to comment.