Skip to content

Refactor get_version to use a context manager for safe file handling #9669

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import shutil
import sys
from pathlib import Path

from setuptools import find_packages, setup

Expand Down Expand Up @@ -35,15 +36,14 @@


def read(f):
with open(f, encoding='utf-8') as file:
return file.read()
return Path(f).read_text(encoding='utf-8')


def get_version(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
init_py = Path(package, "__init__.py").read_text(encoding="utf-8")
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)


Expand Down
Loading