Skip to content

Commit

Permalink
Add ruff code formatting and linting github action (#170)
Browse files Browse the repository at this point in the history
* add ruff action

* apply ruff check --fix

* apply ruff format

* run ruff with import sorting

* style fixes by ruff

* fix e402

* add sort import properly

* add some noqa and fix easy ones

* reformat

* add info to the contributing guidelines

---------

Co-authored-by: bdpedigo <bdpedigo@users.noreply.github.com>
  • Loading branch information
bdpedigo and bdpedigo authored Mar 26, 2024
1 parent f549360 commit 73be62d
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 141 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint and Format
on:
push:
branches:
- master
pull_request:
branches: master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows other workflows to trigger this workflow
workflow_call:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with: # the --extend-select flag adds import sorting
args: check . --extend-select I
- uses: chartboost/ruff-action@v1
with:
args: format . --check
15 changes: 8 additions & 7 deletions caveclient/base.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import urllib
import requests
import datetime
import json
import logging

logger = logging.getLogger(__name__)
import urllib
import webbrowser

from .session_config import patch_session
import numpy as np
import datetime
import pandas as pd
import requests

from .session_config import patch_session

logger = logging.getLogger(__name__)


class BaseEncoder(json.JSONEncoder):
Expand Down Expand Up @@ -149,7 +150,7 @@ def _api_endpoints(
verify=verify,
)
avail_vs_server = set(avail_vs_server)
except:
except: # noqa: E722
avail_vs_server = None

avail_vs_client = set(endpoint_versions.keys())
Expand Down
13 changes: 7 additions & 6 deletions caveclient/chunkedgraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PyChunkedgraph service python interface"""

import datetime
import json
import logging
Expand Down Expand Up @@ -785,11 +786,11 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list:
Root id of object
bounds : np.array
3x2 bounding box (x,y,z) x (min,max) in chunked graph coordinates (use
`client.chunkedgraph.base_resolution` to view this default resolution for
your chunkedgraph client). Note that the result will include any level 2
nodes which have chunk boundaries within some part of this bounding box,
meaning that the representative point for a given level 2 node could still
be slightly outside of these bounds. If None, returns all level 2 chunks
`client.chunkedgraph.base_resolution` to view this default resolution for
your chunkedgraph client). Note that the result will include any level 2
nodes which have chunk boundaries within some part of this bounding box,
meaning that the representative point for a given level 2 node could still
be slightly outside of these bounds. If None, returns all level 2 chunks
for the root ID.
Returns
Expand All @@ -807,7 +808,7 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list:

url = self._endpoints["lvl2_graph"].format_map(endpoint_mapping)
response = self.session.get(url, params=query_d)

r = handle_response(response)

used_bounds = response.headers.get("Used-Bounds")
Expand Down
7 changes: 4 additions & 3 deletions caveclient/datastack_lookup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import json
from . import auth
import logging
import os

from . import auth

logger = logging.getLogger(__name__)

Expand All @@ -16,7 +17,7 @@ def read_map(filename=None):
with open(os.path.expanduser(filename), "r") as f:
data = json.load(f)
return data
except:
except: # noqa E722
return {}


Expand Down
25 changes: 16 additions & 9 deletions caveclient/emannotationschemas.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import logging

from requests import HTTPError

from .auth import AuthClient
from .base import ClientBase, _api_endpoints, handle_response
from .endpoints import schema_api_versions, schema_endpoints_common
from .auth import AuthClient
from requests import HTTPError
import logging

logger = logging.getLogger(__name__)

server_key = "emas_server_address"
Expand Down Expand Up @@ -81,7 +85,7 @@ def get_schemas(self) -> list[str]:
url = self._endpoints["schema"].format_map(endpoint_mapping)
response = self.session.get(url)
return handle_response(response)

def schema_definition(self, schema_type: str) -> dict[str]:
"""Get the definition of a specified schema_type
Expand All @@ -108,20 +112,22 @@ def schema_definition_multi(self, schema_types: list[str]) -> dict:
----------
schema_types : list
List of schema names
Returns
-------
dict
Dictionary of schema definitions. Keys are schema names, values are definitions.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["schema_definition_multi"].format_map(endpoint_mapping)
data={'schema_names': ','.join(schema_types)}
data = {"schema_names": ",".join(schema_types)}
response = self.session.post(url, params=data)
try:
return handle_response(response)
except HTTPError:
logger.warning('Client requested an schema service endpoint (see "schema_definition_multi") not yet available on your deployment. Please talk to your admin about updating your deployment')
logger.warning(
'Client requested an schema service endpoint (see "schema_definition_multi") not yet available on your deployment. Please talk to your admin about updating your deployment'
)
return None

def schema_definition_all(self) -> dict[str]:
Expand All @@ -138,11 +144,12 @@ def schema_definition_all(self) -> dict[str]:
try:
return handle_response(response)
except HTTPError:
logger.warning('Client requested an schema service endpoint (see "schema_definition_all") not yet available on your deployment. Please talk to your admin about updating your deployment')
logger.warning(
'Client requested an schema service endpoint (see "schema_definition_all") not yet available on your deployment. Please talk to your admin about updating your deployment'
)
return None



client_mapping = {
1: SchemaClientLegacy,
2: SchemaClientLegacy,
Expand Down
30 changes: 10 additions & 20 deletions caveclient/materializationengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import logging
import re
import warnings
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timezone
from typing import Iterable, Optional, Union
from requests import HTTPError

import numpy as np
import pandas as pd
import pyarrow as pa
import pytz
from concurrent.futures import ThreadPoolExecutor
from cachetools import TTLCache, cached
from IPython.display import HTML
from requests import HTTPError

from .auth import AuthClient
from .base import (
Expand Down Expand Up @@ -258,7 +258,7 @@ def __init__(
@property
def datastack_name(self):
return self._datastack_name

@property
def cg_client(self):
if self._cg_client is None:
Expand Down Expand Up @@ -296,7 +296,7 @@ def tables(self) -> TableManager:
else:
raise ValueError("No full CAVEclient specified")
return self._tables

@property
def views(self) -> ViewManager:
if self._views is None:
Expand Down Expand Up @@ -1894,25 +1894,15 @@ def __init__(self, *args, **kwargs):
self.get_tables_metadata,
)
)
metadata.append(
executor.submit(
self.fc.schema.schema_definition_all
)
)
metadata.append(
executor.submit(
self.get_views
)
)
metadata.append(
executor.submit(
self.get_view_schemas
)
)
metadata.append(executor.submit(self.fc.schema.schema_definition_all))
metadata.append(executor.submit(self.get_views))
metadata.append(executor.submit(self.get_view_schemas))
tables = None
if self.fc is not None:
if metadata[0].result() is not None and metadata[1].result() is not None:
tables = TableManager(self.fc, metadata[0].result(), metadata[1].result())
tables = TableManager(
self.fc, metadata[0].result(), metadata[1].result()
)
self._tables = tables
if self.fc is not None:
views = ViewManager(self.fc, metadata[2].result(), metadata[3].result())
Expand Down
2 changes: 1 addition & 1 deletion caveclient/mytimer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from time import time
import logging
from time import time

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion caveclient/tools/caching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from caveclient import CAVEclient
from cachetools import TTLCache, cached, keys

from caveclient import CAVEclient

info_cache_cache = TTLCache(maxsize=32, ttl=3600)


Expand Down
4 changes: 2 additions & 2 deletions caveclient/tools/stage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jsonschema
import attrs
import pandas as pd
import jsonschema
import numpy as np
import pandas as pd

SPATIAL_POINT_CLASSES = ["SpatialPoint", "BoundSpatialPoint"]

Expand Down
Loading

0 comments on commit 73be62d

Please sign in to comment.