import subprocess

# pylint: disable=deprecated-module
from distutils.command import build as build_module
from setuptools import setup, find_packages

install_requires: list = [
    "ocyan.core",
    "wagtail >2.1.1",
    "wagtail-metadata >= 2.0",
    "ocyan.plugin.wagtail_utils",
    # The MandelBlog compatibility distribution preserves the upstream
    # ``oscar_elasticsearch`` Python package without its stale uWSGI metadata.
    "ocyan.compat.django-oscar-elasticsearch==3.0.0.post1",
]

extras_require: dict = {
    "test": [
        "ocyan.plugin.testing",
        "wheel",
        "empty_testproject",
        "pylint-django",
        "isort",
        "ruff",
        "vdt.versionplugin.wheel",
        "coverage",
        "wagtailtrans",
        "oxyan.themes",
    ]
}

PACKAGE_CLASSIFIERS = [
    "License :: Other/Proprietary License",
    "Framework :: Ocyan",
    "Environment :: Plugins",
]


class BuildNPM(build_module.build):
    def run(self):
        subprocess.check_call(["npm", "install"])
        subprocess.check_call(["npm", "run", "build"])
        super().run()


setup(
    name="ocyan.plugin.wagtail",
    version="2.0.3rc1",
    url="https://git.mandelblog.com/mandel-plugins/ocyan.plugin.wagtail",
    author="Mandel",
    author_email="info@mandelblog.com",
    description="Installs wagtail to manage content and pages.",
    packages=find_packages(),
    include_package_data=True,
    python_requires=">=3.6",
    install_requires=install_requires,
    extras_require=extras_require,
    classifiers=PACKAGE_CLASSIFIERS,
    cmdclass={"build": BuildNPM},
)
