Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1820)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/scop/pre-commit-shfmt: v3.10.0-1 → v3.10.0-2](scop/pre-commit-shfmt@v3.10.0-1...v3.10.0-2)
- [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.9.1](astral-sh/ruff-pre-commit@v0.7.2...v0.9.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix some linting errors

* fixing format specifiers

* fixing format specifiers

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: shankar ambady <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and shanbady authored Jan 17, 2025
1 parent a4802a1 commit d317078
Show file tree
Hide file tree
Showing 37 changed files with 95 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
html,
]
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.10.0-1
rev: v3.10.0-2
hooks:
- id: shfmt
- repo: https://github.com/adrienverge/yamllint.git
Expand Down Expand Up @@ -74,7 +74,7 @@ repos:
- ".*/generated/"
additional_dependencies: ["gibberish-detector"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.9.1"
hooks:
- id: ruff-format
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions ai_chat/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ChatMessageFactory(factory.Factory):

role = FuzzyChoice(MessageRole.USER, MessageRole.ASSISTANT)
content = factory.Faker("sentence")
id = name = factory.Sequence(lambda n: "%d" % n)
index = factory.Sequence(lambda n: "%d" % n)
id = name = factory.Sequence(lambda n: str(n))
index = factory.Sequence(lambda n: str(n))

class Meta:
model = ChatMessage
2 changes: 1 addition & 1 deletion authentication/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def process_exception(self, request, exception):

if url:
url += (
"?" in url and "&" or "?"
("?" in url and "&") or "?"
) + f"message={quote(message)}&backend={backend_name}"
return redirect(url)
return None
Expand Down
2 changes: 1 addition & 1 deletion channels/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_create_channel(base_channel_data, channel_detail, channel_type):
"""
paths = sorted(
(p.learning_resource for p in LearningPathFactory.create_batch(2)),
key=lambda list: list.id, # noqa: A002
key=lambda lst: lst.id,
reverse=True,
)

Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.fixture(autouse=True)
def prevent_requests(mocker, request): # noqa: PT004
def prevent_requests(mocker, request):
"""Patch requests to error on request by default"""
if "mocked_responses" in request.fixturenames:
return
Expand Down
4 changes: 2 additions & 2 deletions fixtures/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


@pytest.fixture(autouse=True)
def silence_s3_logging(): # noqa: PT004
def silence_s3_logging():
"""Only show S3 errors"""
logging.getLogger("botocore").setLevel(logging.ERROR)


@pytest.fixture
def mock_s3_fixture(): # noqa: PT004
def mock_s3_fixture():
"""Mock the S3 fixture for the duration of the test"""
with mock_aws():
yield
Expand Down
8 changes: 4 additions & 4 deletions fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@


@pytest.fixture(autouse=True)
def silence_factory_logging(): # noqa: PT004
def silence_factory_logging():
"""Only show factory errors"""
logging.getLogger("factory").setLevel(logging.ERROR)


@pytest.fixture(autouse=True)
def warnings_as_errors(): # noqa: PT004
def warnings_as_errors():
"""
Convert warnings to errors. This should only affect unit tests, letting pylint and other plugins
raise DeprecationWarnings without erroring.
Expand All @@ -53,7 +53,7 @@ def warnings_as_errors(): # noqa: PT004


@pytest.fixture
def randomness(): # noqa: PT004
def randomness():
"""Ensure a fixed seed for factoryboy"""
factory.fuzzy.reseed_random("happy little clouds")

Expand Down Expand Up @@ -95,7 +95,7 @@ def mocked_responses():


@pytest.fixture
def offeror_featured_lists(): # noqa: PT004
def offeror_featured_lists():
"""Generate featured offeror lists for testing"""
for offered_by in OfferedBy.names():
offeror = LearningResourceOfferorFactory.create(code=offered_by)
Expand Down
26 changes: 13 additions & 13 deletions learning_resources/etl/loaders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ def test_load_course( # noqa: PLR0913,PLR0912,PLR0915
"start_date": old_run.start_date,
"end_date": old_run.end_date,
"prices": [
{"amount": Decimal(30.00), "currency": CURRENCY_USD},
{"amount": Decimal(120.00), "currency": CURRENCY_USD},
{"amount": Decimal("30.00"), "currency": CURRENCY_USD},
{"amount": Decimal("120.00"), "currency": CURRENCY_USD},
],
},
{
Expand All @@ -384,8 +384,8 @@ def test_load_course( # noqa: PLR0913,PLR0912,PLR0915
"start_date": start_date,
"end_date": run.end_date,
"prices": [
{"amount": Decimal(0.00), "currency": CURRENCY_USD},
{"amount": Decimal(49.00), "currency": CURRENCY_USD},
{"amount": Decimal("0.00"), "currency": CURRENCY_USD},
{"amount": Decimal("49.00"), "currency": CURRENCY_USD},
],
},
]
Expand All @@ -403,12 +403,12 @@ def test_load_course( # noqa: PLR0913,PLR0912,PLR0915
)
assert result.next_start_date == expected_next_start_date
assert result.prices == (
[Decimal(0.00), Decimal(49.00)]
[Decimal("0.00"), Decimal("49.00")]
if is_run_published and result.certification
else []
)
assert [price.amount for price in result.resource_prices.all()] == (
[Decimal(0.00), Decimal(49.00)]
[Decimal("0.00"), Decimal("49.00")]
if is_run_published and result.certification
else []
)
Expand Down Expand Up @@ -563,9 +563,9 @@ def test_load_duplicate_course(

for key, value in props.items():
assert getattr(result, key) == value, f"Property {key} should equal {value}"
assert (
getattr(saved_course, key) == value
), f"Property {key} should be updated to {value} in the database"
assert getattr(saved_course, key) == value, (
f"Property {key} should be updated to {value} in the database"
)


@pytest.mark.parametrize("unique_url", [True, False])
Expand Down Expand Up @@ -695,7 +695,7 @@ def test_load_run(run_exists, status, certification):
if run_exists
else LearningResourceRunFactory.build()
)
prices = [Decimal(70.00), Decimal(20.00)]
prices = [Decimal("70.00"), Decimal("20.00")]
props = model_to_dict(
LearningResourceRunFactory.build(
run_id=learning_resource_run.run_id,
Expand Down Expand Up @@ -964,9 +964,9 @@ def test_load_content_file():
assert loaded_file.run == learning_resource_run

for key, value in props.items():
assert (
getattr(loaded_file, key) == value
), f"Property {key} should equal {value}"
assert getattr(loaded_file, key) == value, (
f"Property {key} should equal {value}"
)


def test_load_image():
Expand Down
6 changes: 3 additions & 3 deletions learning_resources/etl/mitpe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
2123, 4, 25, 4, 0, tzinfo=datetime.UTC
),
"published": True,
"prices": [{"amount": Decimal(1870), "currency": "USD"}],
"prices": [{"amount": Decimal("1870"), "currency": "USD"}],
"url": "https://professional.mit.edu/course-catalog/comunicacao-persuasiva-pensamento-critico-para-aprimorar-mensagem-portuguese",
"instructors": [{"full_name": "Edward Schiappa"}, {"full_name": ""}],
"format": [Format.asynchronous.name],
Expand Down Expand Up @@ -102,7 +102,7 @@
2123, 6, 17, 4, 0, tzinfo=datetime.UTC
),
"published": True,
"prices": [{"amount": Decimal(3600), "currency": "USD"}],
"prices": [{"amount": Decimal("3600"), "currency": "USD"}],
"url": "https://professional.mit.edu/course-catalog/design-thinking-and-innovation-technical-leaders",
"instructors": [
{"full_name": "Blade Kotelly"},
Expand Down Expand Up @@ -154,7 +154,7 @@
2123, 7, 6, 4, 0, tzinfo=datetime.UTC
),
"published": True,
"prices": [{"amount": Decimal(1870), "currency": "USD"}],
"prices": [{"amount": Decimal("1870"), "currency": "USD"}],
"url": "https://professional.mit.edu/course-catalog/manufatura-inteligente-producao-na-industria-40-portuguese",
"instructors": [{"full_name": ""}, {"full_name": "Brian Anthony"}],
"format": [Format.asynchronous.name],
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/mitxonline.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _transform_run(course_run: dict, course: dict) -> dict:
transform_price(price)
for price in sorted(
{
Decimal(0.00),
Decimal("0.00"),
*[
Decimal(price)
for price in [
Expand Down
10 changes: 5 additions & 5 deletions learning_resources/etl/openedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ def _transform_course_commitment(course_run) -> CommitmentConfig:
)
if min_effort or max_effort:
return CommitmentConfig(
commitment=f"{
commit_str_prefix}{max_effort or min_effort
} hour{'s' if max_effort > 1 else ''}/week",
commitment=f"{commit_str_prefix}{max_effort or min_effort} hour{
's' if max_effort > 1 else ''
}/week",
min_weekly_hours=min(min_effort, max_effort),
max_weekly_hours=max(min_effort, max_effort),
)
Expand Down Expand Up @@ -411,7 +411,7 @@ def _get_course_price(course):
if seat["price"] != "0.00"
]
), run.get("seats", [{}])[0].get("currency", CURRENCY_USD)
return Decimal(0.00), CURRENCY_USD
return Decimal("0.00"), CURRENCY_USD

