Skip to content

Commit

Permalink
Merge pull request #343 from eoyilmaz/336-build-install-fail
Browse files Browse the repository at this point in the history
336 build install fail
  • Loading branch information
eoyilmaz authored Mar 26, 2024
2 parents 2cca1f3 + f73daac commit f915df7
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 61 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ jobs:
- name: Compile C-Extensions
run: |
sudo chmod a+rw /etc/udev/rules.d
python3 setup.py install
cp ./build/lib.linux-x86_64-${{ env.add_dir_str }}/DisplayCAL/lib64/python${{ env.py_version }}/RealDisplaySizeMM.cpython-${{ env.py_version }}-x86_64-linux-gnu.so ./DisplayCAL/lib64/python${{ env.py_version }}/
python3 -m build
pip install dist/DisplayCAL-*.whl
export PYPATH=`which python`
export PYDIR=`dirname $PYPATH`
cp $PYDIR/../lib/python${{ matrix.python-version }}/site-packages/DisplayCAL/lib64/python${{ env.py_version }}/RealDisplaySizeMM.*.so ./DisplayCAL/lib64/python${{ env.py_version }}/
- name: Test with pytest
run: |
python -m pytest --verbose --cov=. --cov-report html
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ __pycache__/
/DisplayCAL/lib64/python39/*.so
/DisplayCAL/lib64/python310/*.so
/DisplayCAL/lib64/RealDisplaySizeMM.cpython-310-darwin.so
/DisplayCAL/lib64/RealDisplaySizeMM.cpython-311-darwin.so
/DisplayCAL/lib64/RealDisplaySizeMM.cpython-312-darwin.so
136 changes: 81 additions & 55 deletions DisplayCAL/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def findall(dir=os.curdir):


import distutils.filelist

distutils.filelist.findall = findall # Fix findall bug in distutils


Expand All @@ -74,6 +75,7 @@ def findall(dir=os.curdir):
description,
longdesc,
DOMAIN,
development_home_page,
name,
py_maxversion,
py_minversion,
Expand Down Expand Up @@ -199,7 +201,8 @@ def add_lib_excludes(key, excludebits):
for exclude in ("32", "64"):
for pycompat in ("38", "39", "310", "311"):
if key == "win32" and (
pycompat == str(sys.version_info[0]) + str(sys.version_info[1]) or exclude == excludebits[0]
pycompat == str(sys.version_info[0]) + str(sys.version_info[1])
or exclude == excludebits[0]
):
continue
config["excludes"][key].extend(
Expand Down Expand Up @@ -367,7 +370,7 @@ def create_app_symlinks(dist_dir, scripts):


def get_data(tgt_dir, key, pkgname=None, subkey=None, excludes=None):
"""Return configured data files"""
"""Return configured data files."""
files = config[key]
src_dir = source_dir
if pkgname:
Expand All @@ -381,12 +384,9 @@ def get_data(tgt_dir, key, pkgname=None, subkey=None, excludes=None):
data = []
for pth in files:
if not [exclude for exclude in excludes or [] if fnmatch(pth, exclude)]:
data.append(
(
os.path.normpath(os.path.join(tgt_dir, os.path.dirname(pth))),
safe_glob(os.path.join(src_dir, pth)),
)
)
normalized_path = os.path.normpath(os.path.join(tgt_dir, os.path.dirname(pth)))
safe_path = [relpath(p, src_dir) for p in safe_glob(os.path.join(src_dir, pth))]
data.append((normalized_path, safe_path))
return data


Expand Down Expand Up @@ -470,12 +470,12 @@ def setup():
if use_setuptools:
if "--use-setuptools" in sys.argv[1:] and not os.path.exists("use-setuptools"):
open("use-setuptools", "w").close()
try:
from ez_setup import use_setuptools as ez_use_setuptools

ez_use_setuptools()
except ImportError:
pass
# try:
# from ez_setup import use_setuptools as ez_use_setuptools
#
# ez_use_setuptools()
# except ImportError:
# pass
try:
import setuptools
from setuptools import setup, Extension, find_packages
Expand Down Expand Up @@ -522,7 +522,10 @@ def findall(
sys.argv = sys.argv[:i] + ["install"] + sys.argv[i + 1:]
install.create_home_path = lambda self: None

if skip_instrument_conf_files := "--skip-instrument-configuration-files" in sys.argv[1:]:
if (
skip_instrument_conf_files := "--skip-instrument-configuration-files"
in sys.argv[1:]
):
i = sys.argv.index("--skip-instrument-configuration-files")
sys.argv = sys.argv[:i] + sys.argv[i + 1:]

Expand Down Expand Up @@ -613,9 +616,11 @@ def findall(
# on Mac OS X and Windows, we want data files in the package dir
# (package_data will be ignored when using py2exe)
package_data = {
name: config["package_data"][name]
if sys.platform in ("darwin", "win32") and not do_py2app and not do_py2exe
else []
name: (
config["package_data"][name]
if sys.platform in ("darwin", "win32") and not do_py2app and not do_py2exe
else []
)
}
if sdist and sys.platform in ("darwin", "win32"):
package_data[name].extend(
Expand All @@ -642,7 +647,33 @@ def findall(
)
)
else:
data_files.append((doc, [os.path.join(pydir, "..", "LICENSE.txt")]))
data_files.append(
(
doc,
[
relpath(
os.path.join(pydir, "..", "LICENSE.txt"),
source_dir
)
]
)
)

# metainfo / appdata.xml
data_files.append(
(
os.path.join(os.path.dirname(data), "metainfo"),
[
relpath(
os.path.normpath(
os.path.join(pydir, "..", "dist", f"{appstream_id}.appdata.xml")
),
source_dir,
)
],
)
)

if sys.platform not in ("darwin", "win32") or do_py2app or do_py2exe:
# Linux/Unix or py2app/py2exe
data_files += get_data(data, "package_data", name, excludes=["theme/icons/*"])
Expand Down Expand Up @@ -692,12 +723,6 @@ def findall(
print("WARNING: OpenAL32.dll not found!")
elif sys.platform != "darwin":
# Linux
data_files.append(
(
os.path.join(os.path.dirname(data), "metainfo"),
[os.path.join(pydir, "..", "dist", appstream_id + ".appdata.xml")],
)
)
data_files.append(
(
os.path.join(os.path.dirname(data), "applications"),
Expand All @@ -709,9 +734,11 @@ def findall(
)
data_files.append(
(
autostart
if os.geteuid() == 0 or prefix.startswith("/")
else autostart_home,
(
autostart
if os.geteuid() == 0 or prefix.startswith("/")
else autostart_home
),
[
os.path.join(
pydir,
Expand Down Expand Up @@ -911,7 +938,8 @@ def findall(
from distutils.core import setup, Extension
setup(ext_modules=[Extension("{name}.lib{bits}.RealDisplaySizeMM", sources={sources}, define_macros={macros}, extra_link_args={link_args})])""",
] + sys.argv[1:],
]
+ sys.argv[1:],
stdout=sp.PIPE,
stderr=sp.STDOUT,
)
Expand Down Expand Up @@ -956,12 +984,7 @@ def findall(
if sdist:
# For source distributions we want all libraries
for pycompat in ("38", "39", "310", "311"):
packages.extend(
[
f"{name}.lib{bits}",
f"{name}.lib{bits}.python{pycompat}"
]
)
packages.extend([f"{name}.lib{bits}", f"{name}.lib{bits}.python{pycompat}"])
elif sys.platform == "darwin":
# On Mac OS X we only want the universal binaries
packages.append(f"{name}.lib{bits}")
Expand Down Expand Up @@ -995,7 +1018,7 @@ def findall(
],
"data_files": data_files,
"description": description,
"download_url": f"https://{DOMAIN}/download/{name}-{version}.tar.gz",
"download_url": f"{development_home_page}/releases/download/{version}/{name}-{version}.tar.gz",
"ext_modules": ext_modules,
"license": "GPL v3",
"long_description": longdesc,
Expand All @@ -1005,8 +1028,7 @@ def findall(
"package_data": package_data,
"package_dir": {name: name},
"platforms": [
"Python >= %s <= %s"
% (
"Python >= {} <= {}".format(
".".join(str(n) for n in py_minversion),
".".join(str(n) for n in py_maxversion),
),
Expand All @@ -1024,13 +1046,14 @@ def findall(
if setuptools:
attrs["entry_points"] = {
"gui_scripts": [
"%s = %s.main:main%s"
% (
"{} = {}.main:main{}".format(
script,
name,
""
if script == name.lower()
else script[len(name):].lower().replace("-", "_"),
(
""
if script == name.lower()
else script[len(name):].lower().replace("-", "_")
),
)
for script, desc in scripts
]
Expand Down Expand Up @@ -1271,7 +1294,7 @@ def copy_package_data(self, package, target_dir):
"excludes": config["excludes"]["all"] + config["excludes"]["win32"],
"bundle_files": 3 if wx.VERSION >= (2, 8, 10, 1) else 1,
"compressed": 1,
"optimize": 0 # 0 = don’t optimize (generate .pyc)
"optimize": 0, # 0 = don’t optimize (generate .pyc)
# 1 = normal optimization (like python -O)
# 2 = extra optimization (like python -OO)
}
Expand Down Expand Up @@ -1545,8 +1568,7 @@ def copy_package_data(self, package, target_dir):
for _datadir, datafiles in attrs.get("data_files", []):
for datafile in datafiles:
manifest_in.append(
"include "
+ (
"include {}".format(
relpath(os.path.sep.join(datafile.split("/")), source_dir)
or datafile
)
Expand All @@ -1568,13 +1590,16 @@ def copy_package_data(self, package, target_dir):
"include " + os.path.sep.join([pkgdir] + obj.split("/"))
)
for pymod in attrs.get("py_modules", []):
manifest_in.append("include " + os.path.join(*pymod.split(".")))
manifest_in.append("include " + os.path.join(name, "theme", "theme-info.txt"))
manifest_in.append("include {}".format(os.path.join(*pymod.split("."))))
manifest_in.append(
"recursive-include %s %s %s"
% (os.path.join(name, "theme", "icons"), "*.icns", "*.ico")
"include {}".format(os.path.join(name, "theme", "theme-info.txt"))
)
manifest_in.append("include " + os.path.join("man", "*.1"))
manifest_in.append(
"recursive-include {} {} {}".format(
os.path.join(name, "theme", "icons"), "*.icns", "*.ico"
)
)
manifest_in.append("include {}".format(os.path.join("man", "*.1")))
manifest_in.append("recursive-include misc *")
if skip_instrument_conf_files:
manifest_in.extend(
Expand All @@ -1584,9 +1609,9 @@ def copy_package_data(self, package, target_dir):
"exclude misc/*.usermap",
]
)
manifest_in.append("include " + os.path.join("screenshots", "*.png"))
manifest_in.append("include " + os.path.join("scripts", "*"))
manifest_in.append("include " + os.path.join("tests", "*"))
manifest_in.append("include {}".format(os.path.join("screenshots", "*.png")))
manifest_in.append("include {}".format(os.path.join("scripts", "*")))
manifest_in.append("include {}".format(os.path.join("tests", "*")))
manifest_in.append("recursive-include theme *")
manifest_in.append("recursive-include util *.cmd *.py *.sh")
if sys.platform == "win32" and not setuptools:
Expand All @@ -1609,7 +1634,7 @@ def copy_package_data(self, package, target_dir):
pydir,
"..",
"dist",
"bbfreeze.%s-py%s" % (get_platform(), sys.version[:3]),
"bbfreeze.{}-py{}".format(get_platform(), sys.version[:3]),
)
sys.argv.insert(i + 1, f"--dist-dir={dist_dir}")
if "egg_info" not in sys.argv[1:i]:
Expand Down Expand Up @@ -1686,6 +1711,7 @@ def copy_package_data(self, package, target_dir):

def setup_do_py2exe():
import py2exe

# ModuleFinder can't handle runtime changes to __path__, but win32com
# uses them
try:
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ install_script = util/DisplayCAL_postinstall.py

[install]
record = INSTALLED_FILES

[black]
line-length = 88
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def setup():

replace_placeholders(
Path(pydir, "misc", f"{tmpl_name}.template.html"),
Path(pydir, tmpl_name + ".html"),
Path(pydir, f"{tmpl_name}.html"),
lastmod_time,
{"STABILITY": "Beta" if stability != "stable" else ""},
)
Expand Down Expand Up @@ -688,16 +688,19 @@ def setup():

languages = "\n\t\t".join(languages)
tmpl_name = appstream_id + ".appdata.xml"
misc_tmpl_name = Path(pydir, "misc", tmpl_name)
dist_tmpl_name = Path(pydir, "dist", tmpl_name)
replace_placeholders(
Path(pydir, "misc", tmpl_name),
Path(pydir, "dist", tmpl_name),
misc_tmpl_name,
dist_tmpl_name,
lastmod_time,
{
"APPDATAPROVIDES": provides,
"LANGUAGES": languages,
"CHANGELOG": format_changelog(changelog, "appstream"),
},
)

if appdata:
sys.argv.remove("appdata")

Expand Down
21 changes: 21 additions & 0 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -+-
import os
import pytest

from DisplayCAL.setup import get_data


@pytest.mark.parametrize(
"tgt_dir, key, pkgname, subkey, excludes", [
["DisplayCAL", "doc", None, None, ["LICENSE.txt"]]
]
)
def test_get_data_returns_relative_paths(
tgt_dir, key, pkgname, subkey, excludes
):
"""DisplayCAL.setup.get_data() returns relative paths."""
result = get_data(tgt_dir, key, pkgname, subkey, excludes)
all_paths = []
for r in result:
all_paths += r[1]
assert all([not os.path.isabs(path) for path in all_paths])

0 comments on commit f915df7

Please sign in to comment.