Skip to content

Commit d098443

Browse files
jkowalleckssbarnea
andauthored
Remove pkg_resources (#396)
* remove pkg_resources from `plugin.py` * removed pkg_resources from `__init__.py` Co-authored-by: Sorin Sbarnea <[email protected]>
1 parent 38db4e3 commit d098443

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build-backend = "setuptools.build_meta"
1010

1111
[tool.setuptools_scm]
1212
local_scheme = "no-local-version"
13+
write_to = "src/pytest_html/__version.py"

src/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# file generated by setuptools_scm. don't track in version control
3+
pytest_html/__version.py

src/pytest_html/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from pkg_resources import DistributionNotFound
2-
from pkg_resources import get_distribution
3-
4-
51
try:
6-
__version__ = get_distribution(__name__).version
7-
except DistributionNotFound:
8-
# package is not installed
2+
from . import __version
3+
4+
__version__ = __version.version
5+
except ImportError:
6+
# package is not built with setuptools_scm
97
__version__ = "unknown"
108

119
__pypi_url__ = "https://pypi.python.org/pypi/pytest-html"

src/pytest_html/plugin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from html import escape
1818
from os.path import isfile
1919

20-
import pkg_resources
2120
import pytest
2221
from _pytest.logging import _remove_ansi_escape_sequences
2322
from py.xml import html
@@ -474,9 +473,10 @@ def _generate_report(self, session):
474473
numtests = self.passed + self.failed + self.xpassed + self.xfailed
475474
generated = datetime.datetime.now()
476475

477-
self.style_css = pkg_resources.resource_string(
478-
__name__, os.path.join("resources", "style.css")
479-
).decode("utf-8")
476+
with open(
477+
os.path.join(os.path.dirname(__file__), "resources", "style.css")
478+
) as style_css_fp:
479+
self.style_css = style_css_fp.read()
480480

481481
if ansi_support():
482482
ansi_css = [
@@ -597,9 +597,10 @@ def generate_summary_item(self):
597597
),
598598
]
599599

600-
main_js = pkg_resources.resource_string(
601-
__name__, os.path.join("resources", "main.js")
602-
).decode("utf-8")
600+
with open(
601+
os.path.join(os.path.dirname(__file__), "resources", "main.js")
602+
) as main_js_fp:
603+
main_js = main_js_fp.read()
603604

604605
session.config.hook.pytest_html_report_title(report=self)
605606

0 commit comments

Comments
 (0)