prices_currencies = [
_get_course_price(course) for course in program.get("courses", [])
Expand Down Expand Up @@ -464,7 +464,7 @@ def _transform_course_run(config, course_run, course_last_modified, marketing_ur
transform_price(price, currency)
for (price, currency) in sorted(
{
(Decimal(0.00), CURRENCY_USD),
(Decimal("0.00"), CURRENCY_USD),
*[
(Decimal(seat.get("price")), seat.get("currency"))
for seat in course_run.get("seats", [])
Expand Down
10 changes: 5 additions & 5 deletions learning_resources/etl/podcast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def mock_podcast_file( # pylint: disable=too-many-arguments # noqa: PLR0913

content = f"""---
rss_url: {rss_url}
{ "podcast_title: " + podcast_title if podcast_title else "" }
{ "topics: " + topics if topics else "" }
{ "offered_by: " + offered_by if offered_by else "" }
{"podcast_title: " + podcast_title if podcast_title else ""}
{"topics: " + topics if topics else ""}
{"offered_by: " + offered_by if offered_by else ""}
website: {website_url}
google_podcasts_url: {google_podcasts_url}
apple_podcasts_url: {apple_podcasts_url}
Expand All @@ -64,7 +64,7 @@ def mock_podcast_file( # pylint: disable=too-many-arguments # noqa: PLR0913


@pytest.fixture
def mock_rss_request(mocker): # noqa: PT004
def mock_rss_request(mocker):
"""
Mock request data
"""
Expand All @@ -76,7 +76,7 @@ def mock_rss_request(mocker): # noqa: PT004


@pytest.fixture
def mock_rss_request_with_bad_rss_file(mocker): # noqa: PT004
def mock_rss_request_with_bad_rss_file(mocker):
"""
Mock request data
"""
Expand Down
3 changes: 1 addition & 2 deletions learning_resources/etl/posthog.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def load_posthog_lrd_view_event(
return None
except ValueError:
skip_warning = (
f"WARNING: skipping event for resource ID {event.resourceId}"
" - invalid ID"
f"WARNING: skipping event for resource ID {event.resourceId} - invalid ID"
)
log.warning(skip_warning)
return None
Expand Down
6 changes: 3 additions & 3 deletions learning_resources/etl/prolearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def transform_programs(programs: list[dict]) -> list[dict]:
runs = _transform_runs(program)
if platform and runs:
transformed_program = {
"readable_id": f'prolearn-{platform}-{program["nid"]}',
"readable_id": f"prolearn-{platform}-{program['nid']}",
"title": program["title"],
"description": clean_data(program["body"]),
"offered_by": {"name": offered_by.name} if offered_by else None,
Expand Down Expand Up @@ -328,7 +328,7 @@ def _transform_runs(resource: dict) -> list[dict]:
if start_date and start_date >= now_in_utc():
runs.append(
{
"run_id": f'{resource["nid"]}_{start_value}',
"run_id": f"{resource['nid']}_{start_value}",
"title": resource["title"],
"image": parse_image(resource),
"description": clean_data(resource["body"]),
Expand Down Expand Up @@ -361,7 +361,7 @@ def _transform_course(
runs = _transform_runs(course)
if len(runs) > 0:
return {
"readable_id": f'prolearn-{platform}-{course["nid"]}',
"readable_id": f"prolearn-{platform}-{course['nid']}",
"offered_by": {"name": offered_by.name} if offered_by else None,
"platform": platform,
"etl_source": ETLSource.prolearn.name,
Expand Down
4 changes: 2 additions & 2 deletions learning_resources/etl/prolearn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def test_parse_date(date_int, expected_dt):
@pytest.mark.parametrize(
("price_str", "expected_price"),
[
["$5,342", round(Decimal(5342), 2)], # noqa: PT007
["5.34", round(Decimal(5.34), 2)], # noqa: PT007
["$5,342", round(Decimal("5342"), 2)], # noqa: PT007
["5.34", round(Decimal("5.34"), 2)], # noqa: PT007
[None, None], # noqa: PT007
["", None], # noqa: PT007
],
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/sloan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


@pytest.fixture(autouse=True)
def mock_sloan_api_setting(settings): # noqa: PT004
def mock_sloan_api_setting(settings):
"""Set the prolearn api url"""
settings.SEE_API_URL = "http://localhost/test/programs/api"
settings.SEE_API_CLIENT_ID = "test"
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def text_from_srt_content(content: str):

def text_from_sjson_content(content: str):
"""
return text from sjson content
Return text from sjson content
Args:
content (str): The sjson content
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/youtube_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def mock_channel_file(content):


@pytest.fixture
def mocked_github_channel_response(mocker): # noqa: PT004
def mocked_github_channel_response(mocker):
"""Mock response from github api requst to open-video-data"""

mock_file = mock_channel_file(
Expand Down
Loading

0 comments on commit d317078

Please sign in to comment.