Skip to content

Commit

Permalink
Remove python 3.7 support (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
gecrooks authored Jan 22, 2021
1 parent c57547d commit 2575bc2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.8', '3.9']

steps:
- uses: actions/checkout@v2
Expand Down
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# gecrooks-python-template: Minimal viable setup for an open source, github hosted, python package


![Build Status](https://github.com/gecrooks/gecrooks-python-template/workflows/Build/badge.svg) [![Documentation Status](https://readthedocs.org/projects/gecrooks-python-template/badge/?version=latest)](https://gecrooks-python-template.readthedocs.io/en/latest/?badge=latest)
![Build Status](https://github.com/gecrooks/gecrooks-python-template/workflows/Build/badge.svg)

[Source](https://github.com/gecrooks/gecrooks-python-template)

Expand Down Expand Up @@ -165,7 +165,6 @@ Classifiers=
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Scientific/Engineering
Expand All @@ -176,11 +175,10 @@ Classifiers=
[options]
zip_safe = True
python_requires = >= 3.7
python_requires = >= 3.8
packages = find:
install_requires =
importlib_metadata # required for python 3.7
numpy # example
setup_requires =
Expand All @@ -202,7 +200,7 @@ dev =
```

It's good practice to support at least two consecutive versions of python. Starting with 3.9, python is moving to an annual [release schedule](https://www.python.org/dev/peps/pep-0602/). The initial 3.x.0 release will be in early October and the first bug patch 3.x.1 in early December, second in February, and so on. Since it takes many important packages some time to upgrade (e.g. numpy and tensorflow are often bottlenecks), one should probably plan to upgrade python support by February each year. Upgrading involves changing the python version numbers in the tests and `config.cfg`, and then cleaning up any `__future__` or conditional imports, or other hacks added to maintain compatibility with older python releases.
It's good practice to support at least two consecutive versions of python. Starting with 3.9, python is moving to an annual [release schedule](https://www.python.org/dev/peps/pep-0602/). The initial 3.x.0 release will be in early October and the first bug patch 3.x.1 in early December, second in February, and so on. Since it takes many important packages some time to upgrade (e.g. numpy and tensorflow are often bottlenecks), one should probably plan to upgrade python support around the beginning of each year. Upgrading involves changing the python version numbers in the tests and `config.cfg`, and then cleaning up any `__future__` or conditional imports, or other hacks added to maintain compatibility with older python releases. If you protected the master branch on github, and added required status checks, you'll need to update those too.


We can now install our package (as editable -e, so that the code in our repo is live).
Expand All @@ -223,12 +221,8 @@ My favored approach is use git tags as the source of truth (Option 7 in the abov
The convention is that the version number of a python packages should be available as `packagename.__version__`.
So we add the following code to `example_python_project/config.py` to extract the version number metadata.
```
try:
# python >= 3.8
from importlib import metadata as importlib_metadata # type: ignore
except ImportError: # pragma: no cover
# python == 3.7
import importlib_metadata # type: ignore # noqa: F401
from importlib import metadata as importlib_metadata
__all__ = ["__version__", "about"]
Expand All @@ -250,7 +244,7 @@ from .config import __version__ as __version__ # noqa: F401
```
We put the code to extract the version number in `config.py` and not `__init__.py`, because we don't want to pollute our top level package namespace.

The various pragmas in the code above ("pragma: no cover" and "type: ignore") are there because the conditional import needed for python 3.7 compatibility confuses both our type checker and code coverage tools.
The various pragmas in the code above ("pragma: no cover" and "type: ignore") are there because the conditional imports confuse both our type checker and code coverage tools.

## about

Expand Down Expand Up @@ -527,7 +521,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8']
python-version: ['3.8', '3.9']
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion example_python_project/.github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.8', '3.9']

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 4 additions & 11 deletions example_python_project/example_python_project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
import re
import sys
import typing

try:
# python >= 3.8
from importlib import metadata as importlib_metadata # type: ignore
except ImportError: # pragma: no cover
# python == 3.7
import importlib_metadata # type: ignore # noqa: F401

from importlib import metadata as importlib_metadata

__all__ = ["__version__", "about"]

Expand All @@ -38,7 +31,7 @@ def about(file: typing.TextIO = None) -> None:
Args:
file: Output stream (Defaults to stdout)
"""
metadata = importlib_metadata.metadata(__package__) # type: ignore
metadata = importlib_metadata.metadata(__package__)
print(f"# {metadata['Name']}", file=file)
print(f"{metadata['Summary']}", file=file)
print(f"{metadata['Home-page']}", file=file)
Expand All @@ -49,10 +42,10 @@ def about(file: typing.TextIO = None) -> None:
versions[__package__] = __version__
versions["python"] = sys.version[0:5]

for req in importlib_metadata.requires(__package__): # type: ignore
for req in importlib_metadata.requires(__package__):
name = re.split("[; =><]", req)[0]
try:
versions[name] = importlib_metadata.version(name) # type: ignore
versions[name] = importlib_metadata.version(name)
except Exception: # pragma: no cover
pass

Expand Down
4 changes: 1 addition & 3 deletions example_python_project/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Classifiers=
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Scientific/Engineering
Expand All @@ -43,11 +42,10 @@ Classifiers=

[options]
zip_safe = True
python_requires = >= 3.7
python_requires = >= 3.8
packages = find:

install_requires =
importlib_metadata # required for python 3.7
numpy # example

setup_requires =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.8', '3.9']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 1 addition & 3 deletions {{cookiecutter.module_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Classifiers=
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Scientific/Engineering
Expand All @@ -43,11 +42,10 @@ Classifiers=

[options]
zip_safe = True
python_requires = >= 3.7
python_requires = >= 3.8
packages = find:

install_requires =
importlib_metadata # required for python 3.7
numpy # example

setup_requires =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
import re
import sys
import typing

try:
# python >= 3.8
from importlib import metadata as importlib_metadata # type: ignore
except ImportError: # pragma: no cover
# python == 3.7
import importlib_metadata # type: ignore # noqa: F401

from importlib import metadata as importlib_metadata

__all__ = ["__version__", "about"]

Expand All @@ -38,7 +31,7 @@ def about(file: typing.TextIO = None) -> None:
Args:
file: Output stream (Defaults to stdout)
"""
metadata = importlib_metadata.metadata(__package__) # type: ignore
metadata = importlib_metadata.metadata(__package__)
print(f"# {metadata['Name']}", file=file)
print(f"{metadata['Summary']}", file=file)
print(f"{metadata['Home-page']}", file=file)
Expand All @@ -49,10 +42,10 @@ def about(file: typing.TextIO = None) -> None:
versions[__package__] = __version__
versions["python"] = sys.version[0:5]

for req in importlib_metadata.requires(__package__): # type: ignore
for req in importlib_metadata.requires(__package__):
name = re.split("[; =><]", req)[0]
try:
versions[name] = importlib_metadata.version(name) # type: ignore
versions[name] = importlib_metadata.version(name)
except Exception: # pragma: no cover
pass

Expand Down

0 comments on commit 2575bc2

Please sign in to comment.