Skip to content

_GLOBAL constants #86

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

Merged
merged 12 commits into from
Jan 14, 2023
Merged

_GLOBAL constants #86

merged 12 commits into from
Jan 14, 2023

Conversation

BiffoBear
Copy link
Contributor

closes #84 Added _ to all global constants not referenced by other modules.

@dhalbert
Copy link
Contributor

@bill88t Would you like to test this? You could see how much the .mpy gets smaller with this change.

@bill88t
Copy link
Contributor

bill88t commented Dec 20, 2022

PR branch:
With -O0:

  5116 Dec 20 18:44 adafruit_wiznet5k_dhcp.mpy
 18781 Dec 20 18:41 adafruit_wiznet5k_dhcp.py
  2554 Dec 20 18:44 adafruit_wiznet5k_dns.mpy
  8659 Dec 20 18:41 adafruit_wiznet5k_dns.py
  9813 Dec 20 18:44 adafruit_wiznet5k.mpy
   715 Dec 20 18:44 adafruit_wiznet5k_ntp.mpy
  2300 Dec 20 18:41 adafruit_wiznet5k_ntp.py
 41968 Dec 20 18:41 adafruit_wiznet5k.py
  4761 Dec 20 18:45 adafruit_wiznet5k_socket.mpy
 20788 Dec 20 18:41 adafruit_wiznet5k_socket.py
  2417 Dec 20 18:45 adafruit_wiznet5k_wsgiserver.mpy
  8738 Dec 20 18:41 adafruit_wiznet5k_wsgiserver.py

With -O3:

  4681 Dec 20 18:48 adafruit_wiznet5k_dhcp.mpy
 18781 Dec 20 18:41 adafruit_wiznet5k_dhcp.py
  2379 Dec 20 18:47 adafruit_wiznet5k_dns.mpy
  8659 Dec 20 18:41 adafruit_wiznet5k_dns.py
  8357 Dec 20 18:48 adafruit_wiznet5k.mpy
   671 Dec 20 18:48 adafruit_wiznet5k_ntp.mpy
  2300 Dec 20 18:41 adafruit_wiznet5k_ntp.py
 41968 Dec 20 18:41 adafruit_wiznet5k.py
  4192 Dec 20 18:48 adafruit_wiznet5k_socket.mpy
 20788 Dec 20 18:41 adafruit_wiznet5k_socket.py
  2261 Dec 20 18:48 adafruit_wiznet5k_wsgiserver.mpy
  8738 Dec 20 18:41 adafruit_wiznet5k_wsgiserver.py

Main:
With -O0:

  5620 Dec 20 18:51 adafruit_wiznet5k_dhcp.mpy
 18687 Dec 20 18:40 adafruit_wiznet5k_dhcp.py
  2716 Dec 20 18:51 adafruit_wiznet5k_dns.mpy
  8635 Dec 20 18:40 adafruit_wiznet5k_dns.py
 10768 Dec 20 18:51 adafruit_wiznet5k.mpy
   715 Dec 20 18:51 adafruit_wiznet5k_ntp.mpy
  2300 Dec 20 18:40 adafruit_wiznet5k_ntp.py
 41778 Dec 20 18:40 adafruit_wiznet5k.py
  4806 Dec 20 18:51 adafruit_wiznet5k_socket.mpy
 20728 Dec 20 18:40 adafruit_wiznet5k_socket.py
  2417 Dec 20 18:51 adafruit_wiznet5k_wsgiserver.mpy
  8738 Dec 20 18:40 adafruit_wiznet5k_wsgiserver.py

