Skip to content

Commit

Permalink
fix: static listing of extension requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed May 26, 2023
1 parent 1038b1d commit 1152598
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
1 change: 0 additions & 1 deletion extras.json

This file was deleted.

21 changes: 2 additions & 19 deletions popmon/extensions/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
from __future__ import annotations

import importlib.util
from pathlib import Path
from typing import Callable

try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib


def is_installed(package):
is_present = importlib.util.find_spec(package)
Expand All @@ -36,19 +30,8 @@ def is_installed(package):
class Extension:
name: str
extension: Callable

@property
def requirements(self):
pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
with pyproject_path.open("rb") as f:
data = tomllib.load(f)

project = data["project"]
extras = project.get("optional-dependencies", {})
if self.name not in extras:
return []

return extras[self.name]
# should also be added to `pyproject.toml` optional-dependencies
requirements: list[str]

def check(self):
if all(is_installed(package) for package in self.requirements):
Expand Down
1 change: 1 addition & 0 deletions popmon/extensions/profile_diptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ def diptest_profile(bin_centers, bin_values, bin_width, rng=None):
class Diptest(Extension):
name = "diptest"
extension = extension
requirements = ["diptest"]
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ dependencies = [
"joblib>=0.14.0",
"htmlmin",
"pydantic",
"typing_extensions",
"tomli >= 1.1.0 ; python_version < '3.11'"
"typing_extensions"
]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit 1152598

Please sign in to comment.