Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .git-blame-ignore-revs

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Ruff

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
src: "./oioioi"
version: 0.11.12
18 changes: 0 additions & 18 deletions .pep8rc

This file was deleted.

8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
hooks:
- id: ruff-check
files: ^oioioi/
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
138 changes: 0 additions & 138 deletions .pylintrc

This file was deleted.

3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ RUN rm /bin/sh && ln -s /bin/bash /bin/sh && \
RUN sed -i -e "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen && \
locale-gen

COPY ./entrypoint_checks.sh /entrypoint_checks.sh
RUN chmod +x /entrypoint_checks.sh && chown oioioi /entrypoint_checks.sh

# Installing python dependencies
USER oioioi

Expand Down
48 changes: 27 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,6 @@ you are connected to after using docker exec -it “web” /bin/bash. The defaul
docker compose -f docker-compose-dev.yml exec "web" ../oioioi/test.sh
docker compose -f docker-compose-dev.yml exec "web" ../oioioi/test.sh oioioi/{name_of_the_app}/

Running static code analysis tools locally (requires Docker)
~~~~~~~~~~~~~~~~~~~~~~~

The static code analysis tools currently in use for python code are black, isort, pep8 and pylint.
All of them can be run locally using the `run_static.sh` shell script.
In order for the script to work the `web` container from docker-compose-dev.yml needs to be running.
The docker image for the project needs to be rebuild if you are migrating from and older Dockerfile version (rebuild the image if you are getting error messages that isort or black are not installed).
Commands for building the image and starting up the containers are listed in the paragraphs above.

When running all tools at once or when running pep8 and pylint independently only the recently modified files (files modified in the most recent commit or staged changes) will be processed.

To run all tools at once::

./run_static.sh

To run one of the tools::

./run_static.sh black
./run_static.sh isort
./run_static.sh pylint
./run_static.sh pep8

Script toolbox for Docker (development)
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -121,6 +100,33 @@ Developer environment can be easily set up by running::

For system requirements check `easy_toolbox.py`.

Running static code analysis tools locally
~~~~~~~~~~~~~~~~~~~~~~~
.. _ruff: https://github.com/astral-sh/ruff

The static code analysis tool (linter and formatter) currently in use for Python code is `ruff`_.

It can can be run locally using the::

./easy_toolbox.py ruff

In order for the script to work the `web` container from `docker-compose-dev.yml` needs to be running.

To allow ruff to fix the errors, add the `--fix` flag::

./easy_toolbox.py ruff --fix

To avoid having to run this command every time before committing, you can install `pre-commit` along with ruff::

pip install -r requirements_static.txt

Then simply run the following command::

pre-commit install

From now on, ruff will run automatically before each commit - just keep in mind
that ruff will only run on the files you have modified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add suggestion that it is possible run on all files using: pre-commit run --all-files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Manual installation (deprecated)
~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 3 additions & 1 deletion easy_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
("up", "Run all SIO2 containers", "up -d"),
("down", "Stop and remove all SIO2 containers", "down"),
("wipe", "Stop all SIO2 containers and DESTROY all data", "down -v", True),
("run", "Run django server and webpack",
("run", "Run django server and webpack",
'{exec} web conc -n js,py -c yellow,green -k "npm --prefix ../oioioi run -s watch" "python3 manage.py runserver 0.0.0.0:8000"'),
("stop", "Stop all SIO2 containers", "stop"),
("bash", "Open command prompt on web container.", "{exec} web bash"),
Expand All @@ -45,6 +45,8 @@
'{exec} web bash -c "echo CAPTCHA_TEST_MODE=True >> settings.py"'),
("npm", "Run npm command.", "{exec} web npm --prefix ../oioioi {extra_args}"),
("eslint", "Run javascript linter.", "{exec} web npm --prefix ../oioioi run lint"),
("ruff", "Run Ruff, a linter and formatter. You can add `--fix` to automatically fix some errors.","{exec} -w /sio2/oioioi web bash -c 'ruff check . {extra_args} ; echo ; ruff format .'",
)
]

longest_command_arg = max([len(command[0]) for command in RAW_COMMANDS])
Expand Down
36 changes: 0 additions & 36 deletions entrypoint_checks.sh

This file was deleted.

2 changes: 1 addition & 1 deletion oioioi/problems/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# instead of views.py to avoid circular imports. We still import
# it here to use it in urls.py.
from oioioi.problems.problem_site import (
problem_site_statement_zip_view,
problem_site_statement_zip_view, # noqa: F401
problem_site_tab_registry,
)
from oioioi.problems.problem_sources import problem_sources
Expand Down
50 changes: 22 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
[tool.isort]
profile = 'black'
skip_glob = '*/migrations/*.py'
skip = 'default_settings.py'

[tool.black]
line-length = 88
skip-string-normalization = true
verbose = false
diff = false
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.eggs
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| migrations
)/
'''
force-exclude = '((.*)?default_settings.py|(.*)migrations(.*))'
[tool.ruff]
line-length = 120
lint.select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"UP", # pyupgrade
"C4" # flake8-comprehensions
]
src = ["oioioi"]
exclude = [
"migrations",
"oioioi/**/*settings.py"
]
target-version = "py311"
lint.ignore = [
"B904",
"B026",
"C416"
]
4 changes: 2 additions & 2 deletions requirements_static.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==24.3.0
isort==5.6.4
ruff==0.11.12
elastic-apm
python-memcached
pre-commit==4.2.0
Loading
Loading