Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace configparser readfp with read_file #1428

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

ejona86
Copy link
Contributor

@ejona86 ejona86 commented May 27, 2024

readfp() was deprecated in Python 3.2 and removed in Python 3.12. read_file() is a drop-in replacement.

Fixes this error with Python 3.12:

Traceback (most recent call last):
  File "/usr/bin/pronterface.py", line 62, in <module>
    app = PronterApp(False)
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2596, in __init__
    self.mainwindow = PronterWindow(self)
                      ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 220, in __init__
    self.reload_ui()
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 288, in reload_ui
    self.create_menu()
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 862, in create_menu
    self.load_slic3r_configs(menus)
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2517, in load_slic3r_configs
    config = self.read_slic3r_config(configfile)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2562, in read_slic3r_config
    parser.readfp(add_header(open(configfile)), configfile)
    ^^^^^^^^^^^^^
AttributeError: 'RawConfigParser' object has no attribute 'readfp'. Did you mean: 'read'?

readfp() was [deprecated in Python 3.2][1] and [removed in Python
3.12][2]. read_file() is a drop-in replacement.

[1]: https://github.com/python/cpython/blob/dd0e8a62df8be2a09ef6035b4c92bd9a68a7b918/Lib/configparser.py#L757-L764
[2]: python/cpython@1fc41ae

Fixes this error with Python 3.12:
```
Traceback (most recent call last):
  File "/usr/bin/pronterface.py", line 62, in <module>
    app = PronterApp(False)
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2596, in __init__
    self.mainwindow = PronterWindow(self)
                      ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 220, in __init__
    self.reload_ui()
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 288, in reload_ui
    self.create_menu()
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 862, in create_menu
    self.load_slic3r_configs(menus)
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2517, in load_slic3r_configs
    config = self.read_slic3r_config(configfile)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/printrun/pronterface.py", line 2562, in read_slic3r_config
    parser.readfp(add_header(open(configfile)), configfile)
    ^^^^^^^^^^^^^
AttributeError: 'RawConfigParser' object has no attribute 'readfp'. Did you mean: 'read'?
```
@DivingDuck
Copy link
Collaborator

DivingDuck commented May 27, 2024

Nice finding and yes, we should change this.

Btw , we actually do not support Python 3.12, but but it is good to know if one have already start to test it with Pronterface.

@rockstorm101, I did a successful quick test locally for Windows with py3.10

@rockstorm101
Copy link
Collaborator

Very good report with helpful and on-point links. Many thanks.

@rockstorm101 rockstorm101 merged commit 7b199ed into kliment:master Jun 19, 2024
11 of 12 checks passed
@ejona86 ejona86 deleted the python-3.12 branch June 19, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants