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

python3Packages.pyobjc-core: init at 10.3.1 #336801

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions pkgs/development/python-modules/pyobjc-core/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
lib,
stdenv,
buildPythonPackage,
setuptools,
fetchPypi,
darwin,
}:

buildPythonPackage rec {
pname = "pyobjc-core";
version = "10.3.1";
ferrine marked this conversation as resolved.
Show resolved Hide resolved
src = fetchPypi {
pname = "pyobjc_core";
inherit version;
hash = "sha256-sgSoDMwHD5qz+K9COjolpv14fiKFCNAMTDD4rFOLpyA=";
};
pyproject = true;
build-system = [ setuptools ];


ferrine marked this conversation as resolved.
Show resolved Hide resolved
buildInputs = [
darwin.libffi
];

checkPhase = ''
# TODO: This library does not follow standard testing with pytest
# and implemented its own test runner bootstrapping unittest
python3 setup.py test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That command is deprecated. Can we use pytest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, it just fails with internal errors, not running any tests. In the source code testing is managed by this code and has additional bootstrapping in setup.py

'';

hardeningDisable = [ "strictoverflow" ]; # -fno-strict-overflow is not supported in clang on darwin
env.NIX_CFLAGS_COMPILE = toString [ "-Wno-error=deprecated-declarations" ];
postPatch = ''
# TODO: Make patch for setup.py
# ignore the manual include flag for ffi, appears that it needs a very specific ffi from sdk (needs confirmation)
substituteInPlace setup.py --replace-fail '"-I/usr/include/ffi"' '#"-I/usr/include/ffi"'
# make os.path.exists that can spoil objc4 return True
substituteInPlace setup.py --replace-fail 'os.path.join(self.sdk_root, "usr/include/objc/runtime.h")' '"/"'

# Turn off clang’s Link Time Optimization, or else we can’t recognize (and link) Objective C .o’s:
sed -r 's/"-flto=[^"]+",//g' -i setup.py
# Fix some test code:
grep -RF '"sw_vers"' | cut -d: -f1 | while IFS= read -r file ; do
sed -r "s+"sw_vers"+"/usr/bin/sw_vers"+g" -i "$file"
done
Comment on lines +35 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the test failures, but all of this should now be unnecessary.

Copy link
Contributor

@reckenrode reckenrode Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the SDK and LTO stuff should be unnecessary. LTO was fixed with the ld64 update in #307880.

The sw_vers stuff might still be?


# Disables broken tests and fixes some of them
# TODO: make a patch for tests
substituteInPlace \
PyObjCTest/test_nsdecimal.py \
--replace-fail "Cannot compare NSDecimal and decimal.Decimal" "Cannot compare NSDecimal and (\\\\w+.)?Decimal"
substituteInPlace \
PyObjCTest/test_bundleFunctions.py \
--replace-fail "os.path.expanduser(\"~\")" "\"/var/empty\""
substituteInPlace \
PyObjCTest/test_methodaccess.py \
--replace-fail "testClassThroughInstance2" \
"disable_testClassThroughInstance2"


# Fixes impurities in the package and fixes darwin min version
# TODO: Propose a patch that fixes it in a better way
# Force it to target our ‘darwinMinVersion’, it’s not recognized correctly:
grep -RF -- '-DPyObjC_BUILD_RELEASE=%02d%02d' | cut -d: -f1 | while IFS= read -r file ; do
sed -r '/-DPyObjC_BUILD_RELEASE=%02d%02d/{s/%02d%02d/${
lib.concatMapStrings (lib.fixedWidthString 2 "0") (
lib.splitString "." stdenv.targetPlatform.darwinMinVersion
)
}/;n;d;}' -i "$file"
done
Comment on lines +62 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also likely unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

darwinMinVersion probably shouldn’t be used even if it were. Build scripts should get the minimum version from MACOSX_DEPLOYMENT_TARGET.

# impurities:
( grep -RF '/usr/bin/xcrun' || true ; ) | cut -d: -f1 | while IFS= read -r file ; do
sed -r "s+/usr/bin/xcrun+$(which xcrun)+g" -i "$file"
done
( grep -RF '/usr/bin/python' || true ; ) | cut -d: -f1 | while IFS= read -r file ; do
sed -r "s+/usr/bin/python+$(which python)+g" -i "$file"
done
'';
meta = {
description = "The Python <-> Objective-C Bridge with bindings for macOS frameworks";
homepage = "https://pypi.org/project/pyobjc-core/";
platforms = lib.platforms.darwin;
ferrine marked this conversation as resolved.
Show resolved Hide resolved
maintainers = [ lib.maintainers.ferrine ];
};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12016,6 +12016,8 @@ self: super: with self; {

pyobihai = callPackage ../development/python-modules/pyobihai { };

pyobjc-core = callPackage ../development/python-modules/pyobjc-core { };

pyocd = callPackage ../development/python-modules/pyocd { };

pyocd-pemicro = callPackage ../development/python-modules/pyocd-pemicro { };
Expand Down
Loading