Skip to content

Commit fb6b533

Browse files
committed
non-top-level imports
1 parent ed1b70f commit fb6b533

File tree

6 files changed

+8
-32
lines changed

6 files changed

+8
-32
lines changed

channels/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ def ready(self):
1212
"""
1313
Ready handler. Import signals.
1414
"""
15-
import channels.signals # noqa: F401
16-
from channels import schema # noqa: F401
15+
import channels.signals # noqa: F401,PLC0415
16+
from channels import schema # noqa: F401,PLC0415

learning_resources/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class LearningResourcesConfig(AppConfig):
1212
hookspec = HookspecMarker(name)
1313

1414
def ready(self):
15-
from learning_resources import schema # noqa: F401
15+
from learning_resources import schema # noqa: F401,PLC0415

learning_resources/etl/canvas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from learning_resources.constants import LearningResourceType
1010
from learning_resources.etl.constants import ETLSource
11+
from learning_resources.etl.loaders import load_content_files
1112
from learning_resources.etl.utils import _process_olx_path, calc_checksum
1213
from learning_resources.models import LearningResource, LearningResourceRun
1314

@@ -18,8 +19,6 @@ def sync_canvas_archive(bucket, key: str, overwrite):
1819
"""
1920
Sync a Canvas course archive from S3
2021
"""
21-
from learning_resources.etl.loaders import load_content_files
22-
2322
with TemporaryDirectory() as export_tempdir:
2423
course_archive_path = Path(export_tempdir, key.split("/")[-1])
2524
bucket.download_file(key, course_archive_path)

learning_resources/models.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.db.models.functions import Lower
1414
from django.utils import timezone
1515

