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

Install Python Dev Dependencies to Virtual Environment #15602

Merged
merged 33 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f5a5dbe
Rename install_backend_python_libs.py
U8NWXD Jun 19, 2022
17ad8fe
Install python dev dependencies into venv
U8NWXD Jun 19, 2022
1f1b0ca
Add header and fix syntax
U8NWXD Jun 21, 2022
43197a8
Merge branch 'develop' into python-dev-deps-venv
U8NWXD Jun 21, 2022
faef94b
Make no venv ok on CI
U8NWXD Jun 22, 2022
9f95216
Fix lint, type issues
U8NWXD Jul 10, 2022
3cfa760
Add backend tests for install_python_dev_dependencies.py
U8NWXD Jul 10, 2022
81091d3
Remove PYTHONPATH editing for dev dependencies
U8NWXD Jul 11, 2022
07d1526
Fix lint errors
U8NWXD Jul 11, 2022
59ee71f
Fix mypy checks script
U8NWXD Jul 11, 2022
63eb483
Fix backend tests script
U8NWXD Jul 11, 2022
4dd03c6
Assert dev requirements file stays compiled
U8NWXD Jul 11, 2022
9fcd170
Add backend test to shards
U8NWXD Jul 11, 2022
8c25efb
Removed unused pip installation code
U8NWXD Jul 11, 2022
cb647c0
Fix backend tests
U8NWXD Jul 12, 2022
d3f1e1f
Fix more backend tests
U8NWXD Jul 12, 2022
3aebc2c
Fix lint checks
U8NWXD Jul 12, 2022
29139cb
Formatting fixes
U8NWXD Jul 14, 2022
aaa4375
Update testing self.swap for nonexistent attributes
U8NWXD Jul 15, 2022
69dd997
Make virtualenv check more rigorous
U8NWXD Jul 15, 2022
815ebe6
Merge branch 'develop' into python-dev-deps-venv
U8NWXD Jul 15, 2022
19daf7f
Fix requirements_dev.in comment
U8NWXD Jul 15, 2022
46234ca
Load-balance backend test shards
U8NWXD Jul 15, 2022
97216df
Merge branch 'develop' into python-dev-deps-venv
U8NWXD Jul 15, 2022
b54f7bd
Merge branch 'develop' into python-dev-deps-venv
U8NWXD Jul 19, 2022
fd0436f
Remove scripts/regenerate_requirements.py
U8NWXD Jul 19, 2022
d147a67
Address review comments
U8NWXD Jul 19, 2022
dff8c02
Fix backend tests
U8NWXD Jul 19, 2022
30ac5fc
Fix backend test
U8NWXD Jul 19, 2022
d6de237
Address review comments
U8NWXD Jul 20, 2022
cded151
Avoid modifying GenericTestBase.swap()
U8NWXD Jul 20, 2022
0125b7b
Clarify check_python_env name
U8NWXD Jul 20, 2022
af82499
Fix typo
U8NWXD Jul 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@
/core/domain/user*.py @seanlip
/requirements.txt @vojtechjelinek
/requirements.in @vojtechjelinek
/requirements_dev.txt @vojtechjelinek
/requirements_dev.in @vojtechjelinek
/dependencies.json @vojtechjelinek
/package.json @vojtechjelinek
/yarn.lock @vojtechjelinek
Expand Down
9 changes: 7 additions & 2 deletions core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,12 +1143,17 @@ def swap(self, obj, attr, newvalue):
the generator will immediately raise StopIteration, and contextlib will
raise a RuntimeError.
"""
original = getattr(obj, attr)
had_attribute = hasattr(obj, attr)
U8NWXD marked this conversation as resolved.
Show resolved Hide resolved
if had_attribute:
original = getattr(obj, attr)
setattr(obj, attr, newvalue)
try:
yield
finally:
setattr(obj, attr, original)
if had_attribute:
setattr(obj, attr, original)
else:
delattr(obj, attr)

@contextlib.contextmanager
def swap_to_always_return(self, obj, attr, value=None):
Expand Down
7 changes: 7 additions & 0 deletions core/tests/test_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ def test_capture_logging_with_min_level(self):

self.assertEqual(logs, ['3', '4'])

def test_swap_nonexistent_attribute(self):
obj = mock.Mock(spec=[])
self.assertFalse(hasattr(obj, 'test'))
with self.swap(obj, 'test', 'value'):
self.assertEqual(obj.test, 'value')
self.assertFalse(hasattr(obj, 'test'))

def test_swap_to_always_return_without_value_uses_none(self):
obj = mock.Mock()
obj.func = lambda: obj
Expand Down
15 changes: 4 additions & 11 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import os
import random
import re
import ssl
import string
import sys
import time
import unicodedata
import urllib.parse
Expand All @@ -38,21 +38,14 @@
from core import feconf
from core.constants import constants

import certifi
import yaml

from typing import ( # isort:skip
IO, Any, BinaryIO, Callable, Dict, Iterable, Iterator, List, Optional,
TextIO, Tuple, TypeVar, Union, overload)
from typing_extensions import Literal # isort:skip

_YAML_PATH = os.path.join(os.getcwd(), '..', 'oppia_tools', 'pyyaml-6.0')
sys.path.insert(0, _YAML_PATH)

_CERTIFI_PATH = os.path.join(
os.getcwd(), '..', 'oppia_tools', 'certifi-2021.10.8')
sys.path.insert(0, _CERTIFI_PATH)

import yaml # isort:skip # pylint: disable=wrong-import-position
import certifi # isort:skip pylint: disable=wrong-import-position, wrong-import-order
import ssl # isort:skip pylint: disable=wrong-import-position, wrong-import-order

DATETIME_FORMAT = '%m/%d/%Y, %H:%M:%S:%f'
ISO_8601_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fz'
Expand Down
22 changes: 22 additions & 0 deletions requirements_dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# NOTE TO DEVELOPERS: If you make changes to this file, please run
#
# python -m scripts.install_python_dev_dependencies
#
# to update `requirements_dev.txt` and your current Python environment.
Pillow==9.0.1
PyGithub==1.55
certifi==2021.10.8
coverage==6.1.2
esprima==4.0.1
future==0.18.2
grpcio==1.41.1
isort==5.10.1
protobuf==3.13.0
psutil==5.8.0
pycodestyle==2.8.0
pylint==2.11.1
git+https://github.com/oppia/pylint-quotes.git
pyyaml==6.0
six==1.16.0
typing-extensions==4.0.1
webtest==3.0.0
97 changes: 97 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# This file is autogenerated by pip-compile with python 3.7
# To update, run:
#
# pip-compile --output-file=requirements_dev.txt requirements_dev.in
#
astroid==2.8.6
# via pylint
beautifulsoup4==4.11.1
# via webtest
certifi==2021.10.8
# via
# -r requirements_dev.in
# requests
cffi==1.15.0
# via pynacl
charset-normalizer==2.0.12
# via requests
coverage==6.1.2
# via -r requirements_dev.in
deprecated==1.2.13
# via pygithub
esprima==4.0.1
# via -r requirements_dev.in
future==0.18.2
# via -r requirements_dev.in
grpcio==1.41.1
# via -r requirements_dev.in
idna==3.3
# via requests
isort==5.10.1
# via
# -r requirements_dev.in
# pylint
lazy-object-proxy==1.7.1
# via astroid
mccabe==0.6.1
# via pylint
pillow==9.0.1
# via -r requirements_dev.in
platformdirs==2.5.2
# via pylint
protobuf==3.13.0
# via -r requirements_dev.in
psutil==5.8.0
# via -r requirements_dev.in
pycodestyle==2.8.0
# via -r requirements_dev.in
pycparser==2.21
# via cffi
pygithub==1.55
# via -r requirements_dev.in
pyjwt==2.4.0
# via pygithub
pylint==2.11.1
# via
# -r requirements_dev.in
# pylint-quotes
pylint-quotes @ git+https://github.com/oppia/pylint-quotes.git
# via -r requirements_dev.in
pynacl==1.5.0
# via pygithub
pyyaml==6.0
# via -r requirements_dev.in
requests==2.27.1
# via pygithub
six==1.16.0
# via
# -r requirements_dev.in
# grpcio
# protobuf
soupsieve==2.3.2.post1
# via beautifulsoup4
toml==0.10.2
# via pylint
typed-ast==1.5.4
# via astroid
typing-extensions==4.0.1
# via
# -r requirements_dev.in
# astroid
# pylint
urllib3==1.26.9
# via requests
waitress==2.1.1
# via webtest
webob==1.8.7
# via webtest
webtest==3.0.0
# via -r requirements_dev.in
wrapt==1.13.3
# via
# astroid
# deprecated

# The following packages are considered to be unsafe in a requirements file:
# setuptools
3 changes: 2 additions & 1 deletion scripts/backend_test_shards.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"scripts.linters.linter_utils_test",
"scripts.linters.python_linter_test",
"core.platform.auth.firebase_auth_services_test",
"scripts.install_backend_python_libs_test",
"scripts.install_python_prod_dependencies_test",
"scripts.install_python_dev_dependencies_test",
"scripts.common_test",
"core.controllers.beam_jobs_test",
"core.controllers.contributor_dashboard_admin_test",
Expand Down
2 changes: 1 addition & 1 deletion scripts/backend_tests_incomplete_coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ core.domain.auth_services_test
core.domain.opportunity_services_test
core.domain.feedback_domain_test
core.domain.blog_domain_test
scripts.install_backend_python_libs_test
scripts.install_python_prod_dependencies_test
core.domain.subtopic_page_domain_test
core.storage.skill.gae_models_test
core.storage.topic.gae_models_test
Expand Down
39 changes: 3 additions & 36 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@

CURRENT_PYTHON_BIN = sys.executable

# Versions of libraries used in devflow.
COVERAGE_VERSION = '6.1.2'
ESPRIMA_VERSION = '4.0.1'
ISORT_VERSION = '5.10.1'
PYCODESTYLE_VERSION = '2.8.0'
PSUTIL_VERSION = '5.8.0'
PYLINT_VERSION = '2.11.1'
PYLINT_QUOTES_VERSION = '0.2.4'
PYGITHUB_VERSION = '1.55'
WEBTEST_VERSION = '3.0.0'
PIP_TOOLS_VERSION = '6.6.2'
GRPCIO_VERSION = '1.41.1'
PROTOBUF_VERSION = '3.13.0'
SETUPTOOLS_VERSION = '58.5.3'

# Node version.
NODE_VERSION = '16.13.0'

Expand All @@ -70,9 +55,9 @@

# Buf version.
BUF_VERSION = '0.29.0'
# Protoc is the compiler for protobuf files and the version must be same as
# the version of protobuf library being used.
PROTOC_VERSION = PROTOBUF_VERSION

# Must match the version of protobuf in requirements_dev.in.
U8NWXD marked this conversation as resolved.
Show resolved Hide resolved
PROTOC_VERSION = '3.13.0'

# IMPORTANT STEPS FOR DEVELOPERS TO UPGRADE REDIS:
# 1. Download the new version of the redis cli.
Expand Down Expand Up @@ -103,28 +88,19 @@
GOOGLE_APP_ENGINE_SDK_HOME = os.path.join(
GOOGLE_CLOUD_SDK_HOME, 'platform', 'google_appengine')
GOOGLE_CLOUD_SDK_BIN = os.path.join(GOOGLE_CLOUD_SDK_HOME, 'bin')
ISORT_PATH = os.path.join(OPPIA_TOOLS_DIR, 'isort-%s' % ISORT_VERSION)
WEBPACK_BIN_PATH = (
os.path.join(CURR_DIR, 'node_modules', 'webpack', 'bin', 'webpack.js'))
DEV_APPSERVER_PATH = (
os.path.join(GOOGLE_CLOUD_SDK_BIN, 'dev_appserver.py'))
GCLOUD_PATH = os.path.join(GOOGLE_CLOUD_SDK_BIN, 'gcloud')
NODE_PATH = os.path.join(OPPIA_TOOLS_DIR, 'node-%s' % NODE_VERSION)
PYLINT_PATH = os.path.join(OPPIA_TOOLS_DIR, 'pylint-%s' % PYLINT_VERSION)
PYCODESTYLE_PATH = os.path.join(
OPPIA_TOOLS_DIR, 'pycodestyle-%s' % PYCODESTYLE_VERSION)
PYLINT_QUOTES_PATH = os.path.join(
OPPIA_TOOLS_DIR, 'pylint-quotes-%s' % PYLINT_QUOTES_VERSION)
PY_GITHUB_PATH = os.path.join(
OPPIA_TOOLS_DIR, 'PyGithub-%s' % PYGITHUB_VERSION)
NODE_MODULES_PATH = os.path.join(CURR_DIR, 'node_modules')
FRONTEND_DIR = os.path.join(CURR_DIR, 'core', 'templates')
YARN_PATH = os.path.join(OPPIA_TOOLS_DIR, 'yarn-%s' % YARN_VERSION)
FIREBASE_PATH = os.path.join(
NODE_MODULES_PATH, 'firebase-tools', 'lib', 'bin', 'firebase.js')
OS_NAME = platform.system()
ARCHITECTURE = platform.machine()
PSUTIL_DIR = os.path.join(OPPIA_TOOLS_DIR, 'psutil-%s' % PSUTIL_VERSION)
REDIS_SERVER_PATH = os.path.join(
OPPIA_TOOLS_DIR, 'redis-cli-%s' % REDIS_CLI_VERSION,
'src', 'redis-server')
Expand All @@ -138,7 +114,6 @@
FIREBASE_EMULATOR_CACHE_DIR = (
os.path.join(CURR_DIR, os.pardir, 'firebase_emulator_cache'))

sys.path.insert(0, PY_GITHUB_PATH)
# By specifying this condition, we are importing the below module only while
# type checking, not in runtime.
MYPY = False
Expand Down Expand Up @@ -206,15 +181,7 @@

DIRS_TO_ADD_TO_SYS_PATH = [
GOOGLE_APP_ENGINE_SDK_HOME,
PYLINT_PATH,
os.path.join(OPPIA_TOOLS_DIR, 'webtest-%s' % WEBTEST_VERSION),
os.path.join(OPPIA_TOOLS_DIR, 'Pillow-%s' % PILLOW_VERSION),
os.path.join(OPPIA_TOOLS_DIR, 'protobuf-%s' % PROTOBUF_VERSION),
PSUTIL_DIR,
os.path.join(CURR_DIR, 'proto_files'),
os.path.join(OPPIA_TOOLS_DIR, 'grpcio-%s' % GRPCIO_VERSION),
os.path.join(OPPIA_TOOLS_DIR, 'setuptools-%s' % '36.6.0'),
PY_GITHUB_PATH,
CURR_DIR,
THIRD_PARTY_PYTHON_LIBS_DIR,
]
Expand Down