Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Contribution (Improved formatting for readability, will on it more) #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
146 changes: 96 additions & 50 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def finalize_options(self):

def compile_rc(self, qrc_file):
import PyQt5

py_file = os.path.splitext(qrc_file)[0] + "_rc.py"
if not distutils.dep_util.newer(qrc_file, py_file):
return
Expand All @@ -53,6 +54,7 @@ def compile_rc(self, qrc_file):

def compile_ui(self, ui_file):
from PyQt5 import uic

py_file = os.path.splitext(ui_file)[0] + "_ui.py"
if not distutils.dep_util.newer(ui_file, py_file):
return
Expand All @@ -61,14 +63,17 @@ def compile_ui(self, ui_file):

def compile_ts(self, ts_file):
import PyQt5

qm_file = os.path.splitext(ts_file)[0] + ".qm"
if not distutils.dep_util.newer(ts_file, qm_file):
return
origpath = os.getenv("PATH")
path = origpath.split(os.pathsep)
path.append(os.path.dirname(PyQt5.__file__))
os.putenv("PATH", os.pathsep.join(path))
lr_exe = distutils.spawn.find_executable("lrelease") or distutils.spawn.find_executable("lrelease-qt5")
lr_exe = distutils.spawn.find_executable(
"lrelease"
) or distutils.spawn.find_executable("lrelease-qt5")
if lr_exe is None:
self.warn("Unable to find Qt's Linguist lrelease or lrelease-qt5 tools")
sys.exit(1)
Expand All @@ -82,13 +87,13 @@ def run(self):
basepath = os.path.join(os.path.dirname(__file__), "src", "m64py", "ui")
for dirpath, _, filenames in os.walk(basepath):
for filename in filenames:
if filename.endswith('.ts'):
if filename.endswith(".ts"):
self.compile_ts(os.path.join(dirpath, filename))
for dirpath, _, filenames in os.walk(basepath):
for filename in filenames:
if filename.endswith('.ui'):
if filename.endswith(".ui"):
self.compile_ui(os.path.join(dirpath, filename))
elif filename.endswith('.qrc'):
elif filename.endswith(".qrc"):
self.compile_rc(os.path.join(dirpath, filename))


Expand Down Expand Up @@ -129,15 +134,18 @@ def remove_files(self):

def run_build(self):
import PyInstaller.building.build_main

work_path = os.path.join(self.dist_dir, "build")
spec_file = os.path.join(self.dist_dir, "m64py.spec")
os.environ["BASE_DIR"] = BASE_DIR
os.environ["DIST_DIR"] = self.dist_dir
opts = {"distpath": self.dist_dir,
"workpath": work_path,
"clean_build": True,
"upx_dir": None,
"debug": False}
opts = {
"distpath": self.dist_dir,
"workpath": work_path,
"clean_build": True,
"upx_dir": None,
"debug": False,
}
PyInstaller.building.build_main.main(None, spec_file, True, **opts)

def run_build_dmg(self):
Expand All @@ -146,11 +154,17 @@ def run_build_dmg(self):
subprocess.call(["hdiutil", "create", dst_path, "-srcfolder", src_path])

