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

Run latest pylint-nautobot #3

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
47 changes: 47 additions & 0 deletions .github/workflows/pylint_nautobot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: "Latest pylint-nautobot"

on: # yamllint disable-line rule:truthy rule:comments
schedule:
- cron: "0 3 */2 * *" # every other day at 3am

env:
APP_NAME: "nautobot-app-dev-example"

jobs:
latest-pylint-nautobot:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
matrix:
python-version: ["3.11"]
nautobot-version: ["stable"]
env:
INVOKE_NAUTOBOT_DEV_EXAMPLE_PYTHON_VER: "${{ matrix.python-version }}"
INVOKE_NAUTOBOT_DEV_EXAMPLE_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v3"
- name: "Build"
uses: "docker/build-push-action@v5"
with:
builder: "${{ steps.buildx.outputs.name }}"
context: "./"
push: false
load: true
tags: "${{ env.APP_NAME }}/nautobot:${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
file: "./development/Dockerfile"
cache-from: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
cache-to: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
build-args: |
NAUTOBOT_VER=${{ matrix.nautobot-version }}
PYTHON_VER=${{ matrix.python-version }}
- name: "Copy credentials"
run: "cp development/creds.example.env development/creds.env"
- name: "Linting: pylint"
run: "poetry run invoke pylint --ref=develop"
1 change: 1 addition & 0 deletions changes/3.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run latest pylint-nautobot checks workflow.
50 changes: 46 additions & 4 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,53 @@ def hadolint(context):
run_command(context, command)


@task
def pylint(context):
@task(
help={
"ref": "`pylint-nautobot` git reference to use for the analysis, can be a local path to the repository"
", or a git reference e.g. `--ref=develop`. Use currently installed version if empty. (default: Empty)",
}
)
def pylint(context, ref=""):
"""Run pylint code analysis."""
command = 'pylint --init-hook "import nautobot; nautobot.setup()" --rcfile pyproject.toml nautobot_dev_example'
run_command(context, command)
pylint_command = [
"pylint",
'--init-hook="import nautobot; nautobot.setup()"',
"--rcfile=pyproject.toml",
"nautobot_dev_example",
]

if not ref:
run_command(context, " ".join(pylint_command))
return

pip_and_pylint_command = ["pip install"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to pip install it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For our implementation, similar to pylint-django, it's necessary to have the package installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I don't understand is why is this not installed by poetry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

poetry install doesn't allow to specify the GitHub as a package source, works with local pyproject.toml only.


local_pylint_nautobot_path = Path(ref).resolve().absolute()
if local_pylint_nautobot_path.is_dir() and (local_pylint_nautobot_path / "pyproject.toml").is_file():
pip_and_pylint_command.append(f"-e {local_pylint_nautobot_path}")
else:
local_pylint_nautobot_path = None
pip_and_pylint_command.append(f"git+https://github.com/nautobot/pylint-nautobot.git@{ref}")

pip_and_pylint_command += [
"&&",
*pylint_command,
]

if is_truthy(context.nautobot_dev_example.local):
cmsirbu marked this conversation as resolved.
Show resolved Hide resolved
context.run(" ".join(pip_and_pylint_command))
return

docker_run_command = [
"run --rm --entrypoint=''",
f"--volume {local_pylint_nautobot_path}:{local_pylint_nautobot_path}" if local_pylint_nautobot_path else "",
"-- nautobot sh -c '",
*pip_and_pylint_command,
"'",
]

# Do not use `run_command()` to avoid poluting the running container with the installed package
docker_compose(context, " ".join(docker_run_command))


@task(aliases=("a",))
Expand Down