Skip to content

Commit 14700d2

Browse files
authored
Merge pull request #136 from salman2013/modernize-python-tooling
Modernize python tooling
2 parents 899bc7b + 170b8e5 commit 14700d2

33 files changed

Lines changed: 600 additions & 455 deletions

.github/workflows/ci.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
name: Python CI
22

33
on:
4-
push:
5-
branches:
6-
- master
74
pull_request:
85
branches:
96
- '**'
7+
workflow_call:
108

119
jobs:
1210
run_tests:
13-
name: Tests
14-
runs-on: ${{ matrix.os }}
11+
name: quality
12+
runs-on: ubuntu-latest
1513
strategy:
1614
matrix:
17-
os:
18-
- ubuntu-latest
1915
python-version: ['3.12']
16+
permissions:
17+
contents: read
2018
steps:
2119
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22-
- name: setup python
23-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
20+
- name: Setup uv
21+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
2422
with:
25-
python-version: ${{ matrix.python-version }}
26-
architecture: x64
23+
enable-cache: true
24+
python-version: "${{ matrix.python-version }}"
2725

28-
- name: Install dependencies
29-
run: pip install -r requirements/ci.txt
26+
- name: Install quality dependencies
27+
run: uv sync --group quality
3028

31-
- name: Run Tests
32-
run: pycodestyle . --max-line-length=419 # TODO 419 --> 120
29+
- name: Run quality checks
30+
run: uv run pycodestyle . --max-line-length=419 --exclude=.venv

.github/workflows/pypi-publish.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Semantic Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
run_tests:
10+
uses: ./.github/workflows/ci.yml
11+
secrets: inherit
12+
permissions:
13+
contents: read
14+
15+
release:
16+
needs: run_tests
17+
if: github.ref_name == 'master'
18+
runs-on: ubuntu-latest
19+
concurrency:
20+
group: ${{ github.workflow }}-release
21+
cancel-in-progress: false
22+
23+
permissions:
24+
contents: write
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
29+
with:
30+
ref: ${{ github.ref_name }}
31+
32+
- name: Reset to triggered commit
33+
run: git reset --hard ${{ github.sha }}
34+
35+
- name: Python Semantic Release
36+
id: release
37+
uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3
38+
with:
39+
git_committer_name: "github-actions[bot]"
40+
git_committer_email: "github-actions[bot]@users.noreply.github.com"
41+
changelog: "false"
42+
43+
- name: Upload dist artifacts
44+
if: steps.release.outputs.released == 'true'
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: dist
48+
path: dist/
49+
50+
outputs:
51+
released: ${{ steps.release.outputs.released }}
52+
version: ${{ steps.release.outputs.version }}
53+
54+
publish_to_pypi:
55+
needs: release
56+
if: needs.release.outputs.released == 'true'
57+
runs-on: ubuntu-latest
58+
59+
permissions:
60+
contents: read
61+
id-token: write
62+
63+
steps:
64+
- name: Download dist artifacts
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: dist
68+
path: dist/
69+
70+
- name: Publish to PyPI
71+
uses: pypa/gh-action-pypi-publish@release/v1

Makefile

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
WORKING_DIR := recommender
1+
WORKING_DIR := src/recommender
22
JS_TARGET := $(WORKING_DIR)/public/js/translations
33

4-
COMMON_CONSTRAINTS_TXT=requirements/common_constraints.txt
5-
.PHONY: $(COMMON_CONSTRAINTS_TXT)
6-
$(COMMON_CONSTRAINTS_TXT):
7-
wget -O "$(@)" https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt || touch "$(@)"
8-
9-
upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
10-
upgrade: $(COMMON_CONSTRAINTS_TXT) ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
11-
pip install -r requirements/pip.txt
12-
pip install -q -r requirements/pip_tools.txt
13-
pip-compile --upgrade --allow-unsafe --rebuild -o requirements/pip.txt requirements/pip.in
14-
pip-compile --upgrade -o requirements/pip_tools.txt requirements/pip_tools.in
15-
pip install -qr requirements/pip.txt
16-
pip install -qr requirements/pip_tools.txt
17-
pip-compile --upgrade -o requirements/base.txt requirements/base.in
18-
pip-compile --upgrade -o requirements/test.txt requirements/test.in
19-
pip-compile --upgrade -o requirements/ci.txt requirements/ci.in
4+
upgrade: ## update uv.lock with the latest packages
5+
uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml
6+
uv lock --upgrade
207

218
extract_translations: ## extract strings to be translated, outputting .po files
229
cd $(WORKING_DIR) && i18n_tool extract --no-segment --merge-po-files

pyproject.toml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "setuptools-scm>=8.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "recommender-xblock"
7+
dynamic = ["version"]
8+
description = "recommender XBlock"
9+
readme = "README.rst"
10+
license = "AGPL-3.0"
11+
license-files = ["LICENSE"]
12+
authors = [
13+
{name = "edX", email = "oscm@edx.org"},
14+
]
15+
requires-python = ">=3.12"
16+
classifiers = [
17+
"Development Status :: 4 - Beta",
18+
"Intended Audience :: Developers",
19+
"Natural Language :: English",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.12",
22+
"Framework :: Django",
23+
"Framework :: Django :: 4.2",
24+
"Framework :: Django :: 5.2",
25+
]
26+
dependencies = [
27+
"bleach",
28+
"edx-i18n-tools",
29+
"fs",
30+
"simplejson",
31+
"web-fragments",
32+
"webob",
33+
]
34+
35+
[project.urls]
36+
Homepage = "https://github.com/openedx/RecommenderXBlock"
37+
38+
[project.entry-points."xblock.v1"]
39+
recommender = "recommender.recommender:RecommenderXBlock"
40+
41+
[tool.setuptools_scm]
42+
version_scheme = "only-version"
43+
local_scheme = "no-local-version"
44+
45+
[tool.setuptools.packages.find]
46+
where = ["src"]
47+
48+
[tool.setuptools.package-data]
49+
recommender = [
50+
"static/**/*",
51+
"templates/**/*",
52+
"conf/locale/**",
53+
"public/**/*",
54+
]
55+
56+
[tool.setuptools.exclude-package-data]
57+
"*" = ["tests*", "*.tests*", "spec*", "*.spec*"]
58+
59+
[tool.coverage.run]
60+
branch = true
61+
source = ["recommender"]
62+
omit = [
63+
"*/tests/*",
64+
"*/migrations/*",
65+
"*/__pycache__/*",
66+
"*/settings.py",
67+
]
68+
69+
[tool.coverage.report]
70+
show_missing = true
71+
exclude_lines = [
72+
"pragma: no cover",
73+
"def __repr__",
74+
"raise AssertionError",
75+
"raise NotImplementedError",
76+
"if __name__ == .__main__.:",
77+
"if TYPE_CHECKING:",
78+
]
79+
80+
[tool.coverage.html]
81+
directory = "htmlcov"
82+
83+
[dependency-groups]
84+
quality = [
85+
"pycodestyle",
86+
]
87+
88+
[tool.edx_lint]
89+
uv_constraints = []
90+
91+
[tool.semantic_release]
92+
build_command = "python -m pip install --upgrade build && SETUPTOOLS_SCM_PRETEND_VERSION=$NEW_VERSION python -m build"
93+
allow_zero_version = true
94+
major_on_zero = false
95+
96+
[tool.uv]
97+
package = true

requirements/base.in

Lines changed: 0 additions & 10 deletions
This file was deleted.

requirements/base.txt

Lines changed: 0 additions & 47 deletions
This file was deleted.

requirements/ci.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)