def set_plist(self):
info_plist = os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Info.plist")
shutil.copy(os.path.join(self.dist_dir, "m64py.icns"),
os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Resources"))
shutil.copy(os.path.join(self.dist_dir, "m64py.sh"),
os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "MacOS"))
info_plist = os.path.join(
self.dist_dir, "dmg", "M64Py.app", "Contents", "Info.plist"
)
shutil.copy(
os.path.join(self.dist_dir, "m64py.icns"),
os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "Resources"),
)
shutil.copy(
os.path.join(self.dist_dir, "m64py.sh"),
os.path.join(self.dist_dir, "dmg", "M64Py.app", "Contents", "MacOS"),
)
with open(info_plist, "r") as opts:
data = opts.read()
plist_file = ""
Expand Down Expand Up @@ -222,13 +236,17 @@ def copy_files(self):
rar_dir = os.path.join(os.environ["ProgramFiles(x86)"], "Unrar")
if not os.path.isfile(os.path.join(rar_dir, "UnRAR.exe")):
tempdir = tempfile.mkdtemp()
urllib.request.urlretrieve("http://www.rarlab.com/rar/unrarw32.exe",
os.path.join(tempdir, "unrar.exe"))
urllib.request.urlretrieve(
"http://www.rarlab.com/rar/unrarw32.exe",
os.path.join(tempdir, "unrar.exe"),
)
subprocess.call([os.path.join(tempdir, "unrar.exe"), "-s"])
shutil.rmtree(tempdir)
shutil.copy(os.path.join(rar_dir, "UnRAR.exe"), dest_path)
shutil.copy(os.path.join(rar_dir, "license.txt"),
os.path.join(dest_path, "doc", "unrar-license.txt"))
shutil.copy(
os.path.join(rar_dir, "license.txt"),
os.path.join(dest_path, "doc", "unrar-license.txt"),
)
for file_name in ["AUTHORS", "ChangeLog", "COPYING", "LICENSES", "README.rst"]:
shutil.copy(os.path.join(BASE_DIR, file_name), dest_path)

Expand All @@ -239,23 +257,37 @@ def remove_files(self):
for dir_name in ["qml", "translations"]:
shutil.rmtree(os.path.join(dest_path, "PyQt5", "Qt", dir_name), True)
for file_name in glob.glob(os.path.join(dest_path, "PyQt5", "Qt*.pyd")):
if os.path.basename(file_name) not in ["Qt.pyd", "QtCore.pyd", "QtGui.pyd", "QtWidgets.pyd", "QtOpenGL.pyd"]:
if os.path.basename(file_name) not in [
"Qt.pyd",
"QtCore.pyd",
"QtGui.pyd",
"QtWidgets.pyd",
"QtOpenGL.pyd",
]:
os.remove(file_name)
for file_name in glob.glob(os.path.join(dest_path, "Qt5*.dll")):
if os.path.basename(file_name) not in ["Qt5Core.dll", "Qt5Gui.dll", "Qt5Widgets.dll", "Qt5OpenGL.dll"]:
if os.path.basename(file_name) not in [
"Qt5Core.dll",
"Qt5Gui.dll",
"Qt5Widgets.dll",
"Qt5OpenGL.dll",
]:
os.remove(file_name)

def run_build(self):
import PyInstaller.building.build_main

work_path = os.path.join(self.dist_dir, "build")
spec_file = os.path.join(self.dist_dir, "m64py.spec")
os.environ["BASE_DIR"] = BASE_DIR
os.environ["DIST_DIR"] = self.dist_dir
opts = {"distpath": self.dist_dir,
"workpath": work_path,
"clean_build": True,
"upx_dir": None,
"debug": False}
opts = {
"distpath": self.dist_dir,
"workpath": work_path,
"clean_build": True,
"upx_dir": None,
"debug": False,
}
PyInstaller.building.build_main.main(None, spec_file, True, **opts)

def run_build_installer(self):
Expand All @@ -266,7 +298,9 @@ def run_build_installer(self):
data = iss.read()
lines = data.split("\n")
for line in lines:
line = line.replace("{ICON}", os.path.realpath(os.path.join(self.dist_dir, "m64py")))
line = line.replace(
"{ICON}", os.path.realpath(os.path.join(self.dist_dir, "m64py"))
)
line = line.replace("{VERSION}", FRONTEND_VERSION)
iss_file += line + "\n"
with open(iss_out, "w") as iss:
Expand All @@ -288,13 +322,17 @@ class BuildZip(BuildExe):
description = "Generate a .zip file for distribution"

