Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Overhang.IO committed Nov 24, 2023
2 parents 1d1a336 + e701ab9 commit a7ad233
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 41 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests

on:
pull_request:
branches: [master]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Upgrade pip
run: python -m pip install --upgrade pip setuptools
- name: Install dependencies
run: |
pip install 'tutor[dev]>=16.0.0,<17.0.0' \
'tutor-mfe>=16.0.0, <17.0.0'
- name: Test lint, types, and format
run: make test
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.DEFAULT_GOAL := help
.PHONY: docs
SRC_DIRS = ./tutorecommerce
BLACK_OPTS = --exclude templates ${SRC_DIRS}

# Warning: These checks are not necessarily run on every PR.
test: test-lint test-types test-format # Run some static checks.

test-format: ## Run code formatting tests
black --check --diff $(BLACK_OPTS)

test-lint: ## Run code linting tests
pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${SRC_DIRS}

test-types: ## Run type checks.
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}

format: ## Format code automatically
black $(BLACK_OPTS)

isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
isort --skip=templates ${SRC_DIRS}

changelog-entry: ## Create a new changelog entry.
scriv create

changelog: ## Collect changelog entries in the CHANGELOG.md file.
scriv collect

ESCAPE = 
help: ## Print this help
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
| sed 's/######* \(.*\)/@ $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' | tr '@' '\n' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Rebuild the "ecommerce" Docker image::

tutor images build ecommerce

Lauch your platform again::
Launch your platform again::

tutor dev launch

Expand Down
1 change: 1 addition & 0 deletions changelog.d/20231118_174413_codewithemad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Improvement] Added Typing to code, Makefile and test action to the repository and formatted code with Black and isort. (by @CodeWithEmad)
1 change: 0 additions & 1 deletion tutorecommerce/__about__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = "16.0.0"

91 changes: 52 additions & 39 deletions tutorecommerce/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from glob import glob
import os
import typing as t
from glob import glob

import pkg_resources

from tutor import hooks as tutor_hooks
from tutor.__about__ import __version_suffix__
from tutormfe.hooks import MFE_APPS, MFE_ATTRS_TYPE
Expand All @@ -17,35 +16,6 @@
__version__ += "-" + __version_suffix__

config = {
"unique": {
"MYSQL_PASSWORD": "{{ 8|random_string }}",
"SECRET_KEY": "{{ 20|random_string }}",
"OAUTH2_SECRET": "{{ 8|random_string }}",
"OAUTH2_SECRET_SSO": "{{ 8|random_string }}",
"API_KEY": "{{ 20|random_string }}",
"PAYMENT_PROCESSORS": {
"cybersource": {
"flex_shared_secret_key_id": "SET-ME-PLEASE",
"flex_shared_secret_key": "SET-ME-PLEASE",
"merchant_id": "SET-ME-PLEASE",
"soap_api_url": "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.140.wsdl",
"transaction_key": "SET-ME-PLEASE",
},
"paypal": {
"mode": "sandbox",
"client_id": "SET-ME-PLEASE",
"client_secret": "SET-ME-PLEASE",
"cancel_checkout_path": "/checkout/cancel-checkout/",
"error_url": "/checkout/error/",
"receipt_url": "/checkout/receipt/",
},
},
"ENABLE_IDENTITY_VERIFICATION": True,
"ENABLED_PAYMENT_PROCESSORS": ["cybersource", "paypal"],
"ENABLED_CLIENT_SIDE_PAYMENT_PROCESSORS": ["cybersource"],
"EXTRA_PAYMENT_PROCESSOR_CLASSES": [],
"EXTRA_PAYMENT_PROCESSOR_URLS": {},
},
"defaults": {
"VERSION": __version__,
"API_TIMEOUT": 5,
Expand Down Expand Up @@ -85,11 +55,42 @@
},
},
},
"unique": {
"MYSQL_PASSWORD": "{{ 8|random_string }}",
"SECRET_KEY": "{{ 20|random_string }}",
"OAUTH2_SECRET": "{{ 8|random_string }}",
"OAUTH2_SECRET_SSO": "{{ 8|random_string }}",
"API_KEY": "{{ 20|random_string }}",
"PAYMENT_PROCESSORS": {
"cybersource": {
"flex_shared_secret_key_id": "SET-ME-PLEASE",
"flex_shared_secret_key": "SET-ME-PLEASE",
"merchant_id": "SET-ME-PLEASE",
"soap_api_url": "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.140.wsdl",
"transaction_key": "SET-ME-PLEASE",
},
"paypal": {
"mode": "sandbox",
"client_id": "SET-ME-PLEASE",
"client_secret": "SET-ME-PLEASE",
"cancel_checkout_path": "/checkout/cancel-checkout/",
"error_url": "/checkout/error/",
"receipt_url": "/checkout/receipt/",
},
},
"ENABLE_IDENTITY_VERIFICATION": True,
"ENABLED_PAYMENT_PROCESSORS": ["cybersource", "paypal"],
"ENABLED_CLIENT_SIDE_PAYMENT_PROCESSORS": ["cybersource"],
"EXTRA_PAYMENT_PROCESSOR_CLASSES": [],
"EXTRA_PAYMENT_PROCESSOR_URLS": {},
},
}


