mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-16 11:12:21 +03:00
Refactor get_version function to use pathlib for file reading
- Replaced open() and os.path.join() with Path.read_text() for simplicity and readability.
This commit is contained in:
parent
0a1a82f2b3
commit
f0e27463c9
7
setup.py
7
setup.py
|
@ -2,6 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
@ -35,16 +36,14 @@ an older version of Django REST Framework:
|
||||||
|
|
||||||
|
|
||||||
def read(f):
|
def read(f):
|
||||||
with open(f, encoding='utf-8') as file:
|
return Path(f).read_text(encoding='utf-8')
|
||||||
return file.read()
|
|
||||||
|
|
||||||
|
|
||||||
def get_version(package):
|
def get_version(package):
|
||||||
"""
|
"""
|
||||||
Return package version as listed in `__version__` in `init.py`.
|
Return package version as listed in `__version__` in `init.py`.
|
||||||
"""
|
"""
|
||||||
with open(os.path.join(package, '__init__.py'), encoding='utf-8') as f:
|
init_py = Path(package, "__init__.py").read_text(encoding="utf-8")
|
||||||
init_py = f.read()
|
|
||||||
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
|
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user