Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pylint_django migrations check #50

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

gsnider2195
Copy link
Contributor

Test code with failure

nautobot_dev_example/migrations/0002_runpython.py

# Generated by Django 3.2.21 on 2024-02-16 08:32

from django.db import migrations


def runpython_noop(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("nautobot_dev_example", "0001_initial"),
    ]

    operations = [migrations.RunPython(code=runpython_noop)]

Output

$ inv pylint
Running docker compose command "ps --services --filter status=running"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

Running docker compose command "run --rm --entrypoint='pylint --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml nautobot_dev_example' nautobot"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

[+] Creating 2/0
 ✔ Container nautobot-dev-example-db-1     Running                                                                                                      0.0s 
 ✔ Container nautobot-dev-example-redis-1  Running                                                                                                      0.0s 
18:11:05.133 INFO    nautobot             __init__.py                              setup() : Nautobot initialized!

------------------------------------
Your code has been rated at 10.00/10

Running docker compose command "ps --services --filter status=running"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

Running docker compose command "run --rm --entrypoint='pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml --load-plugins=pylint_django.checkers.migrations --disable=all --enable=new-db-field-with-default,missing-backwards-migration-callable nautobot_dev_example.migrations' nautobot"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

[+] Creating 2/0
 ✔ Container nautobot-dev-example-redis-1  Running                                                                                                      0.0s 
 ✔ Container nautobot-dev-example-db-1     Running                                                                                                      0.0s 
18:11:17.139 INFO    nautobot             __init__.py                              setup() : Nautobot initialized!
Using config file pyproject.toml
************* Module nautobot_dev_example.migrations.0002_runpython
nautobot_dev_example/migrations/0002_runpython.py:15:18: W5197: Always include backwards migration callable (missing-backwards-migration-callable)

-----------------------------------
Your code has been rated at 9.33/10

Error: executing /usr/libexec/docker/cli-plugins/docker-compose --project-name nautobot-dev-example --project-directory /home/gary/github/nautobot/nautobot-app-dev-example/development -f /home/gary/github/nautobot/nautobot-app-dev-example/development/docker-compose.base.yml -f /home/gary/github/nautobot/nautobot-app-dev-example/development/docker-compose.redis.yml -f /home/gary/github/nautobot/nautobot-app-dev-example/development/docker-compose.postgres.yml -f /home/gary/github/nautobot/nautobot-app-dev-example/development/docker-compose.dev.yml run --rm --entrypoint=pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml --load-plugins=pylint_django.checkers.migrations --disable=all --enable=new-db-field-with-default,missing-backwards-migration-callable nautobot_dev_example.migrations nautobot: exit status 4
$ echo $?
1
$ 

Test code with success

nautobot_dev_example/migrations/0002_runpython.py

# Generated by Django 3.2.21 on 2024-02-16 08:32

from django.db import migrations


def runpython_noop(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("nautobot_dev_example", "0001_initial"),
    ]

    operations = [migrations.RunPython(code=runpython_noop, reverse_code=migrations.RunPython.noop)]

Output

$ inv pylint
Running docker compose command "ps --services --filter status=running"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

Running docker compose command "run --rm --entrypoint='pylint --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml nautobot_dev_example' nautobot"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

[+] Creating 2/0
 ✔ Container nautobot-dev-example-db-1     Running                                                                                                      0.0s 
 ✔ Container nautobot-dev-example-redis-1  Running                                                                                                      0.0s 
18:14:40.335 INFO    nautobot             __init__.py                              setup() : Nautobot initialized!

------------------------------------
Your code has been rated at 10.00/10

Running docker compose command "ps --services --filter status=running"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

Running docker compose command "run --rm --entrypoint='pylint --verbose --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml --load-plugins=pylint_django.checkers.migrations --disable=all --enable=new-db-field-with-default,missing-backwards-migration-callable nautobot_dev_example.migrations' nautobot"
>>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please refer to the documentation for details. <<<<

[+] Creating 2/0
 ✔ Container nautobot-dev-example-db-1     Running                                                                                                      0.0s 
 ✔ Container nautobot-dev-example-redis-1  Running                                                                                                      0.0s 
18:14:52.505 INFO    nautobot             __init__.py                              setup() : Nautobot initialized!
Using config file pyproject.toml

------------------------------------
Your code has been rated at 10.00/10

$ echo $?
0
$ 

@gsnider2195 gsnider2195 requested a review from a team as a code owner October 2, 2024 18:18
tasks.py Outdated Show resolved Hide resolved
smk4664
smk4664 previously approved these changes Oct 4, 2024
Copy link
Contributor

@smk4664 smk4664 left a comment

Choose a reason for hiding this comment

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

This looks great, just a question on the verbose.

Copy link
Contributor

@smk4664 smk4664 left a comment

Choose a reason for hiding this comment

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

Even better than before! Thanks for fixing the Verbose part.

@gsnider2195 gsnider2195 merged commit 1bbccae into develop Oct 7, 2024
15 checks passed
@gsnider2195 gsnider2195 deleted the u/gas-pylint-django-migrations branch October 7, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants