Skip to content

Commit 913583a

Browse files
authored
Merge pull request #122 from Tieqiong/win_memory
fix: win_py13 SystemError from pytest
2 parents 889ee05 + d6129aa commit 913583a

File tree

11 files changed

+82
-7
lines changed

11 files changed

+82
-7
lines changed

.github/workflows/matrix-and-codecov-on-merge-to-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: Billingegroup/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0
1616
with:
1717
project: diffpy.pdffit2
18-
python_versions: "3.11, 3.12"
18+
python_versions: "3.11, 3.12, 3.13"
1919
c_extension: true
2020
headless: false
2121
secrets:

.github/workflows/publish-docs-on-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
project: diffpy.pdffit2
1515
c_extension: true
1616
headless: false
17-
python_version: 3.12
17+
python_version: 3.13

.github/workflows/tests-on-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
project: diffpy.pdffi2
1515
c_extension: true
1616
headless: false
17-
python_version: 3.12
17+
python_version: 3.13
1818
secrets:
1919
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ If you use diffpy.pdffit2 in a scientific publication, we would like you to cite
7272
Installation
7373
------------
7474

75-
diffpy.pdffit2 supports Python 3.11 and 3.12.
75+
diffpy.pdffit2 supports Python 3.11, 3.12, and 3.13.
7676

7777
Windows, macOS (non-Arm64), Linux
7878
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -102,7 +102,7 @@ macOS (Arm64)
102102

103103
Create a new conda environment ``diffpy.pdffit2_env``: ::
104104

105-
conda create -n diffpy.pdffit2_env python=3.12
105+
conda create -n diffpy.pdffit2_env python=3.13
106106

107107
Activate the environment: ::
108108

@@ -121,7 +121,7 @@ Build from source
121121

122122
For advanced users, obtain the source archive, and in the ``diffpy.pdffit2`` directory, run ::
123123

124-
conda create -n diffpy.pdffit2_env python=3.12 \
124+
conda create -n diffpy.pdffit2_env python=3.13 \
125125
--file requirements/test.txt \
126126
--file requirements/conda.txt \
127127
--file requirements/build.txt

news/win_memory.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
**Added:**
2+
3+
* Added `restore_stdout` function and wrapper.
4+
* Added Python 3.13 support.
5+
6+
**Changed:**
7+
8+
* Changed `pytest` `capture_output` fixture. Now automatically restores `sys.stdout`.
9+
10+
**Deprecated:**
11+
12+
* <news item>
13+
14+
**Removed:**
15+
16+
* <news item>
17+
18+
**Fixed:**
19+
20+
* Fixed `SystemError` when running `pytest` on Windows with Python 3.13.
21+
22+
**Security:**
23+
24+
* <news item>

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ maintainers = [
1414
description = "PDFfit2 - real space structure refinement program."
1515
keywords = ["PDF", "structure refinement"]
1616
readme = "README.rst"
17-
requires-python = ">=3.11, <3.13"
17+
requires-python = ">=3.11, <3.14"
1818
classifiers = [
1919
'Development Status :: 5 - Production/Stable',
2020
'Environment :: Console',
@@ -27,6 +27,7 @@ classifiers = [
2727
'Operating System :: Unix',
2828
'Programming Language :: Python :: 3.11',
2929
'Programming Language :: Python :: 3.12',
30+
'Programming Language :: Python :: 3.13',
3031
'Topic :: Scientific/Engineering :: Physics',
3132
'Topic :: Scientific/Engineering :: Chemistry',
3233
]

src/diffpy/pdffit2/output.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,13 @@ def redirect_stdout(dst):
3939
return
4040

4141

42+
def restore_stdout():
43+
"""Restore the standard output."""
44+
from diffpy.pdffit2.pdffit2 import restore_stdout
45+
46+
restore_stdout()
47+
global stdout
48+
return
49+
50+
4251
# End of file

src/extensions/pdffit2module/bindings.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ struct PyMethodDef pypdffit2_methods[] = {
330330
{pypdffit2_redirect_stdout__name__, pypdffit2_redirect_stdout,
331331
METH_VARARGS, pypdffit2_redirect_stdout__doc__},
332332

333+
//restore_stdout
334+
{pypdffit2_restore_stdout__name__, pypdffit2_restore_stdout,
335+
METH_VARARGS, pypdffit2_restore_stdout__doc__},
336+
333337
//is_element
334338
{pypdffit2_is_element__name__, pypdffit2_is_element,
335339
METH_VARARGS, pypdffit2_is_element__doc__},

src/extensions/pdffit2module/misc.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,36 @@ PyObject * pypdffit2_redirect_stdout(PyObject *, PyObject *args)
22012201
return Py_None;
22022202
}
22032203

2204+
// restore_stdout
2205+
char pypdffit2_restore_stdout__doc__[] =
2206+
"Restore engine output to the default stream (std::cout).";
2207+
char pypdffit2_restore_stdout__name__[] =
2208+
"restore_stdout";
2209+
2210+
PyObject * pypdffit2_restore_stdout(PyObject *, PyObject *args)
2211+
{
2212+
// no arguments.
2213+
if (!PyArg_ParseTuple(args, ""))
2214+
return 0;
2215+
2216+
// If the global output stream pointer is not std::cout, then delete the custom stream.
2217+
if (NS_PDFFIT2::pout != &std::cout)
2218+
{
2219+
delete NS_PDFFIT2::pout;
2220+
NS_PDFFIT2::pout = &std::cout;
2221+
}
2222+
2223+
// Clean up the custom stream buffer
2224+
if (py_stdout_streambuf)
2225+
{
2226+
delete py_stdout_streambuf;
2227+
py_stdout_streambuf = nullptr;
2228+
}
2229+
2230+
Py_INCREF(Py_None);
2231+
return Py_None;
2232+
}
2233+
22042234
// is_element
22052235
char pypdffit2_is_element__doc__[] = "Check if element or isotope is defined in the built-in periodic table.";
22062236
char pypdffit2_is_element__name__[] = "is_element";

src/extensions/pdffit2module/misc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ extern char pypdffit2_redirect_stdout__name__[];
477477
extern "C"
478478
PyObject * pypdffit2_redirect_stdout(PyObject *, PyObject *);
479479

480+
// restore_stdout
481+
extern char pypdffit2_restore_stdout__doc__[];
482+
extern char pypdffit2_restore_stdout__name__[];
483+
extern "C"
484+
PyObject * pypdffit2_restore_stdout(PyObject *, PyObject *);
485+
480486
// is_element
481487
extern char pypdffit2_is_element__doc__[];
482488
extern char pypdffit2_is_element__name__[];

0 commit comments

Comments
 (0)