Skip to content

Commit

Permalink
refactor: make safe_lxml an ordinary folder in openedx/core/lib (open…
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick authored May 24, 2022
1 parent 2ef25e3 commit 25df9ca
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cms/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs

defuse_xml_libs()

Expand Down
2 changes: 1 addition & 1 deletion cms/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from openedx.core.pytest_hooks import DeferPlugin

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs # isort:skip # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip
defuse_xml_libs()


Expand Down
2 changes: 1 addition & 1 deletion cms/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs
defuse_xml_libs()

import os # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
Expand Down
2 changes: 1 addition & 1 deletion common/lib/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs

# This import is needed for pytest plugin configuration, so please avoid deleting this during refactoring
from openedx.core.pytest_hooks import pytest_configure # pylint: disable=unused-import
Expand Down
16 changes: 0 additions & 16 deletions common/lib/safe_lxml/setup.py

This file was deleted.

4 changes: 3 additions & 1 deletion common/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Code run by pylint before running any tests."""
from safe_lxml import defuse_xml_libs

# Patch the xml libs before anything else.
from openedx.core.lib.safe_lxml import defuse_xml_libs

defuse_xml_libs()
2 changes: 0 additions & 2 deletions docs/guides/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
sys.path.insert(0, root)
sys.path.append(root / "docs/guides")
sys.path.append(root / "common/lib/capa")
sys.path.append(root / "common/lib/safe_lxml")
sys.path.append(root / "common/lib/xmodule")

# Use a settings module that allows all LMS and Studio code to be imported
Expand Down Expand Up @@ -223,7 +222,6 @@
modules = {
'cms': 'cms',
'common/lib/capa/capa': 'common/lib/capa',
'common/lib/safe_lxml/safe_lxml': 'common/lib/safe_lxml',
'common/lib/xmodule/xmodule': 'common/lib/xmodule',
'lms': 'lms',
'openedx': 'openedx',
Expand Down
1 change: 0 additions & 1 deletion docs/guides/docstrings/common_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ out from edx-platform into separate packages at some point.
:maxdepth: 2

common/lib/capa/modules
common/lib/safe_lxml/modules
common/lib/xmodule/modules
2 changes: 1 addition & 1 deletion lms/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs

defuse_xml_libs()

Expand Down
2 changes: 1 addition & 1 deletion lms/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

# Patch the xml libs
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs
defuse_xml_libs()

import os # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
Expand Down
2 changes: 1 addition & 1 deletion lms/wsgi_apache_lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs
defuse_xml_libs()

import os # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
log_python_warnings()

# Patch the xml libs before anything else.
from safe_lxml import defuse_xml_libs
from openedx.core.lib.safe_lxml import defuse_xml_libs # isort:skip
defuse_xml_libs()

import importlib
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions openedx/core/lib/safe_lxml/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Code run by pytest before running any tests in the safe_lxml directory.
"""
from openedx.core.lib.safe_lxml import defuse_xml_libs


defuse_xml_libs()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
It also includes a safer XMLParser.
For processing xml always prefer this over using lxml.etree directly.
isort:skip_file
"""

# Names are imported into this module so that it can be a stand-in for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
"""Test that we have defused XML."""
"""
Test that we have defused XML.
For these tests, the defusing will happen in one or more of the `conftest.py`
files that runs at pytest startup calls `defuse_xml_libs()`.
In production, the defusing happens when the LMS or Studio `wsgi.py` files
call `defuse_xml_libs()`.
"""


import defusedxml
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/lib/xblock_builtin/xblock_discussion/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from xblock.runtime import Runtime

from openedx.core.lib.xblock_builtin.xblock_discussion.xblock_discussion import DiscussionXBlock
from safe_lxml import etree # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.lib.safe_lxml import etree


def attribute_pair_repr(self):
Expand Down
2 changes: 0 additions & 2 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# via -r requirements/edx/local.in
-e git+https://github.com/edx/[email protected]#egg=rate-xblock
# via -r requirements/edx/github.in
-e common/lib/safe_lxml
# via -r requirements/edx/local.in
-e common/lib/sandbox-packages
# via -r requirements/edx/local.in
-e openedx/core/lib/xblock_builtin/xblock_discussion
Expand Down
2 changes: 0 additions & 2 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# via -r requirements/edx/testing.txt
-e git+https://github.com/edx/[email protected]#egg=rate-xblock
# via -r requirements/edx/testing.txt
-e common/lib/safe_lxml
# via -r requirements/edx/testing.txt
-e common/lib/sandbox-packages
# via -r requirements/edx/testing.txt
-e openedx/core/lib/xblock_builtin/xblock_discussion
Expand Down
1 change: 0 additions & 1 deletion requirements/edx/local.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Python libraries to install that are local to the edx-platform repo
-e .
-e common/lib/capa
-e common/lib/safe_lxml
-e common/lib/sandbox-packages
-e common/lib/xmodule

Expand Down
2 changes: 0 additions & 2 deletions requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# via -r requirements/edx/base.txt
-e git+https://github.com/edx/[email protected]#egg=rate-xblock
# via -r requirements/edx/base.txt
-e common/lib/safe_lxml
# via -r requirements/edx/base.txt
-e common/lib/sandbox-packages
# via -r requirements/edx/base.txt
-e openedx/core/lib/xblock_builtin/xblock_discussion
Expand Down
27 changes: 27 additions & 0 deletions safe_lxml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Temporary import path shim module.
Previously, the safe_lxml package was housed in common/lib/safe_lxml.
It was installed as its own Python project, so instead of its import path
being, as one would expect:
import common.lib.safe_lxml.safe_lxml
it was instead just:
import safe_lxml
To increase the sanity of edx-platform and simplify its tooling, we are
moving the safe_lxml package to openedx/core/lib (in tihs same repo) and
changing its import path to:
import openedx.core.lib.safe_lxml
In order to maintain backwards-compatibility with code using the
old import path for one release, we expose this compatibility module.
Jira ticket (public, but requires account): https://openedx.atlassian.net/browse/BOM-2583
Target removal for this shim module: by Olive.
"""

from openedx.core.lib.safe_lxml import * # pylint: disable=unused-wildcard-import,wrong-import-order
2 changes: 1 addition & 1 deletion scripts/verify-dunder-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exclude+='|^common/test/data/?.*$'
# * common/lib/xmodule -> EXCLUDE from check.
# * common/lib/xmodule/xmodule/modulestore -> INCLUDE in check.
exclude+='|^common/lib$'
exclude+='|^common/lib/(capa|safe_lxml|sandbox-packages|xmodule)$'
exclude+='|^common/lib/(capa|sandbox-packages|xmodule)$'

# Docs, scripts.
exclude+='|^docs/.*$'
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ multi_line_output=3
skip=
envs
migrations
common/lib/safe_lxml/safe_lxml/etree.py

0 comments on commit 25df9ca

Please sign in to comment.