Skip to content

Commit

Permalink
Add meta-test to ensure all .py files follow PEP 563 (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored Aug 18, 2023
1 parent d45b7e8 commit 8d613cb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions cognite/client/_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
2 changes: 2 additions & 0 deletions cognite/client/_api/data_modeling/_data_modeling_executor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from concurrent.futures import ThreadPoolExecutor

from cognite.client.utils._concurrency import ConcurrencySettings, MainThreadExecutor, TaskExecutor
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/data_classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from cognite.client.data_classes.annotations import (
Annotation,
AnnotationFilter,
Expand Down
1 change: 1 addition & 0 deletions cognite/client/data_classes/annotation_types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
2 changes: 2 additions & 0 deletions cognite/client/data_classes/data_modeling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from cognite.client.data_classes import filters
from cognite.client.data_classes.data_modeling import aggregations, query
from cognite.client.data_classes.data_modeling.aggregations import AggregatedValue, Aggregation
Expand Down
6 changes: 0 additions & 6 deletions cognite/client/utils/_auxiliary.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""Utilities for Cognite API SDK
This module provides helper methods and different utilities for the Cognite API Python SDK.
This module is protected and should not be used by end-users.
"""
from __future__ import annotations

import functools
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/utils/_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Dict, List, Set, Tuple


Expand Down
17 changes: 17 additions & 0 deletions tests/tests_unit/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ def test_assert_no_root_init_file():
# or uses a pkgutil-style __init__.py. If any distribution does not, it will cause the namespace logic to
# fail and the other sub-packages will not be importable"
assert not Path("cognite/__init__.py").exists()


def test_ensure_all_files_use_future_annots():
def keep(path):
skip_list = [
"_pb2.py", # Auto-generated, dislikes changes ;)
"cognite/client/utils/_priority_tpe.py", # Module docstring at the top takes priority
]
return all(skip not in str(path.as_posix()) for skip in skip_list)

all_filepaths = filter(keep, Path("cognite/client/").glob("**/*.py"))
err_msg = "File: '{}' is missing 'from __future__ import annotations' at line=0"

for filepath in all_filepaths:
with filepath.open("r") as file:
# We just read the first line from each file:
assert file.readline() == "from __future__ import annotations\n", err_msg.format(filepath)

0 comments on commit 8d613cb

Please sign in to comment.