From 3e5bd8c5a31b343fad0fd3af73fc670f28f99ce5 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:55:24 +0200 Subject: [PATCH] Changes for python 3.12 (#259) --- .github/workflows/build-and-test.yml | 10 +++++----- .github/workflows/github-deploy.yml | 16 ++++++++-------- ephem/doc/date.rst | 4 ++-- extensions/_libastro.c | 7 ++++++- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 998f19f..7fa0636 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,13 +12,13 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2019, macos-10.15] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build wheels - uses: pypa/cibuildwheel@v2.3.0 + uses: pypa/cibuildwheel@v2.16.2 env: CIBW_SKIP: pp* CIBW_TEST_COMMAND: python -m unittest discover ephem @@ -29,10 +29,10 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build wheels uses: pypa/cibuildwheel@v1.12.0 diff --git a/.github/workflows/github-deploy.yml b/.github/workflows/github-deploy.yml index ec0a052b7..54c7d21 100644 --- a/.github/workflows/github-deploy.yml +++ b/.github/workflows/github-deploy.yml @@ -11,12 +11,12 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2019, macos-10.15] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v4 name: Install Python with: python-version: '3.8' @@ -30,7 +30,7 @@ jobs: platforms: all - name: Build wheels - uses: pypa/cibuildwheel@v2.12.1 + uses: pypa/cibuildwheel@v2.16.2 env: #CIBW_ARCHS_LINUX: auto aarch64 ppc64le s390x CIBW_ARCHS_LINUX: auto aarch64 s390x @@ -46,9 +46,9 @@ jobs: name: Build source distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v4 name: Install Python with: python-version: '3.8' @@ -56,7 +56,7 @@ jobs: - name: Build sdist run: python setup.py sdist - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: path: dist/*.tar.gz @@ -64,7 +64,7 @@ jobs: needs: [build_wheels, build_sdist] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: artifact path: dist diff --git a/ephem/doc/date.rst b/ephem/doc/date.rst index 48baf2a..559c2a6 100644 --- a/ephem/doc/date.rst +++ b/ephem/doc/date.rst @@ -114,7 +114,7 @@ Datetime objects You can also ask a PyEphem date to convert itself the other direction by calling its ``datetime()`` method. - >>> from datetime import date, datetime + >>> from datetime import date, datetime, timezone >>> print(ephem.Date(datetime(2005, 4, 18, 22, 15))) 2005/4/18 22:15:00 @@ -138,7 +138,7 @@ Datetime objects >>> d = datetime.utcnow() >>> print(ephem.Date(d)) 2015/12/14 15:42:14 - >>> d = datetime.utcfromtimestamp(1450107734) + >>> d = datetime.fromtimestamp(1450107734, tz=timezone.utc) >>> print(ephem.Date(d)) 2015/12/14 15:42:14 diff --git a/extensions/_libastro.c b/extensions/_libastro.c index 24d89dd..a263cbe 100644 --- a/extensions/_libastro.c +++ b/extensions/_libastro.c @@ -3,6 +3,8 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#define PyUnicode_GetSize(o) PyUnicode_GET_SIZE(o) + #if PY_MAJOR_VERSION == 2 #define PyLong_AsLong PyInt_AsLong #define PyLong_FromLong PyInt_FromLong @@ -23,6 +25,9 @@ #define OB_REFCNT ob_base.ob_refcnt #if PY_MINOR_VERSION == 0 || PY_MINOR_VERSION == 1 || PY_MINOR_VERSION == 2 #define PyUnicode_AsUTF8 _PyUnicode_AsString +# elif PY_MINOR_VERSION >= 3 +#undef PyUnicode_GetSize +#define PyUnicode_GetSize PyUnicode_GET_LENGTH #endif #endif @@ -180,7 +185,7 @@ static int scansexa(PyObject *o, double *dp) { Py_DECREF(list); return -1; } - Py_ssize_t item_length = PyUnicode_GET_SIZE(item); + Py_ssize_t item_length = PyUnicode_GetSize(item); if (item_length == 0) { continue; /* accept empty string for 0 */ }