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

Remove use of deprecated imp module in job system. #1717

Merged
merged 2 commits into from
Jun 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions django_extensions/management/jobs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import os
import sys
from imp import find_module
import importlib
from typing import Optional # NOQA
from django.apps import apps

Expand Down Expand Up @@ -72,17 +72,15 @@ def find_jobs(jobs_dir):
return []


def find_job_module(app_name, when=None):
def find_job_module(app_name: str, when: Optional[str] = None) -> str:
"""Find the directory path to a job module."""
parts = app_name.split('.')
parts.append('jobs')
if when:
parts.append(when)
parts.reverse()
path = None
while parts:
part = parts.pop()
f, path, descr = find_module(part, path and [path] or None)
return path
module_name = ".".join(parts)
module = importlib.import_module(module_name)
return module.__path__[0]


def import_job(app_name, name, when=None):
Expand Down