-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement AOT publishing for Python project (#125)
* try expose api as c lib and use aot * code cleanup and c error code * feat: use aot publishing for python project * fix: add catch all for unmanaged entry point
- Loading branch information
Showing
38 changed files
with
1,015 additions
and
160 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Qynit | ||
Biquad | ||
Biquad |
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 |
---|---|---|
@@ -1,107 +1,63 @@ | ||
import platform | ||
import shutil | ||
import subprocess | ||
import sys | ||
from typing import Any, Dict, List | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
SERVER_PROJECT_DIR = "src/Qynit.PulseGen.Server" | ||
if sys.platform == "win32": | ||
NPM = "npm.cmd" | ||
else: | ||
NPM = "npm" | ||
SRC_DIR = "src/Qynit.PulseGen.Aot" | ||
DST_DIR = "python/pulsegen_cs/lib" | ||
|
||
|
||
def _check_dotnet() -> None: | ||
try: | ||
subprocess.run( | ||
[ | ||
"dotnet", | ||
"--version", | ||
], | ||
check=True, | ||
capture_output=True, | ||
) | ||
except FileNotFoundError as e: | ||
msg = "dotnet is not installed" | ||
raise RuntimeError(msg) from e | ||
|
||
|
||
def _dotnet_publish(version: str) -> None: | ||
if version == "editable": | ||
configuration = "Debug" | ||
ci = "false" | ||
else: | ||
configuration = "Release" | ||
ci = "true" | ||
try: | ||
subprocess.run( | ||
[ | ||
"dotnet", | ||
"publish", | ||
SRC_DIR, | ||
"--output", | ||
DST_DIR, | ||
"--configuration", | ||
configuration, | ||
"--nologo", | ||
"--use-current-runtime", | ||
f"-p:ContinuousIntegrationBuild={ci}", | ||
], | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
msg = "dotnet publish failed" | ||
raise RuntimeError(msg) from e | ||
|
||
|
||
class CustomBuildHook(BuildHookInterface): | ||
def initialize(self, version: str, build_data: Dict[str, Any]) -> None: | ||
if self.target_name == "wheel": | ||
self._check_dotnet() | ||
self._check_npm() | ||
self._npm_ci() | ||
self._npm_build() | ||
self._dotnet_publish(version) | ||
_check_dotnet() | ||
_dotnet_publish(version) | ||
|
||
def clean(self, versions: List[str]) -> None: | ||
shutil.rmtree("artifacts", ignore_errors=True) | ||
|
||
def _check_dotnet(self) -> None: | ||
try: | ||
subprocess.run( | ||
[ | ||
"dotnet", | ||
"--version", | ||
], | ||
check=True, | ||
capture_output=True, | ||
) | ||
except FileNotFoundError as e: | ||
msg = "dotnet is not installed" | ||
raise RuntimeError(msg) from e | ||
|
||
def _check_npm(self) -> None: | ||
try: | ||
subprocess.run( | ||
[ | ||
NPM, | ||
"--version", | ||
], | ||
check=True, | ||
capture_output=True, | ||
) | ||
except FileNotFoundError as e: | ||
msg = "npm is not installed" | ||
raise RuntimeError(msg) from e | ||
|
||
|
||
def _npm_ci(self) -> None: | ||
try: | ||
subprocess.run( | ||
[ | ||
NPM, | ||
"ci", | ||
], | ||
check=True, | ||
cwd=SERVER_PROJECT_DIR, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
msg = "npm ci failed" | ||
raise RuntimeError(msg) from e | ||
|
||
def _npm_build(self) -> None: | ||
try: | ||
subprocess.run( | ||
[ | ||
NPM, | ||
"run", | ||
"build", | ||
], | ||
check=True, | ||
cwd=SERVER_PROJECT_DIR, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
msg = "npm build failed" | ||
raise RuntimeError(msg) from e | ||
|
||
def _dotnet_publish(self, version: str) -> None: | ||
if version == "editable": | ||
configuration = "Debug" | ||
ci = "false" | ||
else: | ||
configuration = "Release" | ||
ci = "true" | ||
try: | ||
subprocess.run( | ||
[ | ||
"dotnet", | ||
"publish", | ||
"--configuration", | ||
configuration, | ||
"--nologo", | ||
"/p:UseAppHost=false", | ||
f"/p:ContinuousIntegrationBuild={ci}", | ||
], | ||
check=True, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
msg = "dotnet publish failed" | ||
raise RuntimeError(msg) from e | ||
|
||
shutil.rmtree(DST_DIR, ignore_errors=True) |
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
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.