Skip to content

Commit

Permalink
feat: use PEP 735 for devel deps
Browse files Browse the repository at this point in the history
Use PEP 735 dependency groups for development dependencies.
  • Loading branch information
nijel committed Nov 3, 2024
1 parent d43b645 commit 2430e2a
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ jobs:
- name: Prepare database
run: ./ci/prepare-database
- name: Migrate database
run: coverage run ./manage.py migrate --noinput --traceback
run: uv run ./manage.py migrate --noinput --traceback
- name: Generate OpenAPI
run: |
echo "::add-matcher::.github/matchers/spectacular.json"
./manage.py spectacular --urlconf="weblate.api.urls" > weblate-openapi.yaml
uv run ./manage.py spectacular --urlconf="weblate.api.urls" > weblate-openapi.yaml
echo "::remove-matcher owner=spectacular::"
- name: openapi-lint
run: npx @redocly/cli lint --format github-actions weblate-openapi.yaml
2 changes: 0 additions & 2 deletions .github/workflows/licenses-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ jobs:
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: uv pip install --system $(sed -n 's/.*"\(pre-commit==\([^"]*\)\)".*/\1/p' pyproject.toml)
- run: ./scripts/generate-license-data
- name: Update renovate branch
if: github.ref != 'refs/heads/main'
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: ./ci/pip-install mypy

- name: Run mypy
run: mypy --show-column-numbers weblate > mypy.log
run: uv run --group typing mypy --show-column-numbers weblate > mypy.log
# Temporary hack until we have this fully working
continue-on-error: true
- name: Report mypy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fi
- name: pre-commit
if: ${{ steps.pep735.outputs.found == 1 }}
run: uv run --only-group pre-commit pre-commit run --all
run: uv run --no-dev --only-group pre-commit pre-commit run --all
env:
RUFF_OUTPUT_FORMAT: github
REUSE_OUTPUT_FORMAT: github
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: uv pip install --system $(sed -n 's/.*"\(pylint==\([^"]*\)\)".*/\1/p' pyproject.toml)
- name: Add pylint annotator
uses: pr-annotators/[email protected]

- name: Run pylint
run: pylint weblate/
run: uv run --no-dev --only-group pylint pylint weblate/
10 changes: 3 additions & 7 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ jobs:
python-version: '3.12'
- name: Used versions
run: ./ci/print-versions
- name: Install Python dependencies
run: ./ci/pip-install
- name: Install setuptools
run: uv pip install --system $(sed -n 's/.*"\(setuptools[<>=]=\([^"]*\)\)".*/\1/p' pyproject.toml)
- name: Install Weblate
run: coverage run ./setup.py install
run: uv run coverage run ./setup.py install
- name: Check difference
run: diff -ruNqp weblate $(python -c 'import weblate; import os; print(os.path.dirname(weblate.__file__))')
- name: Coverage
run: |
coverage combine
coverage xml
uv run coverage combine
uv run coverage xml
- uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ jobs:
- name: Prepare database
run: ./ci/prepare-database
- name: Compile MO files
run: coverage run ./manage.py compilemessages
run: uv run coverage run ./manage.py compilemessages
- name: Collect static files
run: coverage run ./manage.py collectstatic --noinput --verbosity 0
run: uv run coverage run ./manage.py collectstatic --noinput --verbosity 0
- name: Migrate database
run: coverage run ./manage.py migrate --noinput --traceback
run: uv run coverage run ./manage.py migrate --noinput --traceback
- name: Django checks
run: coverage run ./manage.py check
run: uv run coverage run ./manage.py check
- name: Demo import
run: coverage run ./manage.py import_demo
run: uv run coverage run ./manage.py import_demo
- name: Test with Django
run: |
pytest --junitxml=junit.xml --cov=weblate weblate
uv run --all-extras pytest --junitxml=junit.xml --cov=weblate weblate
cp .coverage .coverage.pytest
- name: Test wsgi startup
env:
PYTHONPATH: .
run: coverage run weblate/wsgi.py
run: uv run coverage run weblate/wsgi.py
- name: Coverage
run: |
coverage combine
coverage xml
uv run coverage combine
uv run coverage xml
- uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ weblate-*.tar.*
/weblate/static/js/vendor/oss-licenses.json
*node_modules/
/weblate-openapi.yaml
uv.lock
2 changes: 1 addition & 1 deletion ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ check() {
}

run_coverage() {
python -m coverage run --source . --append "$@"
uv run --all-extras coverage run --source . --append "$@"
}