def run_build_zip(self):
os.rename(os.path.join(self.dist_dir, "m64py"),
os.path.join(self.dist_dir, "m64py-{}".format(FRONTEND_VERSION)))
shutil.make_archive(os.path.join(self.dist_dir,
"m64py-{}-portable".format(FRONTEND_VERSION)),
"zip",
self.dist_dir, "m64py-{}".format(FRONTEND_VERSION),
True)
os.rename(
os.path.join(self.dist_dir, "m64py"),
os.path.join(self.dist_dir, "m64py-{}".format(FRONTEND_VERSION)),
)
shutil.make_archive(
os.path.join(self.dist_dir, "m64py-{}-portable".format(FRONTEND_VERSION)),
"zip",
self.dist_dir,
"m64py-{}".format(FRONTEND_VERSION),
True,
)

@staticmethod
def set_config_path():
Expand All @@ -311,14 +349,18 @@ def set_config_path():
core.write(core_file)

settings_file = ""
settings_path = os.path.join(BASE_DIR, "src", "m64py", "frontend", "settings.py")
settings_path = os.path.join(
BASE_DIR, "src", "m64py", "frontend", "settings.py"
)
with open(settings_path, "r") as core:
data = core.read()
lines = data.split("\n")
for line in lines:
if "QSettings(" in line:
line = line.replace("QSettings(\"m64py\", \"m64py\")",
"QSettings(os.path.join(os.getcwd(), \"m64py.ini\"), QSettings.IniFormat)")
line = line.replace(
'QSettings("m64py", "m64py")',
'QSettings(os.path.join(os.getcwd(), "m64py.ini"), QSettings.IniFormat)',
)
settings_file += line + "\n"
with open(settings_path, "w") as core:
core.write(settings_file)
Expand All @@ -337,8 +379,8 @@ class CleanLocal(setuptools.Command):

description = "Clean the local project directory"

wildcards = ['*.py[co]', '*_ui.py', '*_rc.py', '__pycache__', '*.qm']
excludedirs = ['.git', 'build', 'dist']
wildcards = ["*.py[co]", "*_ui.py", "*_rc.py", "__pycache__", "*.qm"]
excludedirs = [".git", "build", "dist"]
user_options = []

def initialize_options(self):
Expand All @@ -351,19 +393,23 @@ def _walkpaths(self, path):
for root, dirs, files in os.walk(path):
for excluded_dir in self.excludedirs:
abs_excluded_dir = os.path.join(path, excluded_dir)
if root == abs_excluded_dir or root.startswith(abs_excluded_dir + os.sep):
if root == abs_excluded_dir or root.startswith(
abs_excluded_dir + os.sep
):
continue
for a_dir in dirs:
file_path = os.path.join(root, a_dir)
if any(fnmatch.fnmatch(a_dir, pattern) for pattern in self.wildcards):
yield file_path
for a_file in files:
file_path = os.path.join(root, a_file)
if any(fnmatch.fnmatch(file_path, pattern) for pattern in self.wildcards):
if any(
fnmatch.fnmatch(file_path, pattern) for pattern in self.wildcards
):
yield file_path

def run(self):
for a_path in self._walkpaths('.'):
for a_path in self._walkpaths("."):
if os.path.isdir(a_path):
shutil.rmtree(a_path)
else:
Expand Down Expand Up @@ -391,22 +437,22 @@ def run(self):
author_email="gen2brain@gmail.com",
license="GNU GPLv3",
url="http://m64py.sourceforge.net",
package_dir={'': "src"},
package_dir={"": "src"},
packages=["m64py", "m64py.core", "m64py.frontend", "m64py.ui"],
scripts=["bin/m64py"],
requires=["PyQt5", "PySDL2"],
platforms=["Linux", "Windows", "Darwin"],
cmdclass={
'build': MyBuild,
'build_dmg': BuildDmg,
'build_exe': BuildExe,
'build_qt': BuildQt,
'build_zip': BuildZip,
'clean': MyClean,
'clean_local': CleanLocal
"build": MyBuild,
"build_dmg": BuildDmg,
"build_exe": BuildExe,
"build_qt": BuildQt,
"build_zip": BuildZip,
"clean": MyClean,
"clean_local": CleanLocal,
},
data_files=[
("share/pixmaps", ["xdg/m64py.png"]),
("share/applications", ["xdg/m64py.desktop"]),
]
],
)