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

Drop support for Python 3.5 #184

Merged
merged 4 commits into from
Dec 2, 2020
Merged

Drop support for Python 3.5 #184

merged 4 commits into from
Dec 2, 2020

Conversation

drasmuss
Copy link
Member

And switch to some of the nice 3.6+ features (pathlib, ordered dicts, and f-strings).

@@ -20,7 +20,7 @@

There are two options for getting NengoDL working:

- Upgrade to Python >= 3.5
- Upgrade to Python >= 3.6

- Install an older version of NengoDL:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll change this "older version of NengoDL" to 3.4.0, since that's the latest to support Python 3.5 (if they're using earlier than 3.5, they'll have to figure things out themselves).

@@ -282,7 +282,7 @@
" plt.ylabel(\"Firing rates (Hz)\")\n",
" plt.xlabel(\"Timestep\")\n",
" plt.title(\n",
" \"Neural activities (conv0 mean=%dHz max=%dHz)\" % (rates.mean(), rates.max())\n",
" f\"Neural activities (conv0 mean={rates.mean()}Hz max={rates.max()}Hz)\"\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should have spaces before units (Hz). Also, we were formatting these as integers before; I might recommend one decimal place.

@@ -835,7 +838,9 @@ def test_profile(Simulator, mode, tmp_path):
with Simulator(net) as sim:
# note: TensorFlow bug if using profile_batch=1, see
# https://github.com/tensorflow/tensorflow/issues/37543
callback = callbacks.TensorBoard(log_dir=tmp_path / "profile", profile_batch=2)
callback = callbacks.TensorBoard(
log_dir=str(tmp_path / "profile"), profile_batch=2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need an explicit str call here, but not earlier in this file when we create a tf.keras.callbacks.TensorBoard? (callbacks.TensorBoard uses the same constructor, so I'd think they'd be the same.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I'm not sure. Generally I started by just passing in a Path wherever I could, and only converted it to a string if that failed. But I don't know why this one would have failed and the other didn't, maybe I just missed this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried removing the str and it fails. No idea why it fails here and not in the other place, but either way it's all on the TensorFlow side of things so all we can do is cast the paths to strings where required.

@@ -5,7 +5,6 @@
import contextlib
import logging
import warnings
from collections import OrderedDict
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm curious why pylint didn't detect these unused imports 🤷

@hunse
Copy link
Collaborator

hunse commented Dec 1, 2020

I've pushed the same fix here that I did in the Nengo PR, which is that we can't use f-strings in the code in __init__.py that errors if we're on Python 3.5 or less, because that code is meant to be executed by earlier python versions. Since version.py is imported before that, we also can't use them in version.py.

If this looks good to you @drasmuss, I'll squash and merge.

@drasmuss
Copy link
Member Author

drasmuss commented Dec 1, 2020

We could probably just drop that whole version warning as well. pip has supported python_requires (which is a better way of doing this) since version 9.0, which has been out since 2016. We added this code back in 2018, when it was plausible that people might still be using a pip version that old. But it seems pretty unlikely that people are installing modern versions of nengo-dl with super old pip versions at this point. And pip already gives a warning telling you that you should upgrade your pip version whenever you try to install a package using one of those old versions.

@hunse
Copy link
Collaborator

hunse commented Dec 1, 2020

Sure, sounds good. We still need to not use f-strings in version.py, though, because we import that in setup.py. And we should remove that f-string from setup.py too. (Right now if you try to pip install -e . in Python 3.5, you get a lengthy syntax error, rather than the concise error about needing a newer Python version.)

@drasmuss
Copy link
Member Author

drasmuss commented Dec 1, 2020

Maybe add a comment in setup/version.py explaining why we aren't using f-strings as well (I can see someone like me forgetting why we did this in the future).

Alternatively, I wonder if there's a way to monkeypatch out the python 3.6 features and try to parse setup.py, to catch errors like this. That seems like it'd be hard to do, but perhaps Python has some kind of built in support for evaling files with a given python version?

@tbekolay
Copy link
Member

tbekolay commented Dec 1, 2020

Another thing we could do is clean up nengo/nengo-bones#39 which puts the version in .nengobones.yml, which means we don't need to import version.py at all.

@drasmuss
Copy link
Member Author

drasmuss commented Dec 1, 2020

Looks like we might be able to use ast.parse("setup.py", feature_version=(3, 5)) to test setup.py for compatibility https://docs.python.org/3/library/ast.html#ast.parse

@hunse
Copy link
Collaborator

hunse commented Dec 1, 2020

Where would we put that ast.parse test? IMO, it's easier just to keep setup.py working with earlier Pythons. (Adding the comment is definitely a good idea.)

I do like the idea of moving the version into .nengobones.yml. I'm happy to dust off that PR now, if we think it's high enough priority, or we can leave it as future work.

@drasmuss
Copy link
Member Author

drasmuss commented Dec 1, 2020

Where would we put that ast.parse test? IMO, it's easier just to keep setup.py working with earlier Pythons. (Adding the comment is definitely a good idea.)

Probably tests/test_setup.py. And this would be ensuring that we're keeping setup.py working with earlier Pythons, it's not opposed to that I don't think.

@hunse
Copy link
Collaborator

hunse commented Dec 1, 2020

Ahh, got it, I misunderstood. I thought you meant we would use f-strings in setup.py, but then have some check that would run before setup.py on a pip install, to tell the user that their python is too old. Sure, I'll look at adding a test.

@drasmuss
Copy link
Member Author

drasmuss commented Dec 2, 2020

Pushed a minor update to the test, fixups LGTM!

nengo_dl/tests/test_setup.py Outdated Show resolved Hide resolved
@hunse
Copy link
Collaborator

hunse commented Dec 2, 2020

I added a fix for some warnings that we weren't importing Mapping from collections.abc. Once the tests pass, I'll merge.

NengoBones and others added 4 commits December 2, 2020 16:52
5f92079 - Fix codecov missing files with same names
01104fd - Extra f-string replacements
2f83812 - Drop support for Python 3.5
- Switch to using pathlib
- Stop using OrderedDict
- Switch to using f-strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants