python3Packages.astropy-helpers: fix build for py312+; python3Packages.astroquery: fix build (#424335)

This commit is contained in:
Peder Bergebakken Sundt
2025-08-27 01:28:47 +02:00
committed by GitHub
3 changed files with 111 additions and 32 deletions
@@ -1,30 +1,35 @@
{
lib,
buildPythonPackage,
fetchPypi,
isPy3k,
pythonAtLeast,
fetchFromGitHub,
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; {
patches = [
# Fixes build with Python 3.12+
./python-imp.patch
];
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 ];
};
}
@@ -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
@@ -1,8 +1,10 @@
{
pkgs,
lib,
buildPythonPackage,
fetchPypi,
fetchFromGitHub,
fetchpatch2,
astropy,
boto3,
requests,
keyring,
beautifulsoup4,
@@ -17,22 +19,35 @@
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;
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=";
})
];
propagatedBuildInputs = [
build-system = [
astropy-helpers
setuptools
];
dependencies = [
astropy
requests
keyring
@@ -41,11 +56,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"
@@ -54,6 +64,7 @@ buildPythonPackage rec {
nativeCheckInputs = [ pytestCheckHook ];
checkInputs = [
boto3
matplotlib
pillow
pytest
@@ -76,10 +87,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 ];
};
}