Skip to content

Commit

Permalink
Added pylint in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard d'Archimbaud authored and marcenacp committed Sep 17, 2021
1 parent a5df448 commit c552b88
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 30 deletions.
582 changes: 582 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions .travis.yml
Expand Up @@ -106,3 +106,19 @@ jobs:
env:
- DOCKER_IMAGE=continuumio/anaconda3:2020.02
- NOTEBOOK_PATH=recipes/getting-started/getting_started-image_classification.ipynb
- &test-pylint
stage: Test *.py with pylint
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker pull ${DOCKER_IMAGE}
- |
docker run \
${DOCKER_IMAGE} /bin/sh -c "cd /root && \
apt-get update && apt-get install -y gcc && \
git clone --branch ${TRAVIS_BRANCH} https://github.com/kili-technology/kili-playground.git && \
pip install pylint && \
cd kili-playground && \
pip install -r requirements.txt && \
pylint kili"
env:
- DOCKER_IMAGE=continuumio/anaconda3:2020.02
8 changes: 4 additions & 4 deletions kili/graphql_client.py
Expand Up @@ -80,15 +80,15 @@ def _send(self, query, variables):
return req.json()
except Exception as exception:
if req is not None:
raise Exception(req.content)
raise Exception(req.content) from exception
raise exception

req = urllib.request.Request(
self.endpoint, json.dumps(data).encode('utf-8'), headers)
try:
response = urllib.request.urlopen(req)
str_json = response.read().decode('utf-8')
return json.loads(str_json)
with urllib.request.urlopen(req) as response:
str_json = response.read().decode('utf-8')
return json.loads(str_json)
except urllib.error.HTTPError as error:
print((error.read()))
print('')
Expand Down
10 changes: 5 additions & 5 deletions kili/helpers.py
Expand Up @@ -44,10 +44,10 @@ def __call__(self, resolver, *args, **kwargs):
def checked_resolver(*args, **kwargs):
try:
client_endpoint = args[0].auth.client.endpoint
except:
except Exception as exception:
raise ValueError(
'Cannot find client endpoint from resolver' \
f' {resolver.__name__} with arguments {args}')
f' {resolver.__name__} with arguments {args}') from exception
if self.client_is_compatible(client_endpoint):
return resolver(*args, **kwargs)
raise EndpointCompatibilityError(
Expand Down Expand Up @@ -154,17 +154,17 @@ def format_json_dict(result):
if key in ['jsonInterface', 'jsonMetadata', 'jsonResponse', 'rules']:
if (value == '' or value is None) \
and not (is_url(value) and key == 'jsonInterface'):
result[key] = dict()
result[key] = {}
elif isinstance(value, str):
try:
if is_url(value):
result[key] = requests.get(value).json()
else:
result[key] = loads(value)
except:
except Exception as exception:
raise ValueError(
'Json Metadata / json response /' \
' json interface / rules should be valid jsons')
' json interface / rules should be valid jsons') from exception
else:
result[key] = format_json(value)
return result
Expand Down
2 changes: 1 addition & 1 deletion kili/mutations/asset/__init__.py
Expand Up @@ -112,7 +112,7 @@ def append_many_to_dataset(

if content_array is None and json_content_array is None:
raise ValueError(
f"Variables content_array and json_content_array cannot be both None.")
"Variables content_array and json_content_array cannot be both None.")
if content_array is None:
content_array = [''] * len(json_content_array)
if external_id_array is None:
Expand Down
4 changes: 2 additions & 2 deletions kili/mutations/project/queries.py
Expand Up @@ -78,7 +78,7 @@
}}
'''

GQL_MAKE_PROJECT_PUBLIC = f'''
GQL_MAKE_PROJECT_PUBLIC = '''
mutation(
$projectID: ID!
) {{
Expand Down Expand Up @@ -153,7 +153,7 @@
}}
'''