@MFE_APPS.add()
def _add_ecommerce_mfe_apps(apps: dict[str, MFE_ATTRS_TYPE]) -> dict[str, MFE_ATTRS_TYPE]:
@MFE_APPS.add() # type: ignore
def _add_ecommerce_mfe_apps(
apps: dict[str, MFE_ATTRS_TYPE]
) -> dict[str, MFE_ATTRS_TYPE]:
apps.update(
{
"orders": {
Expand Down Expand Up @@ -176,7 +177,9 @@ def _add_ecommerce_mfe_apps(apps: dict[str, MFE_ATTRS_TYPE]) -> dict[str, MFE_AT

####### Boilerplate code
# Add the "templates" folder as a template root
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(pkg_resources.resource_filename("tutorecommerce", "templates"))
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorecommerce", "templates")
)
# Render the "build" and "apps" folders
tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
[
Expand All @@ -192,19 +195,25 @@ def _add_ecommerce_mfe_apps(apps: dict[str, MFE_ATTRS_TYPE]) -> dict[str, MFE_AT
)
):
with open(path, encoding="utf-8") as patch_file:
tutor_hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))
tutor_hooks.Filters.ENV_PATCHES.add_item(
(os.path.basename(path), patch_file.read())
)
# Add configuration entries
tutor_hooks.Filters.CONFIG_DEFAULTS.add_items(
[(f"ECOMMERCE_{key}", value) for key, value in config.get("defaults", {}).items()]
)
tutor_hooks.Filters.CONFIG_UNIQUE.add_items(
[(f"ECOMMERCE_{key}", value) for key, value in config.get("unique", {}).items()]
)
tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(list(config.get("overrides", {}).items()))
tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(
list(config.get("overrides", {}).items())
)


@tutor_hooks.Filters.APP_PUBLIC_HOSTS.add()
def _print_ecommerce_public_hosts(hosts: list[str], context_name: t.Literal["local", "dev"]) -> list[str]:
def _print_ecommerce_public_hosts(
hosts: list[str], context_name: t.Literal["local", "dev"]
) -> list[str]:
if context_name == "dev":
hosts += ["{{ ECOMMERCE_HOST }}:8130"]
else:
Expand All @@ -214,7 +223,9 @@ def _print_ecommerce_public_hosts(hosts: list[str], context_name: t.Literal["loc

# Automount /openedx/ecommerce folder from the container
@tutor_hooks.Filters.COMPOSE_MOUNTS.add()
def _mount_ecommerce_apps(mounts, path_basename):
def _mount_ecommerce_apps(
mounts: list[tuple[str, str]], path_basename: str
) -> list[tuple[str, str]]:
if path_basename == "ecommerce":
mounts += [("ecommerce", "/openedx/ecommerce")]
elif path_basename == "frontend-app-ecommerce":
Expand All @@ -227,7 +238,9 @@ def _mount_ecommerce_apps(mounts, path_basename):

# Bind-mount repo at build-time, both for prod and dev images
@tutor_hooks.Filters.IMAGES_BUILD_MOUNTS.add()
def _mount_ecommerce_on_build(mounts: list[tuple[str, str]], host_path: str) -> list[tuple[str, str]]:
def _mount_ecommerce_on_build(
mounts: list[tuple[str, str]], host_path: str
) -> list[tuple[str, str]]:
path_basename = os.path.basename(host_path)
if path_basename == "ecommerce":
mounts.append(("ecommerce", "ecommerce-src"))
Expand Down

0 comments on commit a7ad233

Please sign in to comment.