Skip to content

Commit

Permalink
Remove use of pkg_resources for Python 3.12 compatibility (#14)
Browse files Browse the repository at this point in the history
* Remove use of pkg_resources

* Test on 3.12

* add 'pragma: no cover' to exception

* Keep Python 3.7 compatible
  • Loading branch information
basnijholt authored Nov 16, 2023
1 parent e4ae05e commit 99e12de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 13 additions & 3 deletions markdown_code_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,30 @@
import os
import re
import subprocess
import sys
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any

import pkg_resources

if TYPE_CHECKING:
try:
from typing import Literal # type: ignore[attr-defined]
except ImportError:
from typing_extensions import Literal


__version__ = pkg_resources.get_distribution("markdown-code-runner").version
if sys.version_info >= (3, 8): # pragma: no cover
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("markdown-code-runner")
except PackageNotFoundError:
__version__ = "unknown"
else: # pragma: no cover
import pkg_resources

__version__ = pkg_resources.get_distribution("markdown-code-runner").version


DEBUG: bool = os.environ.get("DEBUG", "0") == "1"

Expand Down

0 comments on commit 99e12de

Please sign in to comment.