From 4bdcc227b99f26d06a7392fb16bcd5bb2d3f1dc5 Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Fri, 11 Jul 2025 16:32:53 +0200 Subject: [PATCH 1/4] python3Packages.astropy-helpers: modernize --- .../astropy-helpers/default.nix | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pkgs/development/python-modules/astropy-helpers/default.nix b/pkgs/development/python-modules/astropy-helpers/default.nix index c803ac0449c3..d7e7cc42f1cd 100644 --- a/pkgs/development/python-modules/astropy-helpers/default.nix +++ b/pkgs/development/python-modules/astropy-helpers/default.nix @@ -1,30 +1,34 @@ { lib, buildPythonPackage, - fetchPypi, + fetchFromGitHub, isPy3k, pythonAtLeast, + setuptools, }: buildPythonPackage rec { pname = "astropy-helpers"; version = "4.0.1"; - format = "setuptools"; + pyproject = true; - # ModuleNotFoundError: No module named 'imp' disabled = !isPy3k || pythonAtLeast "3.12"; - doCheck = false; # tests requires sphinx-astropy - - src = fetchPypi { - inherit pname version; - sha256 = "f1096414d108778218d6bea06d4d9c7b2ff7c83856a451331ac194e74de9f413"; + src = fetchFromGitHub { + owner = "astropy"; + repo = "astropy-helpers"; + tag = "v${version}"; + hash = "sha256-MjL/I+ApyoyoD2NmKuKWpDbyuEgvBb2OBhxqj/w/3lk="; }; - meta = with lib; { + build-system = [ setuptools ]; + + pythonImportsCheck = [ "astropy_helpers" ]; + + meta = { description = "Utilities for building and installing Astropy, Astropy affiliated packages, and their respective documentation"; homepage = "https://github.com/astropy/astropy-helpers"; - license = licenses.bsd3; - maintainers = [ maintainers.smaret ]; + license = lib.licenses.bsd3; + maintainers = [ lib.maintainers.smaret ]; }; } From 927ca2bba0bb554429d0929dde56e00f0cc6befc Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Fri, 11 Jul 2025 16:34:21 +0200 Subject: [PATCH 2/4] python3Packages.astropy-helpers: fix build for py312+ --- .../astropy-helpers/default.nix | 9 +-- .../astropy-helpers/python-imp.patch | 63 +++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/python-modules/astropy-helpers/python-imp.patch diff --git a/pkgs/development/python-modules/astropy-helpers/default.nix b/pkgs/development/python-modules/astropy-helpers/default.nix index d7e7cc42f1cd..f0938e83a7ab 100644 --- a/pkgs/development/python-modules/astropy-helpers/default.nix +++ b/pkgs/development/python-modules/astropy-helpers/default.nix @@ -2,8 +2,6 @@ lib, buildPythonPackage, fetchFromGitHub, - isPy3k, - pythonAtLeast, setuptools, }: @@ -12,8 +10,6 @@ buildPythonPackage rec { version = "4.0.1"; pyproject = true; - disabled = !isPy3k || pythonAtLeast "3.12"; - src = fetchFromGitHub { owner = "astropy"; repo = "astropy-helpers"; @@ -21,6 +17,11 @@ buildPythonPackage rec { hash = "sha256-MjL/I+ApyoyoD2NmKuKWpDbyuEgvBb2OBhxqj/w/3lk="; }; + patches = [ + # Fixes build with Python 3.12+ + ./python-imp.patch + ]; + build-system = [ setuptools ]; pythonImportsCheck = [ "astropy_helpers" ]; diff --git a/pkgs/development/python-modules/astropy-helpers/python-imp.patch b/pkgs/development/python-modules/astropy-helpers/python-imp.patch new file mode 100644 index 000000000000..d12c2fb0e951 --- /dev/null +++ b/pkgs/development/python-modules/astropy-helpers/python-imp.patch @@ -0,0 +1,63 @@ +diff --git a/astropy_helpers/tests/test_git_helpers.py b/astropy_helpers/tests/test_git_helpers.py +index 6b826fc..3fb3a29 100644 +--- a/astropy_helpers/tests/test_git_helpers.py ++++ b/astropy_helpers/tests/test_git_helpers.py +@@ -1,5 +1,5 @@ + import glob +-import imp ++import importlib as imp + import os + import pkgutil + import re +diff --git a/astropy_helpers/utils.py b/astropy_helpers/utils.py +index 115c915..0cfc9e3 100644 +--- a/astropy_helpers/utils.py ++++ b/astropy_helpers/utils.py +@@ -1,12 +1,12 @@ + # Licensed under a 3-clause BSD style license - see LICENSE.rst + + import contextlib +-import imp + import os + import sys + import glob + + from importlib import machinery as import_machinery ++from importlib import util as importlib_util + + + # Note: The following Warning subclasses are simply copies of the Warnings in +@@ -54,9 +54,9 @@ def get_numpy_include_path(): + import builtins + if hasattr(builtins, '__NUMPY_SETUP__'): + del builtins.__NUMPY_SETUP__ +- import imp ++ import importlib + import numpy +- imp.reload(numpy) ++ importlib.reload(numpy) + + try: + numpy_include = numpy.get_include() +@@ -208,8 +208,6 @@ def import_file(filename, name=None): + # generates an underscore-separated name which is more likely to + # be unique, and it doesn't really matter because the name isn't + # used directly here anyway. +- mode = 'r' +- + if name is None: + basename = os.path.splitext(filename)[0] + name = '_'.join(os.path.relpath(basename).split(os.sep)[1:]) +@@ -221,8 +219,10 @@ def import_file(filename, name=None): + loader = import_machinery.SourceFileLoader(name, filename) + mod = loader.load_module() + else: +- with open(filename, mode) as fd: +- mod = imp.load_module(name, fd, filename, ('.py', mode, 1)) ++ importlib_util ++ spec = importlib_util.spec_from_file_location(name, filename) ++ mod = importlib_util.module_from_spec(spec) ++ spec.loader.exec_module(mod) + + return mod + From 9f91eeedcbd89f0d64fcf28717c5030e45796b85 Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Fri, 11 Jul 2025 19:45:35 +0200 Subject: [PATCH 3/4] python3Packages.astroquery: modernize --- .../python-modules/astroquery/default.nix | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/pkgs/development/python-modules/astroquery/default.nix b/pkgs/development/python-modules/astroquery/default.nix index 94ee306cd74e..3da2ea9c8c22 100644 --- a/pkgs/development/python-modules/astroquery/default.nix +++ b/pkgs/development/python-modules/astroquery/default.nix @@ -1,7 +1,7 @@ { - pkgs, + lib, buildPythonPackage, - fetchPypi, + fetchFromGitHub, astropy, requests, keyring, @@ -17,22 +17,26 @@ pyvo, astropy-helpers, setuptools, - isPy3k, }: buildPythonPackage rec { pname = "astroquery"; version = "0.4.10"; - format = "pyproject"; + pyproject = true; - src = fetchPypi { - inherit pname version; - hash = "sha256-6s2R6do3jmQXQPvDEjhQ2qg7oJJqb/9MQMy/XcbVpAY="; + src = fetchFromGitHub { + owner = "astropy"; + repo = "astroquery"; + tag = "v${version}"; + hash = "sha256-5pNKV+XNfUQca7WoWboVphXffzyVIHCmfxwr4nBMaEk="; }; - disabled = !isPy3k; + build-system = [ + astropy-helpers + setuptools + ]; - propagatedBuildInputs = [ + dependencies = [ astropy requests keyring @@ -41,11 +45,6 @@ buildPythonPackage rec { pyvo ]; - nativeBuildInputs = [ - astropy-helpers - setuptools - ]; - # Disable automatic update of the astropy-helper module postPatch = '' substituteInPlace setup.cfg --replace "auto_use = True" "auto_use = False" @@ -77,10 +76,10 @@ buildPythonPackage rec { pythonImportsCheck = [ "astroquery" ]; - meta = with pkgs.lib; { + meta = { description = "Functions and classes to access online data resources"; homepage = "https://astroquery.readthedocs.io/"; - license = licenses.bsd3; - maintainers = [ maintainers.smaret ]; + license = lib.licenses.bsd3; + maintainers = [ lib.maintainers.smaret ]; }; } From 549e1bdb99d771bab7205a3783887938b8596bee Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Fri, 11 Jul 2025 19:50:36 +0200 Subject: [PATCH 4/4] python3Packages.astroquery: fix build --- .../python-modules/astroquery/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/development/python-modules/astroquery/default.nix b/pkgs/development/python-modules/astroquery/default.nix index 3da2ea9c8c22..196c96fa62f6 100644 --- a/pkgs/development/python-modules/astroquery/default.nix +++ b/pkgs/development/python-modules/astroquery/default.nix @@ -2,7 +2,9 @@ lib, buildPythonPackage, fetchFromGitHub, + fetchpatch2, astropy, + boto3, requests, keyring, beautifulsoup4, @@ -31,6 +33,15 @@ buildPythonPackage rec { hash = "sha256-5pNKV+XNfUQca7WoWboVphXffzyVIHCmfxwr4nBMaEk="; }; + patches = [ + # https://github.com/astropy/astroquery/pull/3311 + (fetchpatch2 { + name = "setuptools-package-index.patch"; + url = "https://github.com/astropy/astroquery/commit/9d43beb4b7bea424d73fff0b602ca90026155519.patch"; + hash = "sha256-3QdOwP1rlWeScGxHT9ZVPmffE7S1XE0cbtnQ8T4bIYw="; + }) + ]; + build-system = [ astropy-helpers setuptools @@ -53,6 +64,7 @@ buildPythonPackage rec { nativeCheckInputs = [ pytestCheckHook ]; checkInputs = [ + boto3 matplotlib pillow pytest