Skip to content

Commit

Permalink
Merge PR #95 from jcbianic:features/add_sourcery
Browse files Browse the repository at this point in the history
Adding Sourcery to the tooling & Upgrading Dependencies
  • Loading branch information
jcbianic committed Jan 17, 2023
2 parents ddf03eb + e9e7c67 commit b5f2313
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 60 deletions.
68 changes: 68 additions & 0 deletions .sourcery.yaml
@@ -0,0 +1,68 @@
# 🪄 This is your project's Sourcery configuration file.

# You can use it to get Sourcery working in the way you want, such as
# ignoring specific refactorings, skipping directories in your project,
# or writing custom rules.

# 📚 For a complete reference to this file, see the documentation at
# https://docs.sourcery.ai/Configuration/Project-Settings/

# This file was auto-generated by Sourcery on 2023-01-17 at 11:42.

version: "1" # The schema version of this config file

ignore: # A list of paths or files which Sourcery will ignore.
- .git
- venv
- .venv
- env
- .env
- .tox
- .nox

rule_settings:
enable:
- default
disable: [] # A list of rule IDs Sourcery will never suggest.
rule_types:
- refactoring
- suggestion
- comment
python_version: "3.9" # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
# description: Do not use print statements in the test directory.
# pattern: print(...)
# replacement:
# condition:
# explanation:
# paths:
# include:
# - test
# exclude:
# - conftest.py
# tests: []
# tags: []

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0

# github:
# labels: []
# ignore_labels:
# - sourcery-ignore
# request_review: author
# sourcery_branch: sourcery/{base_branch}

# clone_detection:
# min_lines: 3
# min_duplicates: 2
# identical_clones_only: false

# proxy:
# url:
# ssl_certs_file:
# no_ssl_verify: false
4 changes: 2 additions & 2 deletions flask_jeroboam/_parser.py
Expand Up @@ -51,8 +51,8 @@ def _rename_keys(location: dict, pattern: str) -> dict:
if len(value) == 1 and match is None:
location[key] = value[0]
elif match is not None:
new_key = match.group(1) + "[]"
new_value = {match.group(2): value[0]}
new_key = f"{match[1]}[]"
new_value = {match[2]: value[0]}
renamings.append((key, new_key, new_value))
for key, new_key, new_value in renamings:
if new_key not in location:
Expand Down
16 changes: 8 additions & 8 deletions flask_jeroboam/models.py
Expand Up @@ -2,6 +2,8 @@
import json
import re
from typing import Callable
from typing import Dict
from typing import List
from typing import Union

from pydantic import BaseModel
Expand All @@ -25,14 +27,12 @@ def convert_dict_keys_to(
convert_dict_keys_to(e, convert_function) if isinstance(e, dict) else e
for e in obj
]
new_object = {}
for key, value in obj.items():
new_object[convert_function(key)] = (
convert_dict_keys_to(value, convert_function)
if isinstance(value, dict) or isinstance(value, list)
else value
)
return new_object
return {
convert_function(key): convert_dict_keys_to(value, convert_function)
if isinstance(value, (Dict, List))
else value
for key, value in obj.items()
}


def underscore_to_camel(key: str) -> str:
Expand Down
184 changes: 140 additions & 44 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -70,6 +70,7 @@ sphinx-multiversion = "^0.2.4"
typeguard = ">=2.13.3"
xdoctest = {extras = ["colors"], version = ">=0.15.10"}
certifi = ">=2022.12.7"
sourcery-cli = "^1.0.3"

[tool.poetry.group.docs.dependencies]
sphinx = "<5.3.0"
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Expand Up @@ -27,8 +27,7 @@ def app() -> Jeroboam:
@pytest.fixture
def blueprint() -> APIBlueprint:
"""A Basic Jeroboam Test App."""
router = APIBlueprint("TestBluePrint", __name__)
return router
return APIBlueprint("TestBluePrint", __name__)


@pytest.fixture
Expand Down
5 changes: 1 addition & 4 deletions tests/test_request_parsing.py
Expand Up @@ -187,10 +187,7 @@ class InBoundModel(BaseModel):

@app.get("/optionnal_param")
def ping(payload: Optional[InBoundModel]):
if payload:
return payload.json()
else:
return {}
return payload.json() if payload else {}

r = client.get("/optionnal_param")

Expand Down

0 comments on commit b5f2313

Please sign in to comment.