I am looking for an approach to exclude django migration files from black
and flake8
in github-actions
.
我正在寻找一种方法来排除Django迁移文件在GitHub-Actions中的Black和flke8。
Here's what I've done so far:
以下是我到目前为止所做的:
- created a
.flake8
file with the following content in the root of project:
[flake8]
exclude =
*/migrations/*
max-complexity = 10
max-line-length = 127
- a piece of my
github-actions.yml
content:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
- name: Install dependencies
run: pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
[UPDATE]:
[更新]:
Out:
输出:
6s
Run psf/black@stable
with:
options: --check --diff
src: .
jupyter: false
Run if [ "$RUNNER_OS" == "Windows" ]; then
if [ "$RUNNER_OS" == "Windows" ]; then
python $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
else
python3 $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
fi
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
INPUT_OPTIONS: --check --diff
INPUT_SRC: .
INPUT_JUPYTER: false
INPUT_BLACK_ARGS:
INPUT_VERSION:
pythonioencoding: utf-8
Installing black[colorama]==23.7.0...
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py 2023-09-10 16:56:29.804008+00:00
@@ -2,11 +2,10 @@
from django.db import migrations, models
class Migration(migrations.Migration):
-
initial = True
dependencies = []
operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py 2023-09-10 16:56:29.804642+00:00
@@ -2,11 +2,10 @@
from django.db import migrations, models
class Migration(migrations.Migration):
-
dependencies = [
("contents", "0001_initial"),
]
operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py 2023-09-10 16:56:29.841362+00:00
@@ -3,11 +3,10 @@
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
-
dependencies = [
("contents", "0001_initial"),
("star_ratings", "0001_initial"),
]
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py 2023-09-10 16:56:29.855460+00:00
@@ -3,11 +3,10 @@
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
-
dependencies = [
("contents", "0001_initial"),
("star_ratings", "0002_alter_rating_content"),
]
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py 2023-09-10 16:56:29.868224+00:00
@@ -5,11 +5,10 @@
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
-
initial = True
dependencies = [
("contents", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py 2023-09-10 16:56:29.869773+00:00
@@ -3,11 +3,10 @@
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
-
dependencies = [
("star_ratings", "0003_alter_rating_content"),
]
operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py 2023-09-10 16:56:29.880033+00:00
@@ -4,11 +4,10 @@
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
-
dependencies = [
("contents", "0002_alter_content_text"),
("star_ratings", "0004_alter_userrating_score"),
]
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py 2023-09-10 16:56:29.973121+00:00
@@ -5,11 +5,10 @@
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
-
initial = True
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py
Oh no! 💥 💔 💥
8 files would be reformatted, 35 files would be left unchanged.
Error: Process completed with exit code 1.
更多回答
this seems to work for me? what sort of problems are you seeing?
这看起来对我有用吗?你看到了什么样的问题?
@anthonysottile actually doesn't work. might it be related to the path of mentioned files?
@anthonisotile实际上并不起作用。是否与上述文件的路径有关?
"doesn't work" is not a helpful report. you should say what you're seeing and not assume that we know and can see your screen. if you would have shown some output or said "it changed files" it would have been immediately obvious you weren't talking about flake8
“不管用”不是一个有用的报告。你应该说出你所看到的,而不是假设我们知道并能看到你的屏幕。如果你展示了一些输出或者说“它改变了文件”,你就会立刻明白你说的不是flke8。
Eventually I overcame the problem. Actually, the issue was not related to the flake8
it was related to the black
linter by the following line:
最终,我克服了这个问题。实际上,这件事与薄片无关,而是与黑色短绒有关,具体如下:
- uses: psf/black@stable
-用途:PSF/Black@稳定
So to tackle this issue (excluding migration files) I created a pyproject.toml
in the project root with the following content:
为了解决这个问题(不包括迁移文件),我在项目根目录下创建了一个pyproject.toml,内容如下:
[tool.black]
exclude = '''
(
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
| migrations
)
'''
更多回答
我是一名优秀的程序员,十分优秀!