Skip to content

Commit

Permalink
Merge pull request #72 from moiSentineL/library
Browse files Browse the repository at this point in the history
library file names based on os + multiplatform build
  • Loading branch information
moiSentineL authored Aug 9, 2024
2 parents 73ed905 + f12a29c commit d3a8167
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
67 changes: 62 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,85 @@
name: publish
name: Multi-Platform Build and Publish

on:
release:
types: [published]

jobs:
deploy:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
output: flomo/session_id.so
- os: macos-latest
output: flomo/session_id.dylib
- os: windows-latest
output: flomo/session_id.dll

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.12.3"

- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
if: runner.os != 'Windows'

- name: Set up MSVC
uses: microsoft/[email protected]
if: runner.os == 'Windows'

- name: Compile (Unix)
if: runner.os != 'Windows'
run: gcc -fPIC -shared -o ${{ matrix.output }} flomo/session_id.c

- name: Compile (Windows)
if: runner.os == 'Windows'
run: cl.exe /LD /Fe${{ matrix.output }} flomo/session_id.c

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ runner.os }}-library
path: ${{ matrix.output }}

publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.12.3"
- name: Install GCC
uses: egor-tensin/[email protected]

- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: ./artifacts

- name: Move artifacts to correct locations
run: |
mkdir -p flomo
mv artifacts/Linux-library/session_id.so flomo/
mv artifacts/macOS-library/session_id.dylib flomo/
mv artifacts/Windows-library/session_id.dll flomo/
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and Publish
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
gcc -fPIC -shared -o flomo/session_id.so flomo/session_id.c
python setup.py sdist bdist_wheel
twine upload dist/*
40 changes: 24 additions & 16 deletions flomo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,43 @@
import flomo.errors as errors


def get_path(file_name: str, in_data: bool = False):
def get_path(file_name: str, in_data: bool = False, lib: bool = False):
is_windows = platform.system().lower() == "windows"
is_mac = platform.system().lower() == "darwin"

conf_path = (
str(os.getenv("APPDATA")) or str(os.getenv("LOCALAPPDATA"))
if is_windows
else (
os.path.expanduser("~/Library/Application Support")
if is_mac
else os.path.expanduser("~/.config")
)
)

dir_path = os.path.dirname(os.path.realpath(__file__))

sign = "\\" if is_windows else "/"
data_folder = f"{sign}{'Flomo' if is_windows else 'flomo'}" if in_data else ""

if in_data and not os.path.exists(conf_path + data_folder):
os.makedirs(conf_path + data_folder)

file = f"{data_folder}{sign}{file_name}"

if in_data:
conf_path = (
str(os.getenv("APPDATA")) or str(os.getenv("LOCALAPPDATA"))
if is_windows
else (
os.path.expanduser("~/Library/Application Support")
if is_mac
else os.path.expanduser("~/.config")
)
)
if not os.path.exists(conf_path + data_folder):
os.makedirs(conf_path + data_folder)
return os.path.join(conf_path + file)
elif lib:
return (
os.path.join(dir_path + f"{sign}session_id.dll")
if is_windows
else (
os.path.join(dir_path + f"{sign}session_id.dylib")
if is_mac
else os.path.join(dir_path + f"{sign}session_id.so")
)
)
else:
return os.path.join(dir_path + file)


def play_sound():
try:
path = get_path("beep.mp3")
Expand Down Expand Up @@ -81,4 +89,4 @@ def tag_color(tag: str) -> str:
for k, v in config.Config().get_config(config.TAG_COLORS).items()
}

return tag_colors.get(tag, "blue")
return tag_colors.get(tag, "blue")
2 changes: 1 addition & 1 deletion flomo/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_table(self):
self.conn.commit()

def create_session(self, tag: str, name: str, start_time: datetime.datetime) -> str:
lib = ctypes.CDLL(helpers.get_path("session_id.so"))
lib = ctypes.CDLL(helpers.get_path("", lib=True))

lib.encode_timestamp.argtypes = [ctypes.c_ulonglong]
lib.encode_timestamp.restype = ctypes.c_char_p
Expand Down

0 comments on commit d3a8167

Please sign in to comment.