Skip to content

Commit f0e2746

Browse files
Refactor get_version function to use pathlib for file reading
- Replaced open() and os.path.join() with Path.read_text() for simplicity and readability.
1 parent 0a1a82f commit f0e2746

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Diff for: setup.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import shutil
44
import sys
5+
from pathlib import Path
56

67
from setuptools import find_packages, setup
78

@@ -35,16 +36,14 @@
3536

3637

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

4141

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

5049

0 commit comments

Comments
 (0)