Skip to content

Commit

Permalink
build: refactor building steps
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed May 31, 2024
1 parent cee2152 commit 7fe53a1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ test = [
"pytest",
"beautifulsoup4",
"pytest-regressions",
"pytest-cov"
"pytest-cov",
"defusedxml",
]
doc = [
"pydata-sphinx-theme",
Expand Down Expand Up @@ -88,6 +89,8 @@ convention = "google"

[tool.coverage.run]
source = ["sphinxcontrib.icon"]
branch = true
relative_files = true

[tool.mypy]
scripts_are_modules = true
Expand Down
37 changes: 5 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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)})
1 change: 0 additions & 1 deletion sphinxcontrib/icon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
18 changes: 14 additions & 4 deletions sphinxcontrib/icon/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7fe53a1

Please sign in to comment.