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

change: replace custom types with Pydantic 2 #335

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cedd723
style: run linters on non-docs
thearchitector Mar 28, 2024
dbb9bda
fix: type errors
thearchitector Mar 28, 2024
c930084
add: typed type utils
thearchitector Mar 29, 2024
04a3f8d
add: client config typing
thearchitector Mar 29, 2024
1297751
fix: isort config
thearchitector Mar 29, 2024
f688770
fix: lint config
thearchitector Mar 29, 2024
d5125e5
add: http request typing
thearchitector Mar 29, 2024
b981e32
add: generic typing to request/response pipeline
thearchitector Apr 2, 2024
d02eac7
add: typing to http clients
thearchitector Apr 2, 2024
2f9a2c1
add: proper return typing to client calls
thearchitector Apr 2, 2024
eb44353
fix: styling
thearchitector Apr 3, 2024
2a98454
fix: client and request generic typing
thearchitector Apr 3, 2024
9e75e5e
fix: types-ing
thearchitector Apr 4, 2024
9dbf2a7
fix: 50% typing to queries
thearchitector Apr 4, 2024
e8c3742
light at the end of the typed tunnel
thearchitector Apr 4, 2024
0c77108
fix: rebase
thearchitector Apr 4, 2024
f7fc619
fix: regressions
thearchitector Apr 4, 2024
bf1660c
fix: other regressions
thearchitector Apr 5, 2024
c9d4a01
fix: integration test regressions
thearchitector Apr 5, 2024
e914692
add: typed example
thearchitector Apr 5, 2024
84fbd0b
fix: cleanup
thearchitector Apr 11, 2024
b04a931
fix: status code and base type check
thearchitector May 6, 2024
1a01585
fix: resposne covariance
thearchitector May 23, 2024
7945cc3
fix: add docker tox tester
thearchitector Sep 17, 2024
2e05b7e
add: submission file meta for eml mfs
thearchitector Sep 17, 2024
c16e83b
fix: typing for 3.8
thearchitector Sep 17, 2024
7a56f75
fix: load generic dict scalar fields
thearchitector Sep 17, 2024
2ea837f
change: convert types to pydantic models
thearchitector Oct 4, 2024
95dd31c
fix: use legacy datetime parsing
thearchitector Oct 4, 2024
ab58239
fix: warnings and deprecations
thearchitector Oct 4, 2024
578de0a
fix: postponned annons
thearchitector Oct 4, 2024
cd974c0
docs: to_camel comment
thearchitector Oct 4, 2024
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
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv
dist
docs
docsrc
.hypothesis
.mypy_cache
.pytest_cache
.tox
build
readme_docs
scripts
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pip-log.txt
.coverage
.tox
nosetests.xml
.mypy_cache

# Translations
*.mo
Expand All @@ -37,6 +38,7 @@ nosetests.xml
.noseids
.pytest*
*.json
.hypothesis

codeship.aes
.env
Expand All @@ -55,10 +57,11 @@ examples/readme.py
docsrc/_build
docs/.doctrees
setup_tests.sh
test.csv

.venv
.vscode/

.DS_Store
.ipynb_checkpoints/
*.ipynb
*.ipynb
13 changes: 10 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.5.0
hooks:
- id: check-yaml
exclude: ^docs
- id: end-of-file-fixer
exclude: ^docs
- id: trailing-whitespace
exclude: ^docs
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.11.0
hooks:
- id: black
language_version: python3
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Chris Lee <[email protected]>
Nicolas Kassis<[email protected]>
Nicolas Kassis<[email protected]>
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Oct 16 2019 v2.0.0: Complete change of IndicoIo API through the Indico IPA platform. For IPA Platform API use only.
Oct 16 2019 v2.0.0: Complete change of IndicoIo API through the Indico IPA platform. For IPA Platform API use only.
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @IndicoDataSolutions/pr-be-indicodata-ai
* @IndicoDataSolutions/pr-be-indicodata-ai
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,20 @@ You will also need the following env variables set for the Exchange integration
2. Activate the virtual environment
`source venv/bin/activate`
3. Install the client
`python3 setup.py install`
4. Install pytest
`pip3 install pytest`
`pip3 install --editable .`
4. Install test deps
`pip3 install "pytest<8" "requests-mock>=1.8.0" "pytest-asyncio>0.21"`
5. Run tests
`pytest -sv --host <indico_host> tests/`
_ Only run unit tests `pytest -sv --host <indico_host> tests/unit/`
_ Only run integration tests `pytest -sv --host <indico_host> tests/integration/`
6. Check typing
```sh
pip3 install "mypy==1.8" typing_extensions pandas-stubs types-requests types-pytz types-openpyxl
mypy --config-file=pyproject.toml
```

Alternatively, run all the unit tests via `docker compose run --rm tester`

# Contributing

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ From source:
.. code:: bash

git clone https://github.com/IndicoDataSolutions/indico-client-python.git
python setup.py install
python setup.py install
13 changes: 12 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ services:
indico-client-build:
build:
context: .
entrypoint: [ "sleep", "infinity" ]
entrypoint: ["sleep", "infinity"]

tester:
build:
context: .
dockerfile: tox.Dockerfile
volumes:
- ./:/indico-client
- ${INDICO_API_TOKEN_PATH:-$HOME/indico_api_token.txt}:/root/indico_api_token.txt
environment:
INDICO_HOST: ${INDICO_HOST:-dev-ci.us-east-2.indico-dev.indico.io}
command: tox -vvvvp
2 changes: 1 addition & 1 deletion docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
"sphinx_markdown_builder"
"sphinx_markdown_builder",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion examples/aio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""

import asyncio

from indico import AsyncIndicoClient, IndicoConfig
from indico.queries import CreateDataset


"""
Examples for client creation
"""
Expand Down
42 changes: 20 additions & 22 deletions examples/classifier_extraction_workflow/component_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@

Note the dataset in this example was built from data/swaps_with_class.csv
"""

from datetime import datetime

from component_links import get_component_link_id
from config import CLASSIFIER_CLASSES, DATASET_ID, INDICO_CLIENT
from queries import get_user_ids

from indico import IndicoClient, IndicoConfig
from indico.queries import (
GetDataset,
AddModelGroupComponent,
AddLinkClassificationComponent,
AddModelGroupComponent,
CreateWorkflow,
GetDataset,
)
from indico.types import NewLabelsetArguments, NewQuestionnaireArguments, ModelTaskType

from config import INDICO_CLIENT, DATASET_ID, CLASSIFIER_CLASSES
from queries import get_user_ids
from component_links import get_component_link_id


from indico import IndicoClient, IndicoConfig
from indico.types import ModelTaskType, NewLabelsetArguments, NewQuestionnaireArguments

HOST = "indico.host"
API_TOKEN_PATH = "/path/to/indico_api_token.txt"

INDICO_CONFIG = IndicoConfig(host=HOST, api_token_path=API_TOKEN_PATH)
INDICO_CLIENT = IndicoClient(config=INDICO_CONFIG)
DATASET_ID = <your dataset id>
DATASET_ID = int("<your dataset id>")

CLASSIFIER_CLASSES = ["class A", "class B"]

timestamp = datetime.now()

dataset = INDICO_CLIENT.call(GetDataset(DATASET_ID))
Expand All @@ -50,13 +49,13 @@
"name": classifier_name,
"num_labelers_required": 1,
"task_type": ModelTaskType.CLASSIFICATION,
"target_names": CLASSIFIER_CLASSES
"target_names": CLASSIFIER_CLASSES,
}
questionnaire_args = {
"instructions": "Click things",
"show_predictions": True,
"users": user_ids
}
"instructions": "Click things",
"show_predictions": True,
"users": user_ids,
}

classifier_wf = INDICO_CLIENT.call(
AddModelGroupComponent(
Expand All @@ -82,7 +81,6 @@
after_component_id=classifier_component.id,
filtered_classes=filtered_classes,
labels=None,

)
)

Expand All @@ -93,14 +91,14 @@
class_a_link_id = get_component_link_id(workflow.id, ["class A"])
class_b_link_id = get_component_link_id(workflow.id, ["class B"])

#create extraction model 1
# create extraction model 1
extraction_model_1_name = f"Extraction 1 {timestamp}"
new_labelset_args = {
"datacolumn_id": source_col_id,
"name": extraction_model_1_name,
"num_labelers_required": 1,
"task_type": ModelTaskType.ANNOTATION,
"target_names": ["extraction class 1"]
"target_names": ["extraction class 1"],
}
extraction_model_1 = INDICO_CLIENT.call(
AddModelGroupComponent(
Expand All @@ -114,14 +112,14 @@
)
)

#create extraction model 2
# create extraction model 2
extraction_model_2_name = f"Extraction 2 {timestamp}"
new_labelset_args = {
"datacolumn_id": source_col_id,
"name": extraction_model_2_name,
"num_labelers_required": 1,
"task_type": ModelTaskType.ANNOTATION,
"target_names": ["extraction class 2"]
"target_names": ["extraction class 2"],
}
extraction_model_2 = INDICO_CLIENT.call(
AddModelGroupComponent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from queries import get_component_links


def get_component_link_id(workflow_id, class_filter):
component_links = get_component_links(workflow_id)
for component_link in component_links:
link_filter = component_link["filters"]
if link_filter:
if class_filter == link_filter["classes"]:
return component_link["id"]


6 changes: 3 additions & 3 deletions examples/classifier_extraction_workflow/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def get_component_links(workflow_id, indico_client):
workflow_query = """
query ListWorkflows($workflowIds: [Int]){
workflows(workflowIds: $workflowIds){
workflows {
workflows {
componentLinks{
id
headComponentId
tailComponentId
filters{
classes
}
}
}
}
}
}
}
"""
variables = {"workflowIds": [workflow_id]}
resp = indico_client.call(GraphQLRequest(workflow_query, variables))
Expand Down
4 changes: 2 additions & 2 deletions examples/create-download-export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from indico import IndicoClient, IndicoConfig
from indico.queries import GetDataset, CreateExport, DownloadExport
import pandas as pd

from indico import IndicoClient, IndicoConfig
from indico.queries import CreateExport, DownloadExport, GetDataset

"""Example 1: Create export from dataset and download as csv"""

Expand Down
3 changes: 2 additions & 1 deletion examples/create-image-dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
below shows you what to do if the images are on your computer.
"""

import pandas as pd

from indico import IndicoClient, IndicoConfig
from indico.queries import CreateDataset
import pandas as pd

# Create an Indico API client
my_config = IndicoConfig(
Expand Down
1 change: 1 addition & 0 deletions examples/custom_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from indico import IndicoClient, IndicoConfig

# Will connect to https://try.indico.io
Expand Down
6 changes: 3 additions & 3 deletions examples/get-document-report.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime
from typing import List
from indico import IndicoConfig, IndicoClient

from indico import IndicoClient, IndicoConfig
from indico.filters import DocumentReportFilter
from indico.queries.document_report import GetDocumentReport
from indico.types.document_report import DocumentReport
from indico.filters import DocumentReportFilter


"""Example 1: Document Report for a date range and page through the results"""

Expand Down
8 changes: 4 additions & 4 deletions examples/get-user-metrics.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from datetime import datetime, timedelta

from indico import IndicoConfig, IndicoClient
from indico.filters import or_, UserMetricsFilter
from indico import IndicoClient, IndicoConfig
from indico.filters import UserMetricsFilter, or_
from indico.queries import JobStatus, RetrieveStorageObject
from indico.queries.usermetrics import (
GetUserSummary,
GetUserSnapshots,
GenerateChangelogReport,
GetUserChangelog,
GetUserSnapshots,
GetUserSummary,
)
from indico.types.user_metrics import UserSummary

Expand Down
4 changes: 3 additions & 1 deletion examples/get-workflow-metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from datetime import datetime
from typing import List

import pandas as pd
from indico import IndicoConfig, IndicoClient

from indico import IndicoClient, IndicoConfig
from indico.queries import ListWorkflows
from indico.queries.workflow_metrics import GetWorkflowMetrics
from indico.types.workflow_metrics import WorkflowMetrics, WorkflowMetricsOptions
Expand Down
1 change: 0 additions & 1 deletion examples/graphql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from indico import IndicoClient, IndicoConfig
from indico.queries import GraphQLRequest


my_config = IndicoConfig(
host="try.indico.io", api_token_path="./path/to/indico_api_token.txt"
)
Expand Down
6 changes: 3 additions & 3 deletions examples/train-classification-model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from indico import IndicoClient, IndicoConfig
from indico.queries import (
CreateDataset,
ModelGroupPredict,
AddModelGroupComponent,
JobStatus,
CreateDataset,
GetModelGroupSelectedModelStatus,
JobStatus,
ModelGroupPredict,
)

# Create an Indico API client
Expand Down
Loading