get_mysql_args() {
Expand Down
10 changes: 5 additions & 5 deletions ci/pip-install
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ if [ "${1:-latest}" = minimal ]; then
sed -i '/^ *"/ s/>=/==/' pyproject.toml
fi

if [ "${1:-latest}" = mypy ]; then
uv pip install --system -e ".[all,mysql,mypy,test]"
if [ "${1:-latest}" = typing ]; then
uv sync --all-extras --dev
else
# TODO: lxml can use wheels once xmlsec has one
# see https://github.com/xmlsec/python-xmlsec/issues/327
if python -c 'import sys; sys.exit(0 if sys.version_info >= (3,13) else 1)'; then
uv pip install --system --no-binary=lxml -e ".[all,mysql,test]"
uv sync --all-extras --dev --no-binary-package lxml
else
uv pip install --system -e ".[all,mysql,test]"
uv sync --all-extras --dev
fi
fi
if [ "${1:-latest}" = edge ]; then
uv pip install --system --upgrade -e ".[all,mysql,test]"
# Install from git / pre-release
. .venv/bin/activate
uv pip install --system --no-deps --upgrade --force-reinstall \
https://github.com/translate/translate/archive/master.zip \
https://github.com/WeblateOrg/language-data/archive/main.zip \
Expand Down
2 changes: 1 addition & 1 deletion ci/run-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ check
run_coverage ./manage.py migrate
check
# Check migrated vote exists
./manage.py shell -c 'from weblate.trans.models import Vote; Vote.objects.get(value=1)'
uv run --all-extras ./manage.py shell -c 'from weblate.trans.models import Vote; Vote.objects.get(value=1)'
check
83 changes: 47 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@ requires = [
"translate-toolkit"
]

[dependency-groups]
dev = [
"django-debug-toolbar==4.4.6",
"PyICU==2.14",
"reuse==4.0.3",
"scour==0.38.2",
"tinyunicodeblock==1.3",
"setuptools>=69.0.0",
{include-group = "lint"},
{include-group = "test"},
{include-group = "types"}
]
lint = [
{include-group = "pylint"},
{include-group = "pre-commit"}
]
pre-commit = [
"pre-commit==4.0.1"
]
pylint = [
"pylint==3.3.1"
]
test = [
"coverage==7.6.4",
"pytest==8.3.3",
"pytest-cov==6.0.0",
"pytest-django==4.9.0",
"responses==0.25.3",
"respx==0.21.1",
"selenium==4.26.1"
]
types = [
"boto3-stubs==1.35.54",
"celery-types==0.22.0",
"django-stubs-ext==5.1.1",
"django-stubs==5.1.1",
"djangorestframework-stubs==3.15.1",
"types-lxml==2024.9.16",
"mypy==1.13.0",
"types-dateparser==1.2.0.20240420",
"types-jsonschema==4.23.0.20240813",
"types-openpyxl==3.1.5.20241025",
"types-Pillow==10.2.0.20240822",
"types-python-dateutil==2.9.0.20241003",
"types-requests==2.32.0.20241016"
]

[project]
authors = [{name = "Michal Čihař", email = "[email protected]"}]
classifiers = [
Expand Down Expand Up @@ -116,14 +163,6 @@ amazon = [
antispam = [
"python-akismet>=0.4.2,<0.5"
]
dev = [
"weblate[all,test,lint,mypy]",
"django-debug-toolbar==4.4.6",
"PyICU==2.14",
"reuse==4.0.3",
"scour==0.38.2",
"tinyunicodeblock==1.3"
]
gerrit = [
"git-review>=2.4.0,<2.5.0"
]
Expand All @@ -133,28 +172,9 @@ google = [
ldap = [
"django-auth-ldap>=4.6.0,<6.0.0"
]
lint = [
"pre-commit==4.0.1",
"pylint==3.3.1"
]
mercurial = [
"mercurial>=6.8.0,<7.0"
]
mypy = [
"boto3-stubs==1.35.54",
"celery-types==0.22.0",
"django-stubs-ext==5.1.1",
"django-stubs==5.1.1",
"djangorestframework-stubs==3.15.1",
"types-lxml==2024.9.16",
"mypy==1.13.0",
"types-dateparser==1.2.0.20240420",
"types-jsonschema==4.23.0.20240813",
"types-openpyxl==3.1.5.20241025",
"types-Pillow==10.2.0.20240822",
"types-python-dateutil==2.9.0.20241003",
"types-requests==2.32.0.20241016"
]
mysql = [
"mysqlclient>=2.1.1,<3"
]
Expand All @@ -167,15 +187,6 @@ postgres = [
saml = [
"python3-saml>=1.2.1"
]
test = [
"coverage==7.6.4",
"pytest==8.3.3",
"pytest-cov==6.0.0",
"pytest-django==4.9.0",
"responses==0.25.3",
"respx==0.21.1",
"selenium==4.26.1"
]
zxcvbn = ["django-zxcvbn-password==2.1.1"]

[project.readme]
Expand Down
11 changes: 10 additions & 1 deletion scripts/generate-license-data
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ with open("weblate/utils/licensedata.py", "w") as output:

# Apply coding style
subprocess.run(
["pre-commit", "run", "--files", "weblate/utils/licensedata.py"],
[
"uv",
"run",
"--only-group",
"pre-commit",
"pre-commit",
"run",
"--files",
"weblate/utils/licensedata.py",
],
check=False,
)
14 changes: 13 additions & 1 deletion scripts/set-version
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ files = [
version_contributors.as_posix(),
]
subprocess.run(["git", "add", version_contributors.as_posix()], check=True)
subprocess.run(["pre-commit", "run", "--files", *files], check=False)
subprocess.run(
[
"uv",
"run",
"--only-group",
"pre-commit",
"pre-commit",
"run",
"--files",
*files,
],
check=False,
)
subprocess.run(
["git", "commit", "-m", f"chore: setting version to {version}", *files], check=True
)
2 changes: 1 addition & 1 deletion scripts/show-extras
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ with open("pyproject.toml", "rb") as handle:
toml_dict = tomllib.load(handle)

for section, data in toml_dict["project"]["optional-dependencies"].items():
if section in {"all", "ci", "dev", "lint", "mypy", "test"}:
if section == "all":
continue
dependency = re.split("[;<>=[]", data[0])[0].strip()
print(
Expand Down

0 comments on commit 2430e2a

Please sign in to comment.