Skip to content

Commit

Permalink
configure maturin
Browse files Browse the repository at this point in the history
cleaned project
  • Loading branch information
amamic1803 committed Jan 11, 2024
1 parent 741e112 commit d3d1bec
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 181 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Lint

on:
push:
pull_request:

jobs:
lint-python:
name: Lint Python
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
name: Checkout repository

- uses: chartboost/ruff-action@v1
name: Run Ruff

lint-rust:
name: Lint Rust
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
working-directory: lib/tools_2048

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Update Rust
run: rustup update

- name: Build
run: cargo build

- name: Clippy
run: cargo clippy -- -D warnings
31 changes: 6 additions & 25 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@
import PyInstaller.__main__


def build_rust():
if os.path.isfile(".\\lib\\rust_2048.pyd"):
os.remove(".\\lib\\rust_2048.pyd")

subprocess.run(["cargo", "clean"], cwd=".\\rust_2048", stdin=None, stdout=None, stderr=None, input=None, capture_output=False,
timeout=None, check=True, shell=False, env=None, universal_newlines=False, errors=None,
text=None)

subprocess.run(["cargo", "build", "--release"], cwd=".\\rust_2048", stdin=None, stdout=None, stderr=None, input=None, capture_output=False,
timeout=None, check=True, shell=True, env=None, universal_newlines=False, errors=None,
text=None)

# rename file
os.rename("lib/tools_2048/rust_2048\\target\\release\\rust_2048.dll",
"lib/tools_2048/rust_2048\\target\\release\\rust_2048.pyd")

# copy file
shutil.copyfile("lib/tools_2048/rust_2048\\target\\release\\rust_2048.pyd", ".\\lib\\rust_2048.pyd")

subprocess.run(["cargo", "clean"], cwd=".\\rust_2048", stdin=None, stdout=None, stderr=None, input=None,
capture_output=False,
timeout=None, check=True, shell=False, env=None, universal_newlines=False, errors=None,
text=None)


def build(name, console, onefile, uac_admin, icon, files, folders):
work_path = "build"
while os.path.isdir(work_path):
Expand Down Expand Up @@ -88,6 +63,12 @@ def build(name, console, onefile, uac_admin, icon, files, folders):
else:
raise Exception("Invalid folder!")

# build rust code
subprocess.run(["maturin", "develop", "--release"], cwd=".\\lib\\tools_2048",
stdin=None, stdout=None, stderr=None, input=None, capture_output=False,
timeout=None, check=True, shell=False, env=None, universal_newlines=False,
errors=None, text=None)

PyInstaller.__main__.run(run_list)
shutil.rmtree(path=work_path, ignore_errors=True)

Expand Down
2 changes: 1 addition & 1 deletion lib/tools_2048/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ name = "tools_2048"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.2"
pyo3 = { version = "0.20.2", features = ["extension-module"] }
tools-2048-cratesio = { version = "0.3.2", package = "tools-2048" }
7 changes: 7 additions & 0 deletions lib/tools_2048/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[tool.maturin]
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
features = ["pyo3/extension-module"]
6 changes: 4 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import sys
from tkinter import *
import tools_2048

import lib.rust_2048 as rust_2048

new_game = tools_2048.Game2048(4)
new_game.make_move(0)
print(new_game.board())

def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pyinstaller>=6.3.0
pyinstaller==6.3.0
maturin==1.4.0
139 changes: 0 additions & 139 deletions scripts/2048_logic.py

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/build_rust.bat

This file was deleted.

0 comments on commit d3d1bec

Please sign in to comment.