Skip to content

Commit

Permalink
Merge pull request #32 from Ledenel/pyinstaller-compactibility
Browse files Browse the repository at this point in the history
Pyinstaller compatibility
  • Loading branch information
Ledenel authored Jan 24, 2020
2 parents cb8c189 + 58eb0ed commit 1df7ee0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pyinstallerbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pyinstaller build windows exectuable

on: release

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Build windows exectuable
run: ./pyinstaller-build.bat
- name: Publish to github
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'dist/*.exe'
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pipenv-setup = "*"
beautifulsoup4 = "*"
pandas = "*"
pytest = "*"
pyinstaller = "*"
setuptools = "==44.0.0"

[packages]
numpy = "*"
Expand Down
35 changes: 34 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions mahjong/tenhou_record_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import operator as op
import base64
import os
import sys

import pkg_resources

Expand All @@ -10,7 +11,7 @@
from itertools import groupby, product
from typing import Set, List, Callable, TypeVar, Optional

from jinja2 import Environment, select_autoescape, PackageLoader
from jinja2 import Environment, select_autoescape, PackageLoader, FileSystemLoader

from mahjong.container.pattern.reasoning import HeuristicPatternMatchWaiting
from mahjong.container.pattern.win import NormalTypeWin, UniquePairs
Expand Down Expand Up @@ -121,13 +122,26 @@ def find_in_list(lst: List[T], key: Callable[[T], bool]) -> Optional[T]:
return next((x for x in lst if key(x)), None)


# load_raw("mahjong.templates.mjpic")
def load_raw(resource, resource_path):
return pkg_resources.resource_string(resource_path, resource)
if getattr(sys, 'frozen', False):
logger.debug(sys._MEIPASS)
resource_file_subpath = os.path.join(*resource_path.split('.'))
resource_full_path = os.path.join(sys._MEIPASS, resource_file_subpath, resource)
with open(resource_full_path, "rb") as res:
return res.read()
else:
return pkg_resources.resource_string(resource_path, resource)


def template_env(template_path):
if getattr(sys, 'frozen', False):
logger.debug(sys._MEIPASS)
loader = FileSystemLoader(os.path.join(sys._MEIPASS, template_path, "templates"))
else:
loader = PackageLoader(template_path)
env = Environment(
loader=PackageLoader(template_path),
loader=loader,
autoescape=select_autoescape(['html', 'xml'])
)
env.filters['load_raw'] = load_raw
Expand All @@ -136,6 +150,8 @@ def template_env(template_path):


def main():
logger.remove()
logger.add(sys.stderr, level="INFO")
log_url = input('Input your tenhou.net log link:').strip()
record = from_url(log_url, 10)
print('read successful. pick a number to select player:')
Expand Down
1 change: 1 addition & 0 deletions pyinstaller-build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller --add-data=mahjong\templates;mahjong\templates -c --onefile mahjong\tenhou_record_check.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="auto_white_reimu",
version="0.1.1",
version="0.1.2",
packages=find_packages(),
url="",
license="GPL",
Expand Down

0 comments on commit 1df7ee0

Please sign in to comment.