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

Reintroduce nautobot.setup() function #5532

Merged
merged 5 commits into from
Apr 8, 2024

Conversation

glennmatthews
Copy link
Contributor

Closes #5531

What's Changed

In #5310 I removed the nautobot.setup() function as part of refactoring, not realizing that there were outside use cases relying on it. This resulted in:

This PR reintroduces a form of this function that works similarly but keeps the startup-sequence refactoring from #5310 in place otherwise.

As a bonus, we can adopt the same pattern used in Apps to run pylint, i.e. pylint --init-hook "import nautobot; nautobot.setup()" ... and therefore no longer have a need for the hackish nautobot-server pylint command that we'd added to the example_app as a workaround.

Screenshots

❯ invoke pylint                                                     
Running docker compose command "ps --services --filter status=running"
Running docker compose command "run --rm --entrypoint 'pylint --verbose --init-hook "import nautobot; nautobot.setup()" 
nautobot tasks.py' nautobot"
PYTHON_VER=3.8 \
docker compose \
    --project-name "nautobot" \
    --project-directory "/Users/glennmatthews/Documents/git-stuff/nautobot/development/" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.yml" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.postgres.yml" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.dev.yml" run \
    --rm \
    --entrypoint 'pylint \
    --verbose \
    --init-hook "import nautobot; nautobot.setup()"  nautobot tasks.py' nautobot
[+] Running 3/0
 ⠿ Container nautobot-db-1        Running                                                                          0.0s
 ⠿ Container nautobot-redis-1     Running                                                                          0.0s
 ⠿ Container nautobot-selenium-1  Running                                                                          0.0s
18:14:35.178 DEBUG   nautobot.core.celery __init__.py        import_jobs_as_celery_tasks() :
  Importing system Jobs
18:14:35.184 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.ExportObjectList
18:14:35.192 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.GitRepositorySync
18:14:35.192 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.GitRepositoryDryRun
18:14:35.192 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.ImportObjects
18:14:36.877 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleDryRunJob
18:14:36.878 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleJob
18:14:36.878 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleHiddenJob
18:14:36.878 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleLoggingJob
18:14:36.879 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleFileInputOutputJob
18:14:36.879 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleJobHookReceiver
18:14:36.879 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleSimpleJobButtonReceiver
18:14:36.879 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleComplexJobButtonReceiver
Using config file /source/pyproject.toml

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

Running docker compose command "ps --services --filter status=running"
Running docker compose command "run --rm --entrypoint 'pylint --verbose --init-hook "import nautobot; nautobot.setup()" 
--recursive=y development/ examples/' nautobot"
PYTHON_VER=3.8 \
docker compose \
    --project-name "nautobot" \
    --project-directory "/Users/glennmatthews/Documents/git-stuff/nautobot/development/" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.yml" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.postgres.yml" \
    -f "/Users/glennmatthews/Documents/git-stuff/nautobot/development/docker-compose.dev.yml" run \
    --rm \
    --entrypoint 'pylint \
    --verbose \
    --init-hook "import nautobot; nautobot.setup()" \
    --recursive=y development/ examples/' nautobot
[+] Running 3/0
 ⠿ Container nautobot-selenium-1  Running                                                                          0.0s
 ⠿ Container nautobot-redis-1     Running                                                                          0.0s
 ⠿ Container nautobot-db-1        Running                                                                          0.0s
18:20:30.450 DEBUG   nautobot.core.celery __init__.py        import_jobs_as_celery_tasks() :
  Importing system Jobs
18:20:30.455 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.ExportObjectList
18:20:30.465 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.GitRepositorySync
18:20:30.465 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.GitRepositoryDryRun
18:20:30.465 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job nautobot.core.jobs.ImportObjects
18:20:32.787 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleDryRunJob
18:20:32.788 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleJob
18:20:32.788 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleHiddenJob
18:20:32.788 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleLoggingJob
18:20:32.789 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleFileInputOutputJob
18:20:32.789 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleJobHookReceiver
18:20:32.789 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleSimpleJobButtonReceiver
18:20:32.790 DEBUG   nautobot.core.celery __init__.py                      register_jobs() :
  Registering job example_app.jobs.ExampleComplexJobButtonReceiver
Using config file /source/pyproject.toml

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

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • n/a Unit, Integration Tests
  • n/a Documentation Updates (when adding/changing features)
  • Example App Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@glennmatthews glennmatthews self-assigned this Apr 3, 2024
@glennmatthews glennmatthews merged commit a762466 into develop Apr 8, 2024
17 checks passed
@glennmatthews glennmatthews deleted the u/glennmatthews-5531-nautobot-setup branch April 8, 2024 14:27
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.

App Pylint Broken with 2.2.0
3 participants