Skip to content

Commit

Permalink
Fix part of oppia#21020: Upgrade Python to 3.9 (oppia#21215)
Browse files Browse the repository at this point in the history
* Update to python 3.9

* Fix isAlive

* Fix import ordering

* Fix import ordering

* Fix test

* use python3.9.20 for docker

* Fix lint errors, remove spurious changes

* Fix lint issues

* Address review comment.
  • Loading branch information
seanlip authored Nov 1, 2024
1 parent 996739e commit 39d9f94
Show file tree
Hide file tree
Showing 35 changed files with 123 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/backend_associated_test_file_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/backend_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Initialize Containers
if: startsWith(github.head_ref, 'update-changelog-for-release') == false
Expand Down Expand Up @@ -60,10 +60,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Install coverage
if: startsWith(github.head_ref, 'update-changelog-for-release') == false
Expand Down Expand Up @@ -130,10 +130,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Download time report for shard 1
uses: actions/download-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check_test_suites_to_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
fetch-depth: 0
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
- name: Setup Python 3.8 with pip cache
- name: Setup Python 3.9.20 with pip cache
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: |
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/e2e_lighthouse_performance_acceptance_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8 with pip cache
- name: Setup Python 3.9.20 with pip cache
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: |
Expand Down Expand Up @@ -84,10 +84,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8 with pip cache
- name: Setup Python 3.9.20 with pip cache
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: |
Expand Down Expand Up @@ -200,10 +200,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down Expand Up @@ -290,10 +290,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8 with pip cache
- name: Setup Python 3.9.20 with pip cache
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: |
Expand Down Expand Up @@ -393,10 +393,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/eslint_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/frontend_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ jobs:
ls /home/runner/work/oppia
ls /home/runner/work/oppia/oppia
echo $GITHUB_WORKSPACE
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lighthouse_accessibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down Expand Up @@ -91,10 +91,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8 with pip cache
- name: Setup Python 3.9.20 with pip cache
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Free disk space
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pending-review-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
# SHA1 hash of the develop commit.
- name: Notify reviewers
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python_type_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Merge develop branch into the current branch
uses: ./.github/actions/merge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typescript_and_e2e_acceptance_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.8
- name: Setup Python 3.9.20
uses: actions/setup-python@v4
with:
python-version: '3.8.15'
python-version: '3.9.20'
architecture: 'x64'
- name: Free disk space
run: |
Expand Down
2 changes: 1 addition & 1 deletion app_dev.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
runtime: python38
runtime: python39
instance_class: F2
# The "version" line is added here so that MR jobs can run locally (see issue
# #6534 on oppia/oppia).
Expand Down
99 changes: 15 additions & 84 deletions core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import datetime
import functools
import inspect
import io
import itertools
import json
import logging
Expand All @@ -33,7 +34,6 @@
import random
import re
import string
from types import TracebackType
import unittest

from core import feature_flag_list
Expand Down Expand Up @@ -87,9 +87,9 @@
import elasticsearch
import requests_mock
from typing import (
IO, Any, Callable, Collection, Dict, Final, Iterable, Iterator, List,
Literal, Mapping, Optional, OrderedDict, Pattern, Sequence, Set, Tuple,
Type, TypedDict, TypeVar, Union, cast, overload
Any, Callable, Collection, Dict, Final, Iterable, Iterator, List,
Literal, Mapping, Optional, OrderedDict, Pattern, Sequence, Set,
Tuple, Type, TypedDict, TypeVar, Union, cast, overload
)
import webapp2
import webtest
Expand Down Expand Up @@ -1505,94 +1505,25 @@ def capture_logging(
"""
captured_logs: List[str] = []

class ListStream(IO[str]):
class ListStream(io.StringIO):
"""Stream-like object that appends writes to the captured logs."""

# Here we use MyPy ignore because the signature of this
# method doesn't match with IO's write().
def write(self, msg: str) -> None: # type: ignore[override]
"""Appends stripped messages to captured logs."""
def write(self, msg: str) -> int:
"""Appends stripped messages to captured logs.
Args:
msg: str. The string to be written.
Returns:
int. The length of the written string in bytes.
"""
captured_logs.append(msg.strip())
return len(msg.strip())

def flush(self) -> None:
"""Does nothing."""
pass

# Here, class ListStream inherits from IO and making an instance
# below but due to the absence of some methods MyPy throws an error
# that 'Cannot instantiate abstract class 'ListStream' with abstract
# attributes'. So, to suppress the error, we defined all the methods
# that was present in super class. Since these are just added for
# type checking, we don't need to test them and so have excluded
# them from the coverage checks.
@property
def mode(self) -> str:
pass # pragma: no cover

@property
def name(self) -> str:
pass # pragma: no cover

def close(self) -> None:
pass # pragma: no cover

@property
def closed(self) -> bool:
pass # pragma: no cover

def fileno(self) -> int:
pass # pragma: no cover

def isatty(self) -> bool:
pass # pragma: no cover

def read(self, n: int = -1) -> str:
pass # pragma: no cover

def readable(self) -> bool:
pass # pragma: no cover

def readline(self, limit: int = -1) -> str:
pass # pragma: no cover

def readlines(self, hint: int = -1) -> List[str]:
pass # pragma: no cover

def seek(self, offset: int, whence: int = 0) -> int:
pass # pragma: no cover

def seekable(self) -> bool:
pass # pragma: no cover

def tell(self) -> int:
pass # pragma: no cover

def truncate(self, size: Optional[int] = None) -> int:
pass # pragma: no cover

def writable(self) -> bool:
pass # pragma: no cover

def writelines(self, lines: Iterable[str]) -> None:
pass # pragma: no cover

def __enter__(self) -> IO[str]:
pass # pragma: no cover

def __exit__(
self,
type: Optional[Type[BaseException]], # pylint: disable=redefined-builtin
value: Optional[BaseException],
traceback: Optional[TracebackType]
) -> None:
pass # pragma: no cover

def __iter__(self) -> Iterator[str]:
pass # pragma: no cover

def __next__(self) -> str:
pass # pragma: no cover

list_stream_handler = logging.StreamHandler(ListStream())

logger = logging.getLogger()
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Added platform flag here because -- https://stackoverflow.com/questions/71040681/qemu-x86-64-could-not-open-lib64-ld-linux-x86-64-so-2-no-such-file-or-direc
FROM --platform=linux/amd64 python:3.8.17-slim-buster AS backend
FROM --platform=linux/amd64 python:3.9.20-bullseye AS backend

ENV OPPIA_IS_DOCKERIZED="true"

Expand Down
Loading

0 comments on commit 39d9f94

Please sign in to comment.