-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add npm build step to pyproject.toml * Simplify github workflow * Apparently build is not installed by default * Try installing from wheels * Try just sdist builds? * Fix typo * Try custom script * Retry * Build the wheel again as well * Workflows wtf
- Loading branch information
Showing
4 changed files
with
78 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,35 @@ on: | |
- published | ||
|
||
jobs: | ||
build_frontend: | ||
name: Build frontend Javascript code | ||
build: | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
node-version: 22 | ||
|
||
- name: Build frontend | ||
working-directory: frontend | ||
run: npm ci && npm run build | ||
- name: Install build | ||
run: python -m pip install build | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build | ||
run: python -m build | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist/ | ||
name: build-output | ||
path: dist/opuscleaner-*.* | ||
|
||
run_tests: | ||
needs: [build_frontend] | ||
needs: [build] | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
@@ -38,95 +45,26 @@ jobs: | |
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
name: build-output | ||
path: dist | ||
|
||
- name: Install | ||
run: python3 -m pip install . | ||
run: python3 -m pip install dist/opuscleaner-*.whl | ||
|
||
- name: Run runtime unittest | ||
run: python3 -m unittest discover -s test | ||
|
||
- name: Run filters unittest | ||
run: python3 -m unittest discover -s opuscleaner/filters | ||
|
||
build_sdist: | ||
needs: [build_frontend] | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build sdist | ||
run: pipx run build --sdist | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: sdist | ||
path: dist/opuscleaner-*.tar.gz | ||
|
||
build_wheels: | ||
needs: [build_frontend] | ||
name: Build wheels | ||
runs-on: ubuntu-latest | ||
# name: Build wheels on ${{ matrix.os }} | ||
# runs-on: ${{ matrix.os }} | ||
# strategy: | ||
# matrix: | ||
# os: [ubuntu-latest, windows-2019, macos-13] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build wheels | ||
run: python -m pip wheel -w wheelhouse . | ||
|
||
# - name: Install cibuildwheel | ||
# run: python -m pip install cibuildwheel==2.12.0 | ||
|
||
# - name: Build wheels | ||
# run: python -m cibuildwheel --output-dir wheelhouse | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: wheels | ||
path: ./wheelhouse/opuscleaner-*.whl | ||
|
||
upload_pypi: | ||
needs: [build_wheels, build_sdist] | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'release' && github.event.action == 'published' | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: wheels | ||
path: dist | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: sdist | ||
name: build-output | ||
path: dist | ||
|
||
- uses: pypa/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,17 @@ readme = "README.md" | |
requires-python = ">=3.9" | ||
license = "MIT" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Jelmer van der Linde", email = "[email protected]" }, | ||
] | ||
authors = [{ name = "Jelmer van der Linde", email = "[email protected]" }] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dynamic = [ | ||
"version", | ||
"dependencies", | ||
"optional-dependencies" | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dynamic = ["version", "dependencies", "optional-dependencies"] | ||
|
||
[project.scripts] | ||
opuscleaner-server = "opuscleaner.server:main" | ||
|
@@ -44,10 +38,8 @@ Source = "https://github.com/hplt-project/opuscleaner" | |
path = "opuscleaner/__about__.py" | ||
|
||
[tool.hatch.envs.default] | ||
dependencies = [ | ||
"pytest", | ||
"pytest-cov", | ||
] | ||
dependencies = ["pytest", "pytest-cov"] | ||
|
||
[tool.hatch.envs.default.scripts] | ||
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=opuscleaner --cov=tests {args}" | ||
no-cov = "cov --no-cov {args}" | ||
|
@@ -56,13 +48,16 @@ no-cov = "cov --no-cov {args}" | |
python = ["39", "310", "311"] | ||
|
||
[tool.hatch.build] | ||
include = [ | ||
"/opuscleaner", | ||
] | ||
include = ["/opuscleaner"] | ||
|
||
[tool.hatch.build.force-include] | ||
[tool.hatch.build.targets.sdist.force-include] | ||
"frontend/dist" = "/opuscleaner/frontend" | ||
|
||
[tool.hatch.build.targets.sdist.hooks.custom] | ||
path = "utils/frontend_build_hook.py" | ||
working_dir = "frontend" | ||
artifacts = ["frontend/dist"] | ||
|
||
[tool.hatch.metadata.hooks.requirements_txt] | ||
files = ["requirements.txt"] | ||
|
||
|
@@ -72,13 +67,7 @@ all = ["requirements-all.txt"] | |
[tool.coverage.run] | ||
branch = true | ||
parallel = true | ||
omit = [ | ||
"opuscleaner/__about__.py", | ||
] | ||
omit = ["opuscleaner/__about__.py"] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ | ||
"no cov", | ||
"if __name__ == .__main__.:", | ||
"if TYPE_CHECKING:", | ||
] | ||
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import subprocess | ||
import os | ||
from typing import Any | ||
import logging | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NpmBuildHook(BuildHookInterface): | ||
@property | ||
def working_dir(self): | ||
return self.config.get("working_dir", ".") | ||
|
||
def initialize(self, version: str, build_data: dict[str, Any]) -> None: | ||
# if we can't build because we don't have the build dir, skip | ||
if not os.path.exists(self.working_dir): | ||
logger.info(f"Skipping npm build because {self.working_dir=} does not exist") | ||
return | ||
# if we don't need to build because we have all the artifacts, skip | ||
if all(os.path.exists(artifact) for artifact in self.config.get("artifacts", [])): | ||
logger.info(f"Skipping npm build because all artifacts exist") | ||
return | ||
subprocess.check_output( | ||
"npm install && npm run build", | ||
shell=True, | ||
cwd=self.working_dir) | ||
|
||
def clean(self, versions: list[str]) -> None: | ||
subprocess.check_output("npm run clean", shell=True, cwd=self.working_dir) |