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

build: add import formatting with autoflake and isort #247

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ repos:
name: format
entry: bash -c "make fmt"
language: system
- id: fix
name: fix
entry: bash -c "make fix"
language: system
- id: lint
name: lint
entry: bash -c "make lint"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Before contributing to the `posit-sdk`, ensure that the following prerequisites
1. Create a new branch for your feature or bug fix.
1. Run `make` to run the default development workflow.
1. Make your changes and test them thoroughly using `make test`
1. Run `make fmt`, `make lint`, and `make fix` to verify adherence to the project style guide.
1. Run `make fmt` and `make lint` to verify adherence to the project style guide.
1. Commit your changes and push them to your forked repository.
1. Submit a pull request to the main repository.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't comment lower where it's talked about, but do we give folks steps for setting up ruff? IMO having a "run these lines of code and it will make your dev environment work" really helpful.

Alternatively / in addition: this is something we could trigger a bot on a comment and then CI deals with having an env setup. I've found this pattern to be suuuuper helpful for drop-by contributors

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ruff is installed as part of make deps (which is part of default make). I'll update the README to make this obvious.

CI runs make lint and will fail if there are errors. My assumption is a contributor would be able to figure things out from there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My assumption is a contributor would be able to figure things out from there.

IME, this works sometimes, but not always.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IME, this works sometimes, but not always.

Sure. We can add more context if needed in the future. I believe there are GitHub Actions that will annotate the source code with lining errors.

Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ dev:
docs:
$(MAKE) -C ./docs

fix:
$(PYTHON) -m ruff check --fix

fmt:
$(PYTHON) -m ruff check --fix
$(PYTHON) -m ruff format .

install:
Expand Down
1 change: 0 additions & 1 deletion examples/connect/dash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from databricks import sql
from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
Expand Down
1 change: 0 additions & 1 deletion examples/connect/fastapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from databricks import sql
from fastapi import FastAPI, Header
from fastapi.responses import JSONResponse

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
Expand Down
1 change: 0 additions & 1 deletion examples/connect/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from databricks import sql
from flask import Flask, request

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
Expand Down
3 changes: 1 addition & 2 deletions examples/connect/shiny-python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from databricks import sql
from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI
from shiny import App, Inputs, Outputs, Session, render, ui

from posit.connect.external.databricks import viewer_credentials_provider
from shiny import App, Inputs, Outputs, Session, render, ui

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
Expand Down
3 changes: 1 addition & 2 deletions examples/connect/streamlit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from databricks import sql
from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI
from streamlit.web.server.websocket_headers import _get_websocket_headers

from posit.connect.external.databricks import viewer_credentials_provider
from streamlit.web.server.websocket_headers import _get_websocket_headers

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
Expand Down
1 change: 0 additions & 1 deletion integration/tests/posit/connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from packaging import version

from posit import connect

client = connect.Client()
Expand Down
1 change: 0 additions & 1 deletion integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
from packaging import version

from posit import connect

from . import CONNECT_VERSION
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.ruff.lint]
select = ["D"]
select = ["D", "F401", "I"]
ignore = [
# NumPy style docstring convention with noted exceptions.
# https://docs.astral.sh/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings
Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/metrics/test_shiny_usage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import requests
import responses
from responses import matchers

from posit.connect import config
from posit.connect.metrics import shiny_usage
from responses import matchers

from ..api import load_mock # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/metrics/test_usage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
import responses
from responses import matchers

from posit import connect
from posit.connect.metrics import shiny_usage, usage, visits
from responses import matchers

from ..api import load_mock # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/metrics/test_visits.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import requests
import responses
from responses import matchers

from posit.connect import config
from posit.connect.metrics import visits
from responses import matchers

from ..api import load_mock # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import pytest
import requests
import responses
from responses import matchers

from posit.connect import Client
from posit.connect.bundles import Bundle
from posit.connect.config import Config
from responses import matchers

from .api import get_path, load_mock # type: ignore

Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
import responses

from posit.connect import Client

from .api import load_mock # type: ignore
Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest.mock import patch

import pytest

from posit.connect.config import Config, _get_api_key, _get_url


Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import pytest
import requests
import responses
from responses import matchers

from posit.connect.client import Client
from posit.connect.config import Config
from posit.connect.content import ContentItem, ContentItemOwner
from posit.connect.permissions import Permissions
from responses import matchers

from .api import load_mock # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest
import responses
from responses import matchers

from posit.connect import Client
from responses import matchers

from .api import load_mock # type: ignore

Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from posit.connect.errors import ClientError


Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_groups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest.mock import Mock

import requests

from posit.connect.config import Config
from posit.connect.groups import Group

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import pytest
import responses
from requests import HTTPError, Response

from posit.connect import Client
from posit.connect.errors import ClientError
from posit.connect.hooks import handle_errors
from requests import HTTPError, Response


def test_success():
Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_oauth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import responses

from posit.connect import Client


Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import requests
import responses
from responses import matchers

from posit.connect.config import Config
from posit.connect.permissions import Permission, Permissions
from responses import matchers

from .api import load_mock # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import responses
from responses import matchers

from posit import connect
from posit.connect import tasks
from responses import matchers

from .api import load_mock # type: ignore

Expand Down
1 change: 0 additions & 1 deletion tests/posit/connect/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from posit.connect import urls


Expand Down
3 changes: 1 addition & 2 deletions tests/posit/connect/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import pytest
import requests
import responses
from responses import matchers

from posit.connect.client import Client
from posit.connect.users import User
from responses import matchers

from .api import load_mock # type: ignore

Expand Down
Loading