From 7fe53a1186acda9ae22ff8c14e690c89a72fede3 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Fri, 31 May 2024 08:27:13 +0000 Subject: [PATCH] build: refactor building steps --- noxfile.py | 6 ++--- pyproject.toml | 5 +++- setup.py | 37 ++++------------------------ sphinxcontrib/icon/__init__.py | 1 - sphinxcontrib/icon/package-lock.json | 18 +++++++++++--- 5 files changed, 26 insertions(+), 41 deletions(-) diff --git a/noxfile.py b/noxfile.py index 37da6e1..c8525ec 100644 --- a/noxfile.py +++ b/noxfile.py @@ -34,6 +34,6 @@ def mypy(session): @nox.session(reuse_venv=True) def test(session): """Run all the test using the environment varialbe of the running machine.""" - session.install("--verbose", ".[test]") - # session.run("pytest", "--color=yes", "--cov", "--cov-report=html", *test_files) - session.run("sphinx-build", "--bug-report") + session.install(".[test]") + test_files = session.posargs or ["tests"] + session.run("pytest", "--color=yes", "--cov", "--cov-report=xml", *test_files) diff --git a/pyproject.toml b/pyproject.toml index 2882d12..af6d408 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,8 @@ test = [ "pytest", "beautifulsoup4", "pytest-regressions", - "pytest-cov" + "pytest-cov", + "defusedxml", ] doc = [ "pydata-sphinx-theme", @@ -88,6 +89,8 @@ convention = "google" [tool.coverage.run] source = ["sphinxcontrib.icon"] +branch = true +relative_files = true [tool.mypy] scripts_are_modules = true diff --git a/setup.py b/setup.py index 2f6c1c8..20fe396 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,7 @@ from pynpm import NPMPackage from setuptools import Command, setup -from setuptools.command.build_py import build_py from setuptools.command.egg_info import egg_info -from setuptools.command.sdist import sdist ROOT = Path(__file__).parent @@ -16,8 +14,7 @@ def update_package_data(distribution) -> None: """Update package_data to catch changes during setup.""" - build_py = distribution.get_command_obj("build_py") - build_py.finalize_options() + distribution.get_command_obj("build_py").finalize_options() def js_prerelease(command: Command, strict: bool = False) -> Command: @@ -28,36 +25,12 @@ class DecoratedCommand(command): def run(self) -> None: """Run the command.""" - self.distribution.run_command("jsdeps") - command.run(self) + package = ROOT / "sphinxcontrib" / "icon" / "package.json" + NPMPackage(str(package), shell=is_windows).install() update_package_data(self.distribution) + command.run(self) return DecoratedCommand -class NPM(Command): - """install package.json dependencies using npm.""" - - def initialize_options(self): - """Ignore initialize_options.""" - pass - - def finalize_options(self): - """Ignore finalize_options.""" - pass - - def run(self): - """Run the command.""" - package = ROOT / "sphinxcontrib" / "icon" / "package.json" - NPMPackage(str(package), shell=is_windows).install() - update_package_data(self.distribution) - - -setup( - cmdclass={ - "build_py": js_prerelease(build_py), - "egg_info": js_prerelease(egg_info), - "sdist": js_prerelease(sdist, strict=True), - "jsdeps": NPM, - } -) +setup(cmdclass={"egg_info": js_prerelease(egg_info)}) diff --git a/sphinxcontrib/icon/__init__.py b/sphinxcontrib/icon/__init__.py index d3f2e6c..30d1922 100644 --- a/sphinxcontrib/icon/__init__.py +++ b/sphinxcontrib/icon/__init__.py @@ -22,7 +22,6 @@ def setup(app: Sphinx) -> Dict[str, Any]: font_handler = Fontawesome() # install html related files - raise Exception(str(font_handler.css_file.resolve())) app.add_css_file(str(font_handler.css_file.resolve())) app.add_js_file(str(font_handler.js_file.resolve())) diff --git a/sphinxcontrib/icon/package-lock.json b/sphinxcontrib/icon/package-lock.json index db4b2c9..3931fac 100644 --- a/sphinxcontrib/icon/package-lock.json +++ b/sphinxcontrib/icon/package-lock.json @@ -1,12 +1,22 @@ { "name": "sphinxcontrib-icon", + "lockfileVersion": 3, "requires": true, - "lockfileVersion": 1, - "dependencies": { - "@fortawesome/fontawesome-free": { + "packages": { + "": { + "name": "sphinxcontrib-icon", + "dependencies": { + "@fortawesome/fontawesome-free": "6.3.0" + } + }, + "node_modules/@fortawesome/fontawesome-free": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.3.0.tgz", - "integrity": "sha512-qVtd5i1Cc7cdrqnTWqTObKQHjPWAiRwjUPaXObaeNPcy7+WKxJumGBx66rfSFgK6LNpIasVKkEgW8oyf0tmPLA==" + "integrity": "sha512-qVtd5i1Cc7cdrqnTWqTObKQHjPWAiRwjUPaXObaeNPcy7+WKxJumGBx66rfSFgK6LNpIasVKkEgW8oyf0tmPLA==", + "hasInstallScript": true, + "engines": { + "node": ">=6" + } } } }