With -O3:

  5159 Dec 20 18:52 adafruit_wiznet5k_dhcp.mpy
 18687 Dec 20 18:40 adafruit_wiznet5k_dhcp.py
  2532 Dec 20 18:52 adafruit_wiznet5k_dns.mpy
  8635 Dec 20 18:40 adafruit_wiznet5k_dns.py
  9259 Dec 20 18:53 adafruit_wiznet5k.mpy
   671 Dec 20 18:52 adafruit_wiznet5k_ntp.mpy
  2300 Dec 20 18:40 adafruit_wiznet5k_ntp.py
 41778 Dec 20 18:40 adafruit_wiznet5k.py
  4234 Dec 20 18:53 adafruit_wiznet5k_socket.mpy
 20728 Dec 20 18:40 adafruit_wiznet5k_socket.py
  2261 Dec 20 18:53 adafruit_wiznet5k_wsgiserver.mpy
  8738 Dec 20 18:40 adafruit_wiznet5k_wsgiserver.py

@dhalbert
Copy link
Contributor

@BiffoBear Sorry, I merged your #81, which caused merge conflicts on this.

@BiffoBear
Copy link
Contributor Author

@BiffoBear Sorry, I merged your #81, which caused merge conflicts on this.

Not to worry. I'll sort it out when I get up 😃

@tekktrik
Copy link
Member

tekktrik commented Jan 6, 2023

Does this need to be tested again post-merge from main?

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Jan 9, 2023

This change would provide a really great test for #197 on cookie cutter for testing the size of mpy compiled files from an automated action task.

FoamyGuy and others added 3 commits January 9, 2023 10:16
# Conflicts:
#	adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py
#	adafruit_wiznet5k/adafruit_wiznet5k_socket.py
@FoamyGuy
Copy link
Contributor

I tested this partially successfully with a Feather ESP32-S2.

For these 3 examples:

  • wiznet5k_simpletest.py
  • wiznet5k_wsgiserver.py
  • wiznet5k_aio_post.py

Everything is working as expected with this modified version of the library. However on this example wiznet5k_simpleserver.py I'm getting this exception raised:

Traceback (most recent call last):
  File "code.py", line 46, in <module>
  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 184, in __exit__
AttributeError: 'module' object has no attribute '_SNSR_SOCK_FIN_WAIT'

This does look like it's potentially to do with some of the renamed constants from this PR, but I'm not certain. The main branch of this library does execute the same example without raising an exception.

I think we'll want to figure out why this one behaves different and ideally try to make not raise the exception so that it'll behave the same as currently released library.

@BiffoBear
Copy link
Contributor Author

I think we'll want to figure out why this one behaves different and ideally try to make not raise the exception so that it'll behave the same as currently released library.

Thanks for the review @FoamyGuy. You're right. I'll take a look at this and push a fix.

Cheers,
Martin

@FoamyGuy
Copy link
Contributor

I should have mentioned as well:

That exception comes after the server receives some data. These were my steps:

  • Run simpleserver on the microcontroller
  • On a PC on the same network run telnet [ip] 50007
  • Paste in 1024 bytes of data and send it. (I got it from "t"*1024 in another python script then copy/paste)
  • The server code receives the data and prints it out then raises the exception

@BiffoBear
Copy link
Contributor Author

That exception comes after the server receives some data. These were my steps:

  • Run simpleserver on the microcontroller
  • On a PC on the same network run telnet [ip] 50007
  • Paste in 1024 bytes of data and send it. (I got it from "t"*1024 in another python script then copy/paste)
  • The server code receives the data and prints it out then raises the exception

Hi, I've fixed the problem and your Telnet test now works on my system, the data is printed in the Mu serial and echoed back on my Telnet session. Hope it works for you too.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Tested successfully on the latest version with Feather ESP32-S2 TFT.

Thanks for the memory improvement!

@FoamyGuy FoamyGuy merged commit 73bb5b6 into adafruit:main Jan 14, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 15, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.13.3 from 1.13.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#82 from BiffoBear/NTP_fix_infinite_loop
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#86 from BiffoBear/_GLOBAL_constants

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
@BiffoBear BiffoBear deleted the _GLOBAL_constants branch January 17, 2023 00:12
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.

Prefix global constants with _ when possible
5 participants