Skip to content

Commit

Permalink
Remove usage of distutils (GH-16)
Browse files Browse the repository at this point in the history
Co-authored-by: gvangool <[email protected]>
Co-authored-by: ArtyomVancyan <[email protected]>
  • Loading branch information
ArtyomVancyan and gvangool authored May 31, 2023
2 parents 7475586 + f5febca commit 0bb7295
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/django_mermaid/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from distutils import dir_util
from os import stat
from os.path import dirname
from os.path import exists
from os.path import join
import pathlib
from urllib.request import urlretrieve

from django.apps import AppConfig
Expand All @@ -18,9 +14,11 @@ def ready(self):
"""Download mermaid.js from CDN if not already present"""
version = getattr(settings, "MERMAID_VERSION", DEFAULT_VERSION)
cdn = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/%s/mermaid.min.js" % version
static_dir = join(dirname(__file__), "static")
mermaid_dir = join(static_dir, "mermaid", version)
if not exists(join(mermaid_dir, "mermaid.js")) or \
stat(join(mermaid_dir, "mermaid.js")).st_size == 0:
dir_util.create_tree(mermaid_dir, ["mermaid.js"])
urlretrieve(cdn, join(mermaid_dir, "mermaid.js"))
current_dir = pathlib.Path(__file__).parent
static_dir = current_dir / "static"
mermaid_dir = static_dir / "mermaid" / version
mermaid_js = mermaid_dir / "mermaid.js"
if not mermaid_js.exists() or \
mermaid_js.stat().st_size == 0:
mermaid_dir.mkdir(parents=True, exist_ok=True)
urlretrieve(cdn, str(mermaid_js))

0 comments on commit 0bb7295

Please sign in to comment.