Skip to content

Commit

Permalink
Merge pull request #109 from open-craft/agrendalath/maintenance
Browse files Browse the repository at this point in the history
refactor: repo maintenance
  • Loading branch information
Agrendalath authored Jan 18, 2024
2 parents c930c52 + 9ff18b2 commit d083b8c
Show file tree
Hide file tree
Showing 32 changed files with 882 additions and 139 deletions.
53 changes: 19 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,41 @@ name: Python CI

on:
push:
branches:
- master
branches: [ master ]
pull_request:
branches:
- '**'
workflow_dispatch:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
run_tests:
name: Tests
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
python-version: [3.8]
toxenv: [ quality, unit, integration ]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
toxenv: [django32, django42, quality, package]

- name: Install Required System Packages
if: matrix.toxenv == 'integration'
run: sudo apt-get update && sudo apt-get install libxmlsec1-dev ubuntu-restricted-extras xvfb

- name: Use Gecko Driver
if: matrix.toxenv == 'integration'
uses: browser-actions/setup-geckodriver@latest
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
submodules: recursive

- name: setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install -U pip wheel
pip install tox pylint
- name: Install Dependencies
run: make requirements

- name: Run Quality
env:
TOXENV: ${{ matrix.toxenv }}
if: matrix.toxenv == 'quality'
run: |
tox -e quality
- name: Run Unit Tests
env:
TOXENV: ${{ matrix.toxenv }}
if: matrix.toxenv == 'unit'
run: tox -e unit
- name: Run Integration Tests
- name: Run Tests
env:
TOXENV: ${{ matrix.toxenv }}
if: matrix.toxenv == 'integration'
run: xvfb-run --auto-servernum tox -e integration
run: tox
30 changes: 30 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish package to PyPI

on:
release:
types: [published]

jobs:
push:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: setup python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Dependencies
run: pip install -r requirements/pip.txt

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/upgrade-python-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Upgrade Python Requirements

on:
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
inputs:
branch:
description: Target branch against which to create requirements PR
required: true
default: master

jobs:
call-upgrade-python-requirements-workflow:
uses: openedx/.github/.github/workflows/upgrade-python-requirements.yml@master
# Do not run on forks
if: github.repository_owner == 'openedx'
with:
branch: ${{ github.event.inputs.branch || 'master' }}
# optional parameters below; fill in if you'd like github or email notifications
# user_reviewers: ""
# team_reviewers: ""
# email_address: ""
# send_success_notification: false
secrets:
requirements_bot_github_token: ${{ secrets.REQUIREMENTS_BOT_GITHUB_TOKEN }}
requirements_bot_github_email: ${{ secrets.REQUIREMENTS_BOT_GITHUB_EMAIL }}
edx_smtp_username: ${{ secrets.EDX_SMTP_USERNAME }}
edx_smtp_password: ${{ secrets.EDX_SMTP_PASSWORD }}
74 changes: 69 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
xblock_image_explorer.egg-info
*.pyc
*~
var/workbench.log*
geckodriver.log
*.py[cod]
__pycache__

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
env
venv
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.cache/
.coverage
.coverage.*
.pytest_cache
.tox
coverage.xml
htmlcov/
diff-cover.html
pii_report

# Translations
*.mo

# IDEs and text editors
*~
*.swp
.idea/
.project
.pycharm_helpers/
.pydevproject

# The Silver Searcher
.agignore

# OS X artifacts
*.DS_Store

# Logging
log/
logs/
chromedriver.log
ghostdriver.log

# Complexity
output/*.html
output/*/index.html

# Sphinx
docs/_build

# Cookiecutter
output/
dj-package/
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE
include README.md
include requirements/base.in
include requirements/constraints.txt
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ clean: ## remove generated byte code, coverage reports, and build artifacts
rm -fr dist/
rm -fr *.egg-info

piptools: ## install pinned version of pip-compile and pip-sync
pip install -r requirements/pip.txt
pip install -r requirements/pip-tools.txt

requirements: piptools ## install test requirements locally
pip-sync requirements/ci.txt

requirements_python: piptools ## install all requirements locally
pip-sync requirements/base.txt requirements/ci.txt requirements/test.txt requirements/private.*

# Define PIP_COMPILE_OPTS=-v to get more information during make upgrade.
PIP_COMPILE = pip-compile --upgrade $(PIP_COMPILE_OPTS)

upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -qr requirements/pip-tools.txt
# Make sure to compile files after any other files they include!
$(PIP_COMPILE) --allow-unsafe -o requirements/pip.txt requirements/pip.in
$(PIP_COMPILE) -o requirements/pip-tools.txt requirements/pip-tools.in
pip install -qr requirements/pip.txt
pip install -qr requirements/pip-tools.txt
$(PIP_COMPILE) -o requirements/base.txt requirements/base.in
$(PIP_COMPILE) -o requirements/test.txt requirements/test.in
$(PIP_COMPILE) -o requirements/ci.txt requirements/ci.in
sed -i '/^[dD]jango==/d' requirements/test.txt

## Localization targets

extract_translations: ## extract strings to be translated, outputting .po files
Expand Down Expand Up @@ -49,7 +75,7 @@ build_dummy_translations: dummy_translations compile_translations ## generate an
validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations

pull_translations: ## pull translations from transifex
cd $(WORKING_DIR) && i18n_tool transifex pull
tx pull -t -a -f --mode reviewed --minimum-perc=1

push_translations: ## push translations to transifex
cd $(WORKING_DIR) && i18n_tool transifex push
tx push -s
30 changes: 30 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file records information about this repo. Its use is described in OEP-55:
# https://open-edx-proposals.readthedocs.io/en/latest/processes/oep-0055-proc-project-maintainers.html

apiVersion: backstage.io/v1alpha1
# (Required) Acceptable Values: Component, Resource, System
# A repo will almost certainly be a Component.
kind: Component
metadata:
name: xblock-image-explorer
description: This XBlock allows you to use an image with hotspots in a course. When the student clicks a hotspot icon, a tooltip containing custom content is displayed.
annotations:
# (Optional) Annotation keys and values can be whatever you want.
# We use it in Open edX repos to have a comma-separated list of GitHub user
# names that might be interested in changes to the architecture of this
# component.
openedx.org/component-type: XBlock
openedx.org/arch-interest-groups: ''
spec:

# (Required) This can be a group (`group:<github_group_name>`) or a user (`user:<github_username>`).
# Don't forget the "user:" or "group:" prefix. Groups must be GitHub team
# names in the openedx GitHub organization: https://github.com/orgs/openedx/teams

owner: user:Agrendalath

# (Required) Acceptable Type Values: service, website, library
type: library

# (Required) Acceptable Lifecycle Values: experimental, production, deprecated
lifecycle: production
4 changes: 2 additions & 2 deletions image_explorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"""
Image Explorer XBlock
"""
from __future__ import absolute_import

from .image_explorer import ImageExplorerBlock

__version__ = '2.2.0'
25 changes: 12 additions & 13 deletions image_explorer/image_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import uuid
import logging
import textwrap
from io import StringIO
from urllib.parse import urljoin
import pkg_resources
from six.moves import urllib
from six import StringIO
from parsel import Selector
from lxml import etree, html

from django.conf import settings

from lxml import etree, html
from parsel import Selector
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock
from xblock.fragment import Fragment
Expand All @@ -44,11 +43,11 @@
from .utils import loader, AttrDict, _


log = logging.getLogger(__name__) # pylint: disable=invalid-name
log = logging.getLogger(__name__)


@XBlock.needs('i18n')
class ImageExplorerBlock(XBlock): # pylint: disable=no-init
class ImageExplorerBlock(XBlock):
"""
XBlock that renders an image with tooltips
"""
Expand Down Expand Up @@ -114,7 +113,7 @@ class ImageExplorerBlock(XBlock): # pylint: disable=no-init
</image_explorer>
"""))

def max_score(self): # pylint: disable=no-self-use
def max_score(self):
"""
Returns the maximum score that can be achieved (always 1.0 on this XBlock)
"""
Expand Down Expand Up @@ -254,15 +253,15 @@ def register_progress(self, hotspot_id):

self.runtime.publish(self, 'progress', {})
self.opened_hotspots.append(hotspot_id)
log.debug(u'Opened hotspots so far for %s: %s', self._get_unique_id(), self.opened_hotspots)
log.debug('Opened hotspots so far for %s: %s', self._get_unique_id(), self.opened_hotspots)

opened_hotspots = [h for h in hotspots_ids if h in self.opened_hotspots]
percent_completion = float(len(opened_hotspots)) / len(hotspots_ids)
self.runtime.publish(self, 'grade', {
'value': percent_completion,
'max_value': 1,
})
log.debug(u'Sending grade for %s: %s', self._get_unique_id(), percent_completion)
log.debug('Sending grade for %s: %s', self._get_unique_id(), percent_completion)

def _get_unique_id(self):
try:
Expand Down Expand Up @@ -304,7 +303,7 @@ def studio_submit(self, submissions, suffix=''):
# Python 2 and 3 compatibility fix
# Switch to _, error_message = e.args
try:
error_message = err.message # pylint: disable=exception-message-attribute
error_message = err.message
except: # pylint: disable=bare-except
_, error_message = err.args

Expand Down Expand Up @@ -347,7 +346,7 @@ def _make_url_absolute(url):
lms_base = settings.ENV_TOKENS.get('LMS_BASE')
scheme = 'https' if settings.HTTPS == 'on' else 'http'
lms_base = '{}://{}'.format(scheme, lms_base)
return urllib.parse.urljoin(lms_base, url)
return urljoin(lms_base, url)

def _inner_content(self, tag, absolute_urls=False):
"""
Expand Down Expand Up @@ -464,7 +463,7 @@ def workbench_scenarios():
"""A canned scenario for display in the workbench."""
return [("Image explorer scenario", "<vertical_demo><image-explorer/></vertical_demo>")]

def resource_string(self, path): # pylint: disable=no-self-use
def resource_string(self, path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
2 changes: 1 addition & 1 deletion image_explorer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ class AttrDict(dict):
Attribute Dictionary for storing properties
"""
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.__dict__ = self
Loading

0 comments on commit d083b8c

Please sign in to comment.