diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bdaab28..4c6d29e 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,11 +1,3 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - name: Upload Python Package on: @@ -29,11 +21,9 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build + pip install hatch - name: Build package - run: python -m build + run: hatch build - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + run: | + hatch publish -u "__token__" -a ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/build_differ.py b/build_differ.py index 3c37c17..added50 100644 --- a/build_differ.py +++ b/build_differ.py @@ -1,8 +1,8 @@ +import re import subprocess import os import tarfile import zipfile -import sys def get_version(): @@ -40,10 +40,22 @@ def compress_files(source_dir, target_file): os.path.join(source_dir, '..'))) +def cleanup_old_builds(dist_dir, current_version): + """ + Deletes any build files ending in .zip or .tar.gz in the dist_dir with a different version tag. + """ + for file in os.listdir(dist_dir): + if not file.endswith((f'{current_version}.zip', f'{current_version}.tar.gz', '.gitignore')): + file_path = os.path.join(dist_dir, file) + os.remove(file_path) + print(f"Deleted old build file: {file}") + def main(): version = get_version() print(f"Version: {version}") + dist_dir = "./src/python_redlines/dist/" + # Build for Linux print("Building for Linux...") run_command('dotnet publish ./csproj -c Release -r linux-x64 --self-contained') @@ -58,15 +70,17 @@ def main(): # Compress the Linux build linux_build_dir = './csproj/bin/Release/net8.0/linux-x64' - compress_files(linux_build_dir, f"./dist/linux-x64-{version}.tar.gz") + compress_files(linux_build_dir, f"{dist_dir}/linux-x64-{version}.tar.gz") # Compress the Windows build windows_build_dir = './csproj/bin/Release/net8.0/win-x64' - compress_files(windows_build_dir, f"./dist/win-x64-{version}.zip") + compress_files(windows_build_dir, f"{dist_dir}/win-x64-{version}.zip") # Compress the macOS build macos_build_dir = './csproj/bin/Release/net8.0/osx-x64' - compress_files(macos_build_dir, f"./dist/osx-x64-{version}.tar.gz") + compress_files(macos_build_dir, f"{dist_dir}/osx-x64-{version}.tar.gz") + + cleanup_old_builds(dist_dir, version) print("Build and compression complete.") diff --git a/dist/.gitignore b/dist/.gitignore index e69de29..c96a04f 100644 --- a/dist/.gitignore +++ b/dist/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/dist/linux-x64-0.0.1.tar.gz b/dist/linux-x64-0.0.1.tar.gz deleted file mode 100644 index 46ef67b..0000000 Binary files a/dist/linux-x64-0.0.1.tar.gz and /dev/null differ diff --git a/dist/osx-x64-0.0.1.tar.gz b/dist/osx-x64-0.0.1.tar.gz deleted file mode 100644 index 1c88f3b..0000000 Binary files a/dist/osx-x64-0.0.1.tar.gz and /dev/null differ diff --git a/dist/win-x64-0.0.1.zip b/dist/win-x64-0.0.1.zip deleted file mode 100644 index 78e15c9..0000000 Binary files a/dist/win-x64-0.0.1.zip and /dev/null differ diff --git a/docs/quickstart.md b/docs/quickstart.md index 1f6e951..c99ad7b 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -27,6 +27,7 @@ with open('/path/to/original.docx', 'rb') as f: with open('/path/to/modified.docx', 'rb') as f: modified_bytes = f.read() +# This is a tuple, bytes @ element 0 output = wrapper.run_redlines('AuthorTag', original_bytes, modified_bytes) ``` @@ -39,5 +40,5 @@ Process or save the output as needed. For example, to save the redline output to ```python with open('/path/to/redline_output.docx', 'wb') as f: - f.write(output) + f.write(output[0]) ``` diff --git a/hatch_run_build_hook.py b/hatch_run_build_hook.py new file mode 100644 index 0000000..01c1766 --- /dev/null +++ b/hatch_run_build_hook.py @@ -0,0 +1,9 @@ +import subprocess +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + +class HatchRunBuildHook(BuildHookInterface): + PLUGIN_NAME = 'hatch-run-build' + + def initialize(self, version, build_data): + # Run the 'hatch run build' command + subprocess.run(['hatch', 'run', 'build'], check=True) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 3e00f21..b128099 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,10 @@ artifacts = [ "*.tar.gz", ] +# Build hook to build the binaries for distribution... +[tool.hatch.build.hooks.custom] +path = "hatch_run_build_hook.py" + [project] name = "python-redlines" dynamic = ["version"] diff --git a/src/python_redlines/__about__.py b/src/python_redlines/__about__.py index 818403c..b83c8b5 100644 --- a/src/python_redlines/__about__.py +++ b/src/python_redlines/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2024-present U.N. Owen # # SPDX-License-Identifier: MIT -__version__ = "0.0.3" +__version__ = "0.0.4" diff --git a/src/python_redlines/bin/.gitignore b/src/python_redlines/bin/.gitignore index f59ec20..c96a04f 100644 --- a/src/python_redlines/bin/.gitignore +++ b/src/python_redlines/bin/.gitignore @@ -1 +1,2 @@ -* \ No newline at end of file +* +!.gitignore \ No newline at end of file diff --git a/src/python_redlines/dist/.gitignore b/src/python_redlines/dist/.gitignore index 74e5b1d..c96a04f 100644 --- a/src/python_redlines/dist/.gitignore +++ b/src/python_redlines/dist/.gitignore @@ -1 +1,2 @@ -!* \ No newline at end of file +* +!.gitignore \ No newline at end of file diff --git a/src/python_redlines/engines.py b/src/python_redlines/engines.py index 2d64a94..e8d8fcf 100644 --- a/src/python_redlines/engines.py +++ b/src/python_redlines/engines.py @@ -2,6 +2,7 @@ import tempfile import os import platform +import logging import zipfile import tarfile from pathlib import Path @@ -9,6 +10,8 @@ from .__about__ import __version__ +logger = logging.getLogger(__name__) + class XmlPowerToolsEngine(object): def __init__(self): @@ -44,7 +47,7 @@ def __extract_binary(self, zip_path: str, target_path: str): zip_path: str - The path to the zip file target_path: str - The path to extract the binary to """ - + print(f"") if zip_path.endswith('.zip'): with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(target_path)