Skip to content

Commit

Permalink
Use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
leifwar committed Sep 28, 2023
1 parent 84af135 commit 3e33520
Show file tree
Hide file tree
Showing 28 changed files with 865 additions and 1,983 deletions.
46 changes: 15 additions & 31 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
---
name: "CodeQL"

on:
push:
branches: [ master ]
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches: [master]
schedule:
- cron: '25 22 * * 1'

Expand All @@ -32,40 +33,23 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ['python']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
10 changes: 6 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Deploy to PyPI

on:
Expand All @@ -10,8 +11,9 @@ permissions:
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
# Allow only one concurrent deployment, skipping runs queued between the run in-progress
# and latest queued. However, do NOT cancel in-progress runs as we want to allow these
# production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
Expand All @@ -31,7 +33,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install and configure Poetry
uses: abatilo/actions-poetry@v2.3.0
with:
Expand All @@ -58,7 +60,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install and configure Poetry
uses: abatilo/actions-poetry@v2.3.0
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/poetry.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
name: poetry

on:
schedule:
- cron: "0 9 * * 1" # Mondays at 09:00
- cron: "0 9 * * 1" # Mondays at 09:00
workflow_dispatch:

jobs:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11

- name: Get full python version
id: full-python-version
Expand All @@ -40,9 +40,9 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.9', '3.10', '3.11']
poetry-version: [ 1.6.1 ]
os: [ubuntu-latest]
python-version: ['3.10', '3.11']
poetry-version: [1.6.1]

services:
rdf4j:
Expand Down
60 changes: 18 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
---
default_language_version:
python: python3
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/hadialqattan/pycln
rev: v2.2.2
- id: check-json
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
hooks:
- id: pycln
args: [--all]
- repo: https://github.com/psf/black
rev: 23.7.0
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- pyflakes
- pycodestyle
- flake8-bugbear
- flake8-comprehensions
- flake8-eradicate
- flake8-mutable
- flake8-simplify
- flake8-builtins
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.6
hooks:
- id: python-bandit-vulnerability-check
args: [-ll, -ii, --exclude, ./.venv/*, --recursive, .]
pass_filenames: false
always_run: true
- id: black
14 changes: 8 additions & 6 deletions cimsparql/async_sparql_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from http import HTTPStatus
from typing import Optional
from typing import Any

import httpx
from SPARQLWrapper import JSON, SPARQLWrapper
Expand All @@ -21,20 +23,20 @@


class AsyncSparqlWrapper(SPARQLWrapper):
def __init__(self, *args, **kwargs):
self.ca_bundle: Optional[str] = kwargs.pop("ca_bundle", None)
def __init__(self, *args: Any, **kwargs: dict[str, str | None]) -> None:
self.ca_bundle: str | None = kwargs.pop("ca_bundle", None)
super().__init__(*args, **kwargs)

async def queryAndConvert(self) -> dict:
async def queryAndConvert(self) -> dict: # noqa N802
if self.returnFormat != JSON:
raise NotImplementedError("Async client only support JSON return format")

request = self._createRequest()
url = request.get_full_url()
method = request.get_method()

args = {"timeout": self.timeout} | ({"verify": self.ca_bundle} if self.ca_bundle else {})
async with httpx.AsyncClient(**args) as client:
kwargs = {"verify": self.ca_bundle} if self.ca_bundle else {}
async with httpx.AsyncClient(timeout=self.timeout, **kwargs) as client:
response = await client.request(
method, url, headers=request.headers, content=request.data
)
Expand Down
7 changes: 4 additions & 3 deletions cimsparql/data_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
from typing import ClassVar

import pandas as pd
import pandera as pa
Expand All @@ -8,7 +9,7 @@
class JsonSchemaOut(pa.SchemaModel):
class Config:
to_format = "json"
to_format_kwargs = {"orient": "table"}
to_format_kwargs: ClassVar[dict[str, str]] = {"orient": "table"}
coerce = True


Expand Down Expand Up @@ -103,8 +104,8 @@ class SynchronousMachinesSchema(NamedMarketResourceSchema):
station_group: Series[str] = pa.Field(nullable=True)
station_group_name: Series[str] = pa.Field(nullable=True)
station: Series[str] = pa.Field()
maxP: Series[float] = pa.Field(nullable=True)
minP: Series[float] = pa.Field(nullable=True)
maxP: Series[float] = pa.Field(nullable=True) # noqa N815
minP: Series[float] = pa.Field(nullable=True) # noqa N815
MO: Series[float] = pa.Field(nullable=True)
bidzone: Series[str] = pa.Field(nullable=True)
sn: Series[float] = pa.Field()
Expand Down
Loading

0 comments on commit 3e33520

Please sign in to comment.