Skip to content

Commit

Permalink
Remove references to Python 2. (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlip authored Nov 17, 2024
1 parent b7e7f32 commit 7c7abcf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Backend-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ Notice that the test class inherits from `test_utils.GenericTestBase`, which pro
```python
self.swap_with_checks(
subprocess, 'Popen', mock_popen,
expected_args=[(['python'],), (['python2'],)],
expected_args=[(['python'],), (['python3'],)],
expected_kwargs=[{'shell': True}, {'shell': False}])
```

This code will assert that `mock_popen` receives the following calls in order:

```python
mock_popen(['python'], shell=True)
mock_popen(['python2'], shell=False)
mock_popen(['python3'], shell=False)
```

These swap functions each return a context where the mocking has been performed. You'll see this called a `swap` in the code. You can use the swap like this:
Expand Down
12 changes: 6 additions & 6 deletions Debug-backend-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Normally, we suppress any console output from passing tests, so even if you add
[datastore] Sep 19, 2021 3:30:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[datastore] INFO: Detected HTTP/2 connection.
19:30:23 FINISHED scripts.run_e2e_tests_test.RunE2ETestsTests.test_is_oppia_server_already_running_when_ports_closed: 22.1 secs
Stopping Redis Server(name="redis-server", pid=37086)...
Stopping Cloud Datastore Emulator(name="python2.7", pid=37069)...
Stopping Redis Server(name="sh", pid=37086)...
Stopping Cloud Datastore Emulator(name="sh", pid=37069)...
+------------------+
| SUMMARY OF TESTS |
Expand Down Expand Up @@ -163,8 +163,8 @@ Ran 1 test in 1.455s
OK
----------------------------------------
19:32:30 FINISHED scripts.run_e2e_tests_test.RunE2ETestsTests.test_is_oppia_server_already_running_when_ports_closed: 26.3 secs
Stopping Redis Server(name="redis-server", pid=37294)...
Stopping Cloud Datastore Emulator(name="python2.7", pid=37277)...
Stopping Redis Server(name="sh", pid=37294)...
Stopping Cloud Datastore Emulator(name="sh", pid=37277)...
+------------------+
| SUMMARY OF TESTS |
Expand Down Expand Up @@ -207,8 +207,8 @@ Traceback (most recent call last):
result.testsRun, len(result.errors), len(result.failures)))
Exception: Test suite failed: 1 tests run, 0 errors, 1 failures.
Stopping Redis Server(name="redis-server", pid=38032)...
Stopping Cloud Datastore Emulator(name="python2.7", pid=38015)...
Stopping Redis Server(name="sh", pid=38032)...
Stopping Cloud Datastore Emulator(name="sh", pid=38015)...
+------------------+
| SUMMARY OF TESTS |
Expand Down
4 changes: 1 addition & 3 deletions Installing-Oppia-(Linux;-Python-3).md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ Alternatively, if you are on Debian/Ubuntu, you can use the `install_prerequisit
bash scripts/install_prerequisites.sh
```

3. Make sure that you have **Python 2** installed, it is needed for the dev server to run. On Ubuntu 20 you can install it using `sudo apt install python2`. On Ubuntu 18 you can install it using `sudo apt install python-minimal`. If both of these commands do not work, try using `sudo apt install python2-minimal`.

4. Install Chrome from [Google's website](https://www.google.com/chrome). You'll need this to run tests.
3. Install Chrome from [Google's website](https://www.google.com/chrome). You'll need this to run tests.

## Clone Oppia

Expand Down
19 changes: 4 additions & 15 deletions Installing-Oppia-(Mac-OS;-Python-3).md
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,10 @@ For your vitual environment, we recommend you use [pyenv](https://github.com/pye
Installed Python-3.9.20 to /Users/user/.pyenv/versions/3.9.20
```
4. Install Python 2.7.18:
```console
$ pyenv install 2.7.18
...
Installed Python-2.7.18 to ~/.pyenv/versions/2.7.18
```
This is needed because App Engine's `dev_appserver.py` [requires Python 2.7 to be installed](https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command).
5. Make both Python 3 and Python 2 available globally on your system:
4. Make Python 3 available globally on your system:
```console
pyenv global 3.9.20 2.7.18
pyenv global 3.9.20
```
Note that you can use a different version of Python 3 if you prefer--we'll specify Python 3.9.20 as our version for Oppia development later.
Expand Down Expand Up @@ -297,11 +286,11 @@ For your vitual environment, we recommend you use [pyenv](https://github.com/pye
i hub: Stopping emulator hub
i logging: Stopping Logging Emulator
Stopping Web Browser(name="open", pid=29306)...
Stopping GAE Development Server(name="python2.7", pid=29289)...
Stopping GAE Development Server(name="sh", pid=29289)...
Stopping Webpack Compiler(name="node", pid=29234)...
Stopping Firebase Emulator(name="node", pid=29216)...
Stopping ElasticSearch Server(name="java", pid=29148)...
Stopping Redis Server(name="redis-server", pid=29147)...
Stopping Redis Server(name="sh", pid=29147)...
Done! Thank you for waiting.
Expand Down
2 changes: 1 addition & 1 deletion Overview-of-the-Oppia-codebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The domain models are defined in `*_domain.py` files under `core/domain/`.

### Storage layer

Finally, we have the storage layer, which defines the storage models. These are also classes, but they define how data is stored in whatever system we are using to store data to the file system. In production, we use the [Google Cloud Datastore](https://cloud.google.com/datastore), and we interface with it from Python using [Cloud NDB](https://googleapis.dev/python/python-ndb/latest/index.html). (Cloud NDB is for Python 3. For Python 2, we use App Engine NDB.)
Finally, we have the storage layer, which defines the storage models. These are also classes, but they define how data is stored in whatever system we are using to store data to the file system. In production, we use the [Google Cloud Datastore](https://cloud.google.com/datastore), and we interface with it from Python using [Cloud NDB](https://googleapis.dev/python/python-ndb/latest/index.html).

The storage models are defined in `core/storage`, while the code that handles interacting with the datastore is in `core/platform`. `core/platform/models.py` provides an interface to these storage models and the underlying datastore that dynamically loads the correct classes to interface with whatever datastore is currently in use. All the code in the controller, service, and domain layers should remain platform-agnostic by relying on the storage layer.

Expand Down
28 changes: 3 additions & 25 deletions Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Here are some general troubleshooting tips for Oppia. The platform specific tips
- [Push fails due to connection timeout](#push-fails-due-to-connection-timeout)
- [Exception: Error compiling proto files](#exception-error-compiling-proto-files)
- [Linux](#linux)
- [Python 2 is not available](#python-2-is-not-available)
- [OSError: \[Errno 2\] No such file or directory](#oserror-errno-2-no-such-file-or-directory)
- [Pip: Cannot Import Name Main](#pip-cannot-import-name-main)
- [ENOSPC: System Limit for Number of File Watchers Reached](#enospc-system-limit-for-number-of-file-watchers-reached)
Expand All @@ -37,7 +36,6 @@ Here are some general troubleshooting tips for Oppia. The platform specific tips
- [Subprocess.CalledProcessError: Command 'yarn install --pure-lockfile' returned non-zero exit status 1](#subprocesscalledprocesserror-command-yarn-install---pure-lockfile-returned-non-zero-exit-status-1)

- [Mac OS](#mac-os)
- [Python 2 is not available](#python-2-is-not-available-1)
- [Error: alert\_on\_exit() -\> Iterator\[None\]](#error-alert_on_exit---iteratornone)
- [Local datastore data are not being deleted](#local-datastore-data-are-not-being-deleted)
- [No module named '\_ctypes' on M1 Macs](#no-module-named-_ctypes-on-m1-macs)
Expand Down Expand Up @@ -313,16 +311,6 @@ Try searching for where protoc is installed (probably in `/opt/homebrew/bin/prot

## Linux

### Python 2 is not available

If you get error like this when running `python -m scripts.start`:

```
ERROR: (dev_appserver) python2: command not found
```

you will need to install Python 2 on your platform, even though Oppia doesn't use Python 2 anymore some parts of the App Engine dev server still need it. If you are on Ubuntu, you should be able to fix this using `sudo apt install python2`.

### OSError: [Errno 2] No such file or directory

If you get an error like this
Expand Down Expand Up @@ -443,16 +431,6 @@ npm install yarn
## Mac OS

### Python 2 is not available

If you get error like this when running `python -m scripts.start`:

```
ERROR: (dev_appserver) python2: command not found
```

you will need to install Python 2 on your platform, even though Oppia doesn't use Python 2 anymore some parts of the App Engine dev server still need it. If you have MacOS >= 12.3, please follow the steps listed [here](https://github.com/oppia/oppia/wiki/Installing-Oppia-(Mac-OS;-Python-3)#install-prerequisites) to install Python 2 on your system.

### Error: alert_on_exit() -> Iterator[None]

If after running python -m scripts.start, you get an error similar to this below:
Expand All @@ -471,7 +449,7 @@ Traceback (most recent call last):

Then,

1. Open your `.bash_profile` file, and check if there are two versions of Python listed inside of it, one for Python 2.7 and other for Python 3.8. Simply remove the entry for Python 2.7. Finally, this is how your file should look like:
1. Open your `.bash_profile` file, and check if there are two versions of Python listed inside of it, one for Python 2.7 and other for Python 3.9. Simply remove the entry for Python 2.7. Finally, this is how your file should look like:

```
export PYENV_ROOT="$HOME/.pyenv"
Expand All @@ -481,9 +459,9 @@ eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Setting PATH for Python 3.10
# Setting PATH for Python 3.9
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH
```

Expand Down

0 comments on commit 7c7abcf

Please sign in to comment.