16+
from channels.models import Channel
1617
from learning_resources import constants
1718
from learning_resources.constants import (
1819
Availability,
@@ -69,8 +70,6 @@ def for_serialization(self):
6970

7071
def annotate_channel_url(self):
7172
"""Annotate with the channel url"""
72-
from channels.models import Channel
73-
7473
return self.annotate(
7574
channel_url=(
7675
Channel.objects.filter(topic_detail__topic=OuterRef("pk"))
@@ -135,8 +134,6 @@ def for_serialization(self):
135134

136135
def annotate_channel_url(self):
137136
"""Annotate with the channel url"""
138-
from channels.models import Channel
139-
140137
return self.annotate(
141138
channel_url=(
142139
Channel.objects.filter(unit_detail__unit=OuterRef("pk"))
@@ -253,8 +250,6 @@ def for_serialization(self, *, prefetch_school: bool = False):
253250

254251
def annotate_channel_url(self):
255252
"""Annotate the queryset with channel_url"""
256-
from channels.models import Channel
257-
258253
return self.annotate(
259254
channel_url=(
260255
Channel.objects.filter(department_detail__department=OuterRef("pk"))
@@ -281,8 +276,6 @@ class LearningResourceDepartment(TimestampedModel):
281276
@cached_property
282277
def channel_url(self) -> str | None:
283278
"""Get the channel url for the department if it exists"""
284-
from channels.models import Channel
285-
286279
channel = Channel.objects.filter(department_detail__department=self).first()
287280
return channel.channel_url if channel is not None else None
288281

learning_resources/views_test.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
VideoPlaylistFactory,
3838
)
3939
from learning_resources.models import (
40+
LearningResource,
4041
LearningResourceOfferor,
4142
LearningResourceRelationship,
4243
PodcastEpisode,
@@ -54,6 +55,7 @@
5455
VideoResourceSerializer,
5556
VideoSerializer,
5657
)
58+
from learning_resources.views import CourseViewSet
5759
from learning_resources_search.api import Search
5860
from learning_resources_search.serializers import serialize_learning_resource_for_update
5961

@@ -209,7 +211,6 @@ def test_no_excess_queries(rf, user, mocker, django_assert_num_queries, course_c
209211
There should be a constant number of queries made (based on number of
210212
related models), regardless of number of results returned.
211213
"""
212-
from learning_resources.views import CourseViewSet
213214

214215
CourseFactory.create_batch(course_count)
215216

@@ -1092,8 +1093,6 @@ def test_featured_view_filter(client, offeror_featured_lists, parameter):
10921093

10931094
def test_similar_resources_endpoint_does_not_return_self(mocker, client):
10941095
"""Test similar learning_resources endpoint does not return initial resource"""
1095-
from learning_resources.models import LearningResource
1096-
10971096
resources = LearningResourceFactory.create_batch(5)
10981097

10991098
resource_ids = [learning_resource.id for learning_resource in resources]
@@ -1127,8 +1126,6 @@ def test_similar_resources_endpoint_does_not_return_self(mocker, client):
11271126

11281127
def test_similar_resources_endpoint_only_returns_published(mocker, client):
11291128
"""Test similar learning_resources endpoint only returns published items"""
1130-
from learning_resources.models import LearningResource
1131-
11321129
resources = LearningResourceFactory.create_batch(5)
11331130

11341131
resource_ids = [learning_resource.id for learning_resource in resources]
@@ -1170,8 +1167,6 @@ def test_similar_resources_endpoint_only_returns_published(mocker, client):
11701167

11711168
def test_similar_resources_endpoint_ignores_opensearch_published(mocker, client):
11721169
"""Test similar learning_resources ignores the published attribute from opensearch"""
1173-
from learning_resources.models import LearningResource
1174-
11751170
resources = LearningResourceFactory.create_batch(5)
11761171

11771172
resource_ids = [learning_resource.id for learning_resource in resources]
@@ -1209,8 +1204,6 @@ def test_similar_resources_endpoint_ignores_opensearch_published(mocker, client)
12091204

12101205
def test_vector_similar_resources_endpoint_does_not_return_self(mocker, client):
12111206
"""Test vector based similar resources endpoint does not return initial id"""
1212-
from learning_resources.models import LearningResource
1213-
12141207
resources = LearningResourceFactory.create_batch(5)
12151208

12161209
resource_ids = [learning_resource.id for learning_resource in resources]
@@ -1241,8 +1234,6 @@ def test_vector_similar_resources_endpoint_does_not_return_self(mocker, client):
12411234

12421235
def test_vector_similar_resources_endpoint_only_returns_published(mocker, client):
12431236
"""Test vector based similar resources endpoint only returns published items"""
1244-
from learning_resources.models import LearningResource
1245-
12461237
resources = LearningResourceFactory.create_batch(5)
12471238

12481239
resource_ids = [learning_resource.id for learning_resource in resources]
@@ -1279,8 +1270,6 @@ def test_vector_similar_resources_endpoint_only_returns_published(mocker, client
12791270

12801271
def test_learning_resources_display_info_list_view(mocker, client):
12811272
"""Test learning_resources_display_info_list_view returns expected results"""
1282-
from learning_resources.models import LearningResource
1283-
12841273
LearningResource.objects.all().delete()
12851274
resources = LearningResourceFactory.create_batch(
12861275
5, published=True, title="test_learning_resources_display_info_list_view"
@@ -1309,8 +1298,6 @@ def test_learning_resources_display_info_list_view(mocker, client):
13091298

13101299
def test_run_with_null_prices_does_not_throw_error(mocker, client):
13111300
"""Test learning_resources_display_info_detail_view does not throw exception"""
1312-
from learning_resources.models import LearningResource
1313-
13141301
run = LearningResourceRunFactory.create(
13151302
run_id="test",
13161303
learning_resource=CourseFactory.create(
@@ -1338,8 +1325,6 @@ def test_run_with_null_prices_does_not_throw_error(mocker, client):
13381325

13391326
def test_learning_resources_display_info_detail_view(mocker, client):
13401327
"""Test learning_resources_display_info_detail_view returns expected result"""
1341-
from learning_resources.models import LearningResource
1342-
13431328
resource = LearningResource.objects.for_search_serialization().get(
13441329
id=LearningResourceFactory.create().id
13451330
)

learning_resources_search/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
document_percolated_actions,
3737
)
3838
from vector_search.constants import RESOURCES_COLLECTION_NAME
39+
from vector_search.utils import dense_encoder, qdrant_client, vector_point_id
3940

4041
log = logging.getLogger(__name__)
4142

@@ -923,8 +924,6 @@ def _qdrant_similar_results(doc, num_resources):
923924
list of dict:
924925
list of serialized resources
925926
"""
926-
from vector_search.utils import dense_encoder, qdrant_client, vector_point_id
927-
928927
encoder = dense_encoder()
929928
client = qdrant_client()
930929
return [

0 commit comments

Comments
 (0)