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 non deprecated importlib files API #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions sphinx_panels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
""""A sphinx extension to add a ``panels`` directive."""
import hashlib
import importlib.resources as resources
from pathlib import Path

try:
import importlib.resources as resources
except ImportError:
# python < 3.7
import importlib_resources as resources

from docutils import nodes
from docutils.parsers.rst import directives, Directive
from sphinx.application import Sphinx
Expand Down Expand Up @@ -59,7 +54,9 @@ def update_css(app: Sphinx):
old_resources = {path.name for path in static_path.glob("*") if path.is_file()}

# Add core CSS
css_files = [r for r in resources.contents(css_module) if r.endswith(".css")]
css_files = [
r.name for r in resources.files(css_module).iterdir() if r.name.endswith(".css")
]
if app.config.panels_add_boostrap_css is not None:
LOGGER.warning(
"`panels_add_boostrap_css` will be deprecated. Please use"
Expand All @@ -72,8 +69,10 @@ def update_css(app: Sphinx):
for filename in css_files:
app.add_css_file(filename)
if not (static_path / filename).exists():
content = resources.read_text(css_module, filename)
(static_path / filename).write_text(content)
with (resources.files(css_module) / filename).open(
encoding="utf-8", errors="strict"
) as fp:
(static_path / filename).write_text(fp.read())
app.env.panels_css_changed = True
if filename in old_resources:
old_resources.remove(filename)
Expand Down