Skip to content

Commit

Permalink
Merge pull request #131 from Amulet-Team/fix-build
Browse files Browse the repository at this point in the history
Fix some issues with the build process
  • Loading branch information
gentlegiantJGC authored Nov 15, 2020
2 parents 4decd87 + baf9a6f commit a6faacf
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 64 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ jobs:
- name: PyInstaller build
run: |
PyInstaller -y Amulet.spec
7z a Amulet-v${{ github.event.release.tag_name }}-windows-x64.zip dist/Amulet
cd dist
7z a Amulet-v${{ github.event.release.tag_name }}-windows-x64.zip Amulet
cd ..
- name: Publish to PyPi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand All @@ -45,7 +47,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./Amulet-v${{ github.event.release.tag_name }}-windows-x64.zip
asset_path: ./dist/Amulet-v${{ github.event.release.tag_name }}-windows-x64.zip
asset_name: Amulet-v${{ github.event.release.tag_name }}-windows-x64.zip
asset_content_type: application/zip

Expand All @@ -72,14 +74,16 @@ jobs:
- name: PyInstaller build
run: |
PyInstaller -y Amulet.spec
zip -r Amulet-v${{ github.event.release.tag_name }}-osx.zip dist/Amulet
cd dist
zip -r Amulet-v${{ github.event.release.tag_name }}-osx.zip Amulet
cd ..
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./Amulet-v${{ github.event.release.tag_name }}-osx.zip
asset_path: ./dist/Amulet-v${{ github.event.release.tag_name }}-osx.zip
asset_name: Amulet-v${{ github.event.release.tag_name }}-osx.zip
asset_content_type: application/zip
3 changes: 1 addition & 2 deletions amulet_map_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
experimental_bedrock_resources = False
from amulet_map_editor.api import lang, config as CONFIG, log
from .api import version, AmuletUI

from ._version import get_versions

__version__ = get_versions()["version"]
del get_versions
from amulet_map_editor.api import lang, config as CONFIG, log
3 changes: 1 addition & 2 deletions amulet_map_editor/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import wx
from amulet_map_editor import AmuletUI
from amulet_map_editor import log
from amulet_map_editor.api import AmuletUI, log
import traceback

if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion amulet_map_editor/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from amulet_map_editor.api.version import version
from .framework import AmuletUI
from .logging import log
11 changes: 6 additions & 5 deletions amulet_map_editor/api/framework/amulet_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from amulet.api.errors import LoaderNoneMatched
from amulet_map_editor.api.wx.ui.select_world import WorldSelectDialog
from amulet_map_editor.api import version, lang
from amulet_map_editor import __version__
from amulet_map_editor.api import lang
from amulet_map_editor.api.logging import log
from amulet_map_editor.api.framework.pages import WorldPageUI
from .pages import AmuletMainMenu, BasePageUI
Expand Down Expand Up @@ -39,7 +40,7 @@ def __init__(self, parent):
self,
parent,
id=wx.ID_ANY,
title=f"Amulet V{version}",
title=f"Amulet V{__version__}",
pos=wx.DefaultPosition,
size=wx.Size(560, 400),
style=wx.CAPTION
Expand Down Expand Up @@ -78,12 +79,12 @@ def __init__(self, parent):
self.Bind(wx.EVT_CLOSE, self._on_close_app)
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._page_change)

if update_check is not None:
if update_check:
self.Bind(
update_check.EVT_UPDATE_CHECK,
lambda evt: update_check.show_update_window(self, version, evt),
lambda evt: update_check.show_update_window(self, __version__, evt),
)
update_check.check_for_update(version, self)
update_check.check_for_update(__version__, self)

self.Show()

Expand Down
105 changes: 64 additions & 41 deletions amulet_map_editor/api/framework/update_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from typing import Tuple
import urllib.request
import threading
import json
Expand All @@ -9,77 +10,101 @@
import wx

URL = "http://api.github.com/repos/Amulet-Team/Amulet-Map-Editor/releases"
TAG_REGEX = re.compile(
r"^v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(?P<bugfix>\d+)$"
)
VERSION_REGEX = re.compile(
r"^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(?P<bugfix>\d+)$"
r"^v?(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?(\.(?P<bugfix>\d+))?(b(?P<beta>\d+))?$"
)

_EVT_UPDATE_CHECK = wx.NewEventType()
EVT_UPDATE_CHECK = wx.PyEventBinder(_EVT_UPDATE_CHECK, 1)


class ReleaseStageFilter:
@staticmethod
def pre_release_stage(d):
return d["prerelease"]
def get_version(version_string: str) -> Tuple[bool, Tuple[int, ...]]:
"""Parse the version into a more usable format
:param version_string: The version string. Eg 1.2 or 1.2.3.4 or 1.2.3.4b0
:return: (bool(full_version), (major, minor, patch, bugfix, <beta>)) beta will not exist if it is not a beta
"""
version_match = VERSION_REGEX.match(version_string)
if version_match:
v = version_match.groupdict()
version = (
int(v["major"]),
int(v["minor"]),
int(
v["patch"] or 0,
),
int(
v["bugfix"] or 0,
),
)
if v["beta"] is None:
# full release
return (True, version)
else:
# beta release
return (False, version + (int(v["beta"]),))

@staticmethod
def release_stage(d):
return not d["prerelease"]
raise Exception(f"Invalid version string {version_string}")


class UpdateEvent(wx.PyCommandEvent):
def __init__(self, etype, eid, new_version):
def __init__(self, etype, eid, new_version: str):
wx.PyCommandEvent.__init__(self, etype, eid)
self._new_version = new_version

def GetVersion(self):
def GetVersion(self) -> str:
return self._new_version


class CheckForUpdate(threading.Thread):
def __init__(self, url, current_version, parent, release_stage):
def __init__(self, url, current_version, parent):
threading.Thread.__init__(self)
self.url = url
self.current_version = current_version
self._parent = parent
self._release_stage = release_stage
self.data = None
self._new_version = None

def run(self):
try:
conn = urllib.request.urlopen(self.url, timeout=5)
data = conn.read()
data = json.loads(data)
version_match = VERSION_REGEX.match(self.current_version)
if not version_match:
try:
current_version = get_version(self.current_version)
except Exception:
return

for release in data:
match = TAG_REGEX.match(release["tag_name"])
if not match:
try:
release_version = get_version(release["tag_name"])
except Exception:
continue
tag_tuple = tuple(map(int, match.groups()))
version_tuple = tuple(map(int, version_match.groups()))

if not self._release_stage(release):
continue

if tag_tuple > version_tuple:
self.data = (True, tag_tuple)
break

if self.data[0]:
evt = UpdateEvent(_EVT_UPDATE_CHECK, -1, self.data[1])
if current_version[0] == release_version[0]:
# if they are both full releases or betas
if release_version[1] > current_version[1]:
self._new_version = release["tag_name"]
break
elif not current_version[0]:
# if current is beta
if release_version[0]:
release_version = (
release_version[0],
release_version[1] + (float("inf"),),
)
if release_version[1] > current_version[1]:
self._new_version = release["tag_name"]
break

if self._new_version:
evt = UpdateEvent(_EVT_UPDATE_CHECK, -1, self._new_version)
wx.PostEvent(self._parent, evt)
except Exception:
pass


class UpdateDialog(wx.Dialog):
def __init__(self, parent, current_version, new_version):
def __init__(self, parent, current_version: str, new_version: str):
wx.Dialog.__init__(self, parent)

sizer_1 = wx.BoxSizer(wx.VERTICAL)
Expand Down Expand Up @@ -114,19 +139,17 @@ def __init__(self, parent, current_version, new_version):
)
ok_button.Bind(wx.EVT_BUTTON, lambda evt: self.Close())

def goto_download_page(self, new_version, _):
@staticmethod
def goto_download_page(new_version, _):
webbrowser.open(
f"https://github.com/Amulet-Team/Amulet-Map-Editor/releases/tag/v{new_version}"
f"https://github.com/Amulet-Team/Amulet-Map-Editor/releases/tag/{new_version}"
)


def show_update_window(parent, current_version, evt):
new_version = ".".join(map(str, evt.GetVersion()))
UpdateDialog(parent, current_version, new_version).ShowModal()
def show_update_window(parent, current_version: str, evt: UpdateEvent):
UpdateDialog(parent, current_version, evt.GetVersion()).ShowModal()


def check_for_update(
version, listening_parent, release_stage=ReleaseStageFilter.pre_release_stage
):
update_thread = CheckForUpdate(URL, version, listening_parent, release_stage)
def check_for_update(version, listening_parent):
update_thread = CheckForUpdate(URL, version, listening_parent)
update_thread.start()
8 changes: 0 additions & 8 deletions amulet_map_editor/api/version/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion amulet_map_editor/api/version/version

This file was deleted.

0 comments on commit a6faacf

Please sign in to comment.