GQL_PROJECT_DELETE_ASYNCHRONOUSLY = f'''
GQL_PROJECT_DELETE_ASYNCHRONOUSLY = '''
mutation($projectID: ID!) {{
data: deleteProjectAsynchronously(where: {{
id: $projectID
Expand Down
4 changes: 2 additions & 2 deletions kili/orm.py
Expand Up @@ -10,7 +10,7 @@ class DictClass(dict):
"""

def __init__(self, *args, **kwargs):
super(DictClass, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.__dict__ = self

@dataclass
Expand Down Expand Up @@ -142,7 +142,7 @@ class Asset(DictClass):
"""

def __init__(self, *args, **kwargs):
super(Asset, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if 'labels' in self:
labels = []
for label in self['labels']:
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/asset/queries.py
Expand Up @@ -14,7 +14,7 @@ def gql_assets(fragment):
}}
'''

GQL_ASSETS_COUNT = f'''
GQL_ASSETS_COUNT = '''
query($where: AssetWhere!) {{
data: countAssets(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/dataset_asset/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_assets(fragment):
'''


GQL_DATASET_ASSETS_COUNT = f'''
GQL_DATASET_ASSETS_COUNT = '''
query($where: DatasetAssetWhere!) {{
data: countDatasetAssets(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/issue/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_issues(fragment):
'''


GQL_LABELS_COUNT = f'''
GQL_LABELS_COUNT = '''
query($where: IssueWhere!) {{
data: countIssues(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/label/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_labels(fragment):
'''


GQL_LABELS_COUNT = f'''
GQL_LABELS_COUNT = '''
query($where: LabelWhere!) {{
data: countLabels(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/lock/queries.py
Expand Up @@ -14,7 +14,7 @@ def gql_locks(fragment):
}}
'''

GQL_LOCKS_COUNT = f'''
GQL_LOCKS_COUNT = '''
query($where: LockWhere!) {{
data: countLocks(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/notification/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_notifications(fragment):
'''


GQL_NOTIFICATIONS_COUNT = f'''
GQL_NOTIFICATIONS_COUNT = '''
query($where: NotificationWhere!) {{
data: countNotifications(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/organization/queries.py
Expand Up @@ -14,7 +14,7 @@ def gql_organizations(fragment):
}}
'''

GQL_ORGANIZATIONS_COUNT = f'''
GQL_ORGANIZATIONS_COUNT = '''
query($where: OrganizationWhere!) {{
data: countOrganizations(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/project/queries.py
Expand Up @@ -14,7 +14,7 @@ def gql_projects(fragment: str):
}}
'''

GQL_PROJECTS_COUNT = f'''
GQL_PROJECTS_COUNT = '''
query($where: ProjectWhere!) {{
data: countProjects(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/project_user/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_project_users(fragment):
'''


GQL_PROJECT_USERS_COUNT = f'''
GQL_PROJECT_USERS_COUNT = '''
query($where: ProjectUserWhere!) {{
data: countProjectUsers(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/project_version/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_project_version(fragment):
'''


GQL_PROJECT_VERSION_COUNT = f'''
GQL_PROJECT_VERSION_COUNT = '''
query($where: ProjectVersionWhere!) {{
data: countProjectVersions(where: $where)
}}
Expand Down
2 changes: 1 addition & 1 deletion kili/queries/user/queries.py
Expand Up @@ -15,7 +15,7 @@ def gql_users(fragment):
'''


GQL_USERS_COUNT = f'''
GQL_USERS_COUNT = '''
query($where: UserWhere!) {{
data: countUsers(where: $where)
}}
Expand Down
11 changes: 6 additions & 5 deletions kili/transfer_learning.py
Expand Up @@ -88,9 +88,10 @@ def launch_train(self):
if len(self.assets_seen_in_training) == 0:
filtered_assets_to_train = assets_to_train
else:
filtered_assets_to_train = [asset for asset in assets_to_train
if all([asset['id'] not in training
for training in self.assets_seen_in_training])]
filtered_assets_to_train = [
asset for asset in assets_to_train
if all([asset['id'] not in training # pylint: disable=use-a-generator
for training in self.assets_seen_in_training])]
if len(filtered_assets_to_train) >= self.minimum_number_of_assets_to_launch_training:
TransferLearning.train(filtered_assets_to_train)
self.current_training_number += 1
Expand Down Expand Up @@ -139,8 +140,8 @@ def launch_tensorboard():
Launches the tensorboard
"""
print('Starting Tensorboard...')
subprocess.Popen(['tensorboard', '--logdir=runs'])
print('You can access Tensorboard at http://localhost:6006\n')
with subprocess.Popen(['tensorboard', '--logdir=runs']):
print('You can access Tensorboard at http://localhost:6006\n')

def launch(self):
"""
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
@@ -0,0 +1,6 @@
pandas==1.2.5
requests
six
tqdm
typeguard
websocket-client

0 comments on commit c552b88

Please sign in to comment.