diff --git a/pkgs/development/python-modules/freetype-py/default.nix b/pkgs/development/python-modules/freetype-py/default.nix new file mode 100644 index 000000000000..52b9b2ea1fa0 --- /dev/null +++ b/pkgs/development/python-modules/freetype-py/default.nix @@ -0,0 +1,29 @@ +{ lib, buildPythonPackage, fetchPypi, substituteAll, stdenv, setuptools_scm, freetype }: + +buildPythonPackage rec { + pname = "freetype-py"; + version = "2.1.0.post1"; + + src = fetchPypi { + inherit pname version; + sha256 = "1k62fx53qrv9nb73mpqi2r11wzbx41qfv5qppvh6rylywnrknf3n"; + }; + + patches = [ + (substituteAll { + src = ./library-paths.patch; + freetype = "${freetype.out}/lib/libfreetype${stdenv.hostPlatform.extensions.sharedLibrary}"; + }) + ]; + + nativeBuildInputs = [ setuptools_scm ]; + + propagatedBuildInputs = [ freetype ]; + + meta = with lib; { + homepage = https://github.com/rougier/freetype-py; + description = "FreeType (high-level Python API)"; + license = licenses.bsd3; + maintainers = with maintainers; [ ]; + }; +} diff --git a/pkgs/development/python-modules/freetype-py/library-paths.patch b/pkgs/development/python-modules/freetype-py/library-paths.patch new file mode 100644 index 000000000000..a30c7e7355fa --- /dev/null +++ b/pkgs/development/python-modules/freetype-py/library-paths.patch @@ -0,0 +1,37 @@ +diff --git a/freetype/raw.py b/freetype/raw.py +index ff3bea3..78c68ab 100644 +--- a/freetype/raw.py ++++ b/freetype/raw.py +@@ -19,31 +19,7 @@ from freetype.ft_enums import * + from freetype.ft_errors import * + from freetype.ft_structs import * + +-# First, look for a bundled FreeType shared object on the top-level of the +-# installed freetype-py module. +-system = platform.system() +-if system == 'Windows': +- library_name = 'libfreetype.dll' +-elif system == 'Darwin': +- library_name = 'libfreetype.dylib' +-else: +- library_name = 'libfreetype.so' +- +-filename = os.path.join(os.path.dirname(freetype.__file__), library_name) +- +-# If no bundled shared object is found, look for a system-wide installed one. +-if not os.path.exists(filename): +- # on windows all ctypes does when checking for the library +- # is to append .dll to the end and look for an exact match +- # within any entry in PATH. +- filename = ctypes.util.find_library('freetype') +- +- if filename is None: +- if platform.system() == 'Windows': +- # Check current working directory for dll as ctypes fails to do so +- filename = os.path.join(os.path.realpath('.'), "freetype.dll") +- else: +- filename = library_name ++filename = "@freetype@" + + try: + _lib = ctypes.CDLL(filename) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 6f07d73493f9..71de105067c7 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -742,6 +742,8 @@ in { foxdot = callPackage ../development/python-modules/foxdot { }; + freetype-py = callPackage ../development/python-modules/freetype-py { }; + fsspec = callPackage ../development/python-modules/fsspec { }; furl = callPackage ../development/python-modules/furl { };