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

Use full names for lms.djangoapps imports #25401

Merged
merged 26 commits into from
Nov 4, 2020

Conversation

kdmccormick
Copy link
Member

@kdmccormick kdmccormick commented Oct 22, 2020

Overview

Part of the sys.path modification removal & cleanup, started by https://github.com/edx/edx-platform/pull/24616 . See the ADR for details.

This PR fixes all imports of LMS djangoapps to use the preferred style (import lms.djangoapps.myapp..) instead of the deprecated short version (import myapp...). It also un-silences the deprecated-import warnings so that we can see whether any installed packages are using the deprecated imports. Each LMS djangoapp's imports are fixed in their own commit.

Related, rename sys_path_hacks to import_shims [MERGED]

Next up, remove sys.path hack for common/djangoapps.

Desired end goal

General approach

I repeated the following approach for each top-level folder in lms/djangoapps, notated here as {APPNAME}:

First, replace from {APPNAME} import {X} with from lms.djangoapps.{APPNAME} import {X}. Using Sublime Text Find+Replace:

Find:
^( *)from {APPNAME}\b
Replace:
\1from lms.djangoapps.{APPNAME}

Then, search for instances of import {APPNAME}...

Find:
^( *)import {APPNAME}\b

and manually fix them. The manual fixes are required here because import without from or as causes the module to imported with its qualified name, so changing the qualified name requires also changing code in the module.

Finally, search for references to the old import path by string (patches, INSTALLED_APPS, etc.):

Find:
(['"]){APPNAME}\b

and comb through the output, fixing any references to the old import path. This involves making judgement calls as to what is an import path versus something different (like, a cache key or URL name).

isort

Sorting imports as part of this PR isn't necessary, but it should make the import block much more readable, especially now that many of the names have changed and any previous manual alphabetization efforts have been messed up.

So, I'm going to include one big isort commit at the end isort everything in a PR after this one.

(In the CMS PR, I was able to sort import within cms/ without only some minor isort:skip additions, but that folder much smaller and less magic-filled than lms/, common/, and openedx/.)

@kdmccormick kdmccormick marked this pull request as draft October 22, 2020 01:29
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch 2 times, most recently from 76a7b72 to f9b3e49 Compare October 26, 2020 14:46
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch 3 times, most recently from 7bd0d30 to f254793 Compare October 26, 2020 16:25
@kdmccormick kdmccormick marked this pull request as ready for review October 26, 2020 16:25
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch 2 times, most recently from be6c3bb to c0c3a0b Compare October 26, 2020 20:51
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch from c0c3a0b to 42952d4 Compare October 28, 2020 12:50
@kdmccormick
Copy link
Member Author

jenkins run python

@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch 2 times, most recently from 12a9750 to af2e820 Compare November 2, 2020 14:18
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch from af2e820 to f644572 Compare November 3, 2020 22:24
@kdmccormick kdmccormick force-pushed the kdmccormick/sys-path-hacks-lms-cleanup branch from f644572 to 7050e60 Compare November 3, 2020 23:42
@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@kdmccormick kdmccormick merged commit d1a775d into master Nov 4, 2020
@kdmccormick kdmccormick deleted the kdmccormick/sys-path-hacks-lms-cleanup branch November 4, 2020 13:48
@kdmccormick
Copy link
Member Author

FYI @davidjoy. I expect this to be on prod around 9:45; I'll be keeping a close eye on it.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants