Skip to content

Commit

Permalink
Get builds going for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
codewarrior0 committed Aug 24, 2016
1 parent 2f97bf4 commit 9b60287
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
Binary file added mcedit2.icns
Binary file not shown.
54 changes: 37 additions & 17 deletions mcedit2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ except ImportError:

# --- Configurations ---

onefile = True # if False, also skips the distribution packaging
is_win = sys.platform == 'win32'
is_osx = sys.platform == 'darwin'

SEVENZIP = r"C:\Program Files\7-Zip\7z.exe"

Expand All @@ -32,10 +33,18 @@ if 'APPVEYOR_BUILD_FOLDER' in os.environ:
arch_plat = os.environ.get('PYTHON_ARCH_PLAT')
if arch_plat is None:
_arch = platform.architecture()[0][:2]
_plat = "win" if os.name == 'nt' else os.name
_plat = "win" if sys.platform == 'win32' else os.name

arch_plat = _plat + _arch

if is_win:
exe_name = dist_app_name = "mcedit2.exe"
exclude_binaries = False

if is_osx:
exe_name = "MCEdit 2"
dist_app_name = "MCEdit 2.app"
exclude_binaries = True

# --- Get version number and write to _version.py ---

Expand Down Expand Up @@ -152,20 +161,20 @@ def apply_filter(toc):
a.datas = apply_filter(a.datas)
a.binaries = apply_filter(a.binaries)

if onefile:
if is_win:
a.scripts += a.binaries + a.zipfiles + a.datas + a.zipped_data

exe = EXE(pyz,
a.scripts,
exclude_binaries=not onefile,
name='mcedit2.exe',
exclude_binaries=exclude_binaries,
name=exe_name,
debug=True,
strip=None,
upx=False,
console=True,
icon="mcediticon.ico")

if not onefile:
if is_osx:
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
Expand All @@ -174,20 +183,31 @@ if not onefile:
upx=True,
name='mcedit2')

bundle = BUNDLE(coll,
name=dist_app_name,
icon="mcedit2.icns",
bundle_identifier='net.mcedit.mcedit2',
)

# --- Distribution packaging ---

if onefile:
dist_folder_path = path.join("dist", dist_folder_name)
os.makedirs(dist_folder_path)
shutil.copy(path.join("dist", "mcedit2.exe"), dist_folder_path)

userdata_path = path.join(dist_folder_path, "MCEdit 2 Files")
plugins_path = path.join(userdata_path, "plugins")

os.makedirs(userdata_path)

shutil.copytree(path.join('src', 'plugins'), plugins_path)

dist_folder_path = path.join("dist", dist_folder_name)
os.makedirs(dist_folder_path)

if is_osx:
shutil.copytree(path.join("dist", dist_app_name), path.join(dist_folder_path, dist_app_name))
else:
shutil.copy(path.join("dist", dist_app_name), dist_folder_path)

userdata_path = path.join(dist_folder_path, "MCEdit 2 Files")
plugins_path = path.join(userdata_path, "plugins")

os.makedirs(userdata_path)

shutil.copytree(path.join('src', 'plugins'), plugins_path)

if is_win:
sfx_exe_path = path.join("dist", sfx_exe_name)

subprocess.check_call(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements-mceditlib.txt
pyzmq==15.0.0 # v15.4.0 fails to freeze with PyInstaller - see pyinstaller/issues/2147
pyside>=1.2.0
pyside>=1.2.0 ; sys.platform != 'darwin' # install this via homebrew, not visible to pip
pyopengl
ipython
qtconsole
Expand Down
9 changes: 7 additions & 2 deletions setup_mcedit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
"numpy",
]

include_dirs = [numpy.get_include()]

mcedit2_ext_modules = cythonize(
[
"src/mcedit2/rendering/blockmodels.pyx",
"src/mcedit2/rendering/modelmesh.pyx",
]
],
)

for m in mcedit2_ext_modules:
m.include_dirs = include_dirs

setup(name='mcedit2',
version=version,
description="Interactive 3D World Editor for Minecraft Levels",
Expand All @@ -49,7 +54,7 @@
packages=["mcedit2"],
package_dir={'': 'src'},
ext_modules=mcedit2_ext_modules,
include_dirs=numpy.get_include(),
include_dirs=include_dirs,
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
Expand Down
7 changes: 6 additions & 1 deletion setup_mceditlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
"numpy",
]

include_dirs = [numpy.get_include()]

mceditlib_ext_modules = cythonize([
"src/mceditlib/nbt.pyx",
"src/mceditlib/relight/with_cython.pyx"
])

for m in mceditlib_ext_modules:
m.include_dirs = include_dirs

setup(name='mceditlib',
version=version,
description="Python library for editing Minecraft levels",
Expand All @@ -45,7 +50,7 @@
packages=["mceditlib"],
package_dir={'': 'src'},
ext_modules=mceditlib_ext_modules,
include_dirs=numpy.get_include(),
include_dirs=include_dirs,
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
Expand Down
10 changes: 6 additions & 4 deletions src/mcedit2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def _write(a):

return _write

sys.stdout = codecs.getwriter(sys.stdin.encoding)(sys.stdout, errors='ignore')
sys.stderr = codecs.getwriter(sys.stdin.encoding)(sys.stderr, errors='ignore')
ioencoding = sys.stdin.encoding or 'utf-8'

sys.stdout = codecs.getwriter(ioencoding)(sys.stdout, errors='ignore')
sys.stderr = codecs.getwriter(ioencoding)(sys.stderr, errors='ignore')

sys.stdout.write = writer(sys.stdout)
sys.stderr.write = writer(sys.stderr)
Expand Down Expand Up @@ -109,15 +111,15 @@ def getMessage(self):
logging.captureWarnings(True)
from mcedit2.util.directories import getUserFilesDirectory
mceditUserData = getUserFilesDirectory()
logfilename = os.path.join(mceditUserData, 'mcedit.log')
logfilename = os.path.join(mceditUserData, 'mcedit2.log')

abslogfile = os.path.abspath(logfilename)
if hasattr(sys, 'frozen'):
log_debug("sys.frozen is set")

if sys.platform == "darwin":
log_debug("OS X found.")
logfile = os.path.expanduser(b"~/Library/Logs/" + logfilename)
logfile = os.path.expanduser(b"~/Library/Logs/" + 'mcedit2.log')
else:
logfile = abslogfile
else:
Expand Down

0 comments on commit 9b60287

Please sign in to comment.