Skip to content

Commit 57c441c

Browse files
robotraptaAuto-format Bot
andauthored
Adding auto-formatting of code with black. (#14)
* Adding auto-formatting of code with black. * Removing duplicate black dependency. * Automatically reformatting code with black * Reverting black version for py3.6 support in tests. * Auto-formats generated OpenAPI code. Co-authored-by: Auto-format Bot <runner@fv-az617-496.pwnmbzmyba5ezmab2zpzaqbtmg.cx.internal.cloudapp.net>
1 parent f8533b4 commit 57c441c

34 files changed

+1800
-1868
lines changed

.github/workflows/auto-format.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: auto-format
2+
on: pull_request
3+
jobs:
4+
format:
5+
# Check if the PR is not from a fork
6+
if: github.event.pull_request.head.repo.full_name == github.repository
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
with:
11+
ref: ${{ github.head_ref }}
12+
- name: black
13+
#uses: lgeiger/[email protected]
14+
uses: psf/black@stable
15+
with:
16+
src: "."
17+
options: "--verbose"
18+
- name: Check for modified files
19+
id: git-check
20+
run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
21+
- name: Push changes
22+
if: steps.git-check.outputs.modified == 'true'
23+
run: |
24+
git config --global user.name 'Auto-format Bot'
25+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
26+
git commit -am "Automatically reformatting code with black"
27+
git push
28+

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ generate: install ## Generate the SDK from our public openapi spec
99
-g python \
1010
-o ./generated
1111
poetry run datamodel-codegen --input spec/public-api.yaml --output generated/model.py
12+
poetry run black .
13+
1214

1315
test-local: install ## Run integration tests against an API server running at http://localhost:8000/device-api (needs GROUNDLIGHT_API_TOKEN)
1416
GROUNDLIGHT_TEST_API_ENDPOINT="http://localhost:8000/device-api" poetry run pytest --cov=src test --log-cli-level INFO

generated/model.py

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,91 +14,71 @@
1414
class ClassificationResult(BaseModel):
1515
confidence: Optional[confloat(ge=0.0, le=1.0)] = Field(
1616
None,
17-
description='On a scale of 0 to 1, how confident are we in the predicted label?',
17+
description="On a scale of 0 to 1, how confident are we in the predicted label?",
1818
)
19-
label: str = Field(..., description='What is the predicted label?')
19+
label: str = Field(..., description="What is the predicted label?")
2020

2121

2222
class DetectorCreationInput(BaseModel):
23-
name: constr(max_length=200) = Field(
24-
..., description='A short, descriptive name for the detector.'
25-
)
26-
query: constr(max_length=300) = Field(
27-
..., description='A question about the image.'
28-
)
23+
name: constr(max_length=200) = Field(..., description="A short, descriptive name for the detector.")
24+
query: constr(max_length=300) = Field(..., description="A question about the image.")
2925
group_name: Optional[constr(max_length=100)] = Field(
30-
None, description='Which group should this detector be part of?'
26+
None, description="Which group should this detector be part of?"
3127
)
3228
confidence_threshold: Optional[confloat(ge=0.0, le=1.0)] = Field(
3329
0.9,
3430
description="If the detector's prediction is below this confidence threshold, send the image query for human review.",
3531
)
3632
config_name: Optional[constr(max_length=100)] = Field(
3733
None,
38-
description='(Advanced usage) If your account has multiple named ML configuration options enabled, you can use this field to specify which one you would like to use.',
34+
description="(Advanced usage) If your account has multiple named ML configuration options enabled, you can use this field to specify which one you would like to use.",
3935
)
4036

4137

4238
class DetectorTypeEnum(Enum):
43-
detector = 'detector'
39+
detector = "detector"
4440

4541

4642
class ImageQueryTypeEnum(Enum):
47-
image_query = 'image_query'
43+
image_query = "image_query"
4844

4945

5046
class ResultTypeEnum(Enum):
51-
binary_classification = 'binary_classification'
47+
binary_classification = "binary_classification"
5248

5349

5450
class Detector(BaseModel):
55-
id: str = Field(..., description='A unique ID for this object.')
56-
type: DetectorTypeEnum = Field(..., description='The type of this object.')
57-
created_at: datetime = Field(..., description='When this detector was created.')
58-
name: constr(max_length=200) = Field(
59-
..., description='A short, descriptive name for the detector.'
60-
)
61-
query: str = Field(..., description='A question about the image.')
62-
group_name: str = Field(
63-
..., description='Which group should this detector be part of?'
64-
)
51+
id: str = Field(..., description="A unique ID for this object.")
52+
type: DetectorTypeEnum = Field(..., description="The type of this object.")
53+
created_at: datetime = Field(..., description="When this detector was created.")
54+
name: constr(max_length=200) = Field(..., description="A short, descriptive name for the detector.")
55+
query: str = Field(..., description="A question about the image.")
56+
group_name: str = Field(..., description="Which group should this detector be part of?")
6557
confidence_threshold: Optional[confloat(ge=0.0, le=1.0)] = Field(
6658
0.9,
6759
description="If the detector's prediction is below this confidence threshold, send the image query for human review.",
6860
)
6961

7062

7163
class ImageQuery(BaseModel):
72-
id: str = Field(..., description='A unique ID for this object.')
73-
type: ImageQueryTypeEnum = Field(..., description='The type of this object.')
74-
created_at: datetime = Field(..., description='When was this detector created?')
75-
query: str = Field(..., description='A question about the image.')
76-
detector_id: str = Field(
77-
..., description='Which detector was used on this image query?'
78-
)
79-
result_type: ResultTypeEnum = Field(
80-
..., description='What type of result are we returning?'
81-
)
64+
id: str = Field(..., description="A unique ID for this object.")
65+
type: ImageQueryTypeEnum = Field(..., description="The type of this object.")
66+
created_at: datetime = Field(..., description="When was this detector created?")
67+
query: str = Field(..., description="A question about the image.")
68+
detector_id: str = Field(..., description="Which detector was used on this image query?")
69+
result_type: ResultTypeEnum = Field(..., description="What type of result are we returning?")
8270
result: ClassificationResult
8371

8472

8573
class PaginatedDetectorList(BaseModel):
8674
count: Optional[int] = Field(None, example=123)
87-
next: Optional[AnyUrl] = Field(
88-
None, example='http://api.example.org/accounts/?page=4'
89-
)
90-
previous: Optional[AnyUrl] = Field(
91-
None, example='http://api.example.org/accounts/?page=2'
92-
)
75+
next: Optional[AnyUrl] = Field(None, example="http://api.example.org/accounts/?page=4")
76+
previous: Optional[AnyUrl] = Field(None, example="http://api.example.org/accounts/?page=2")
9377
results: Optional[List[Detector]] = None
9478

9579

9680
class PaginatedImageQueryList(BaseModel):
9781
count: Optional[int] = Field(None, example=123)
98-
next: Optional[AnyUrl] = Field(
99-
None, example='http://api.example.org/accounts/?page=4'
100-
)
101-
previous: Optional[AnyUrl] = Field(
102-
None, example='http://api.example.org/accounts/?page=2'
103-
)
82+
next: Optional[AnyUrl] = Field(None, example="http://api.example.org/accounts/?page=4")
83+
previous: Optional[AnyUrl] = Field(None, example="http://api.example.org/accounts/?page=2")
10484
results: Optional[List[ImageQuery]] = None

0 commit comments

Comments
 (0)