Skip to content

Commit bd8545b

Browse files
committed
Added a workflow to build the latest differs.
2 parents 3c833e4 + 4ee2e99 commit bd8545b

File tree

7 files changed

+90
-62
lines changed

7 files changed

+90
-62
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Upload Python Package
2+
3+
on:
4+
pull_request:
5+
branches: [ 'main' ]
6+
paths-ignore: [ 'docs/**' ]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
deploy:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up .NET 8
19+
uses: actions/setup-dotnet@v3
20+
with:
21+
dotnet-version: '8.0.x'
22+
- name: Set up Python
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: '3.x'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install hatch
30+
- name: Build differs
31+
run: hatch run build
32+
- name: Commit differ
33+
run: |
34+
git config --global user.name 'JSv4'
35+
git config --global user.email 'JSv4@users.noreply.github.com'
36+
git commit -am "Engine Builds"
37+
git push

.github/workflows/python-publish.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v3
17-
- name: Set up .NET 8
18-
uses: actions/setup-dotnet@v3
19-
with:
20-
dotnet-version: '8.0.x'
2117
- name: Set up Python
2218
uses: actions/setup-python@v3
2319
with:

build_differ.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import tarfile
44
import zipfile
5-
import sys
65

76

87
def get_version():

docs/developer-guide.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ dotnet publish -c Release -r linux-x64 --self-contained
7878
dotnet publish -c Release -r win-x64 --self-contained
7979
```
8080

81-
3. Archive and package binaries into `./dist/`:
81+
3. Build a binary for MacOS:
82+
83+
```bash
84+
dotnet publish -c Release -r osx-x64 --self-contained
85+
```
86+
87+
4. Archive and package binaries into `./dist/`:
8288

8389

8490
## Running Tests

hatch_run_build_hook.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ artifacts = [
1111
"*.tar.gz",
1212
]
1313

14-
# Build hook to build the binaries for distribution...
15-
[tool.hatch.build.hooks.custom]
16-
path = "hatch_run_build_hook.py"
17-
1814
[project]
1915
name = "python-redlines"
2016
dynamic = ["version"]

src/python_redlines/engines.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import subprocess
22
import tempfile
3-
import logging
43
import os
54
import platform
5+
import logging
66
import zipfile
77
import tarfile
88
from pathlib import Path
@@ -14,71 +14,74 @@
1414

1515

1616
class XmlPowerToolsEngine(object):
17-
def __init__(self, reload_binary: bool = False):
18-
self.extracted_binaries_path = self._unzip_binary()
19-
self._reload_binary = reload_binary
17+
def __init__(self):
18+
self.extracted_binaries_path = self.__unzip_binary()
2019

21-
def _unzip_binary(self):
20+
def __unzip_binary(self):
2221
"""
2322
Unzips the appropriate C# binary for the current platform.
2423
"""
2524
base_path = os.path.dirname(__file__)
26-
logger.debug(f"Python redlining base path: {base_path}")
27-
2825
binaries_path = os.path.join(base_path, 'dist')
29-
logger.debug(f"Python redlining binaries path: {binaries_path}")
26+
target_path = os.path.join(base_path, 'bin')
27+
28+
if not os.path.exists(target_path):
29+
os.makedirs(target_path)
30+
31+
# Get the binary name and zip name based on the OS and architecture
32+
binary_name, zip_name = self.__get_binaries_info()
3033

34+
# Check if the binary already exists. If not, extract it.
35+
full_binary_path = os.path.join(target_path, binary_name)
36+
37+
if not os.path.exists(full_binary_path):
38+
zip_path = os.path.join(binaries_path, zip_name)
39+
self.__extract_binary(zip_path, target_path)
40+
41+
return os.path.join(target_path, binary_name)
42+
43+
def __extract_binary(self, zip_path: str, target_path: str):
44+
"""
45+
Extracts the binary from the zip file based on the extension. Supports .zip and .tar.gz files
46+
:parameter
47+
zip_path: str - The path to the zip file
48+
target_path: str - The path to extract the binary to
49+
"""
50+
print(f"")
51+
if zip_path.endswith('.zip'):
52+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
53+
zip_ref.extractall(target_path)
54+
55+
elif zip_path.endswith('.tar.gz'):
56+
with tarfile.open(zip_path, 'r:gz') as tar_ref:
57+
tar_ref.extractall(target_path)
58+
59+
def __get_binaries_info(self):
60+
"""
61+
Returns the binary name and zip name based on the OS and architecture
62+
:return
63+
binary_name: str - The name of the binary file
64+
zip_name: str - The name of the zip file
65+
"""
3166
os_name = platform.system().lower()
3267
arch = 'x64' # Assuming x64 architecture
3368

3469
if os_name == 'linux':
3570
zip_name = f"linux-{arch}-{__version__}.tar.gz"
3671
binary_name = 'linux-x64/redlines'
3772

38-
elif os_name == "windows":
73+
elif os_name == 'windows':
3974
zip_name = f"win-{arch}-{__version__}.zip"
4075
binary_name = 'win-x64/redlines.exe'
4176

42-
elif os_name == "darwin":
77+
elif os_name == 'darwin':
4378
zip_name = f"osx-{arch}-{__version__}.tar.gz"
4479
binary_name = 'osx-x64/redlines'
45-
else:
46-
raise EnvironmentError("Unsupported OS")
47-
48-
target_path = os.path.join(base_path, 'bin')
49-
logger.debug(f"Target path: {target_path}")
5080

51-
# If target folder doesn't exist... created
52-
if not os.path.exists(target_path):
53-
os.makedirs(target_path)
54-
else:
55-
# If we don't want to reload the binary and it already exists... just return path
56-
if not self._reload_binary:
57-
return os.path.join(target_path, binary_name)
58-
59-
# Otherwise, go ahead and unzip... and this may vary depending on the architecture & env
60-
if os_name == 'linux':
61-
zip_path = os.path.join(binaries_path, zip_name)
62-
if os.path.exists(zip_path):
63-
with tarfile.open(zip_path, 'r:gz') as tar_ref:
64-
tar_ref.extractall(target_path)
65-
66-
elif os_name == 'windows':
67-
zip_path = os.path.join(binaries_path, zip_name)
68-
if os.path.exists(zip_path):
69-
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
70-
zip_ref.extractall(target_path)
71-
72-
elif os_name == 'darwin':
73-
zip_path = os.path.join(binaries_path, zip_name)
74-
if os.path.exists(zip_path):
75-
with tarfile.open(zip_path, 'r:gz') as tar_ref:
76-
tar_ref.extractall(target_path)
77-
# This is redundant given above test... but I'm leaving it here.
7881
else:
7982
raise EnvironmentError("Unsupported OS")
8083

81-
return os.path.join(target_path, binary_name)
84+
return binary_name, zip_name
8285

8386
def run_redline(self, author_tag: str, original: Union[bytes, Path], modified: Union[bytes, Path]) \
8487
-> Tuple[bytes, Optional[str], Optional[str]]:

0 commit comments

Comments
 (0)