|
1 | 1 | """Python setup information.""" |
2 | 2 |
|
3 | | -import codecs |
4 | 3 | import os |
5 | 4 | import re |
| 5 | +from pathlib import Path |
6 | 6 |
|
7 | 7 | from setuptools import find_packages, setup |
8 | 8 |
|
9 | | -PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) |
10 | | -REQUIREMENTS_FILE = os.path.join(PROJECT_ROOT, "requirements.txt") |
11 | | -README_FILE = os.path.join(PROJECT_ROOT, "README.md") |
12 | | -VERSION_FILE = os.path.join(PROJECT_ROOT, "pyinfraformat", "__init__.py") |
| 9 | +PROJECT_ROOT = Path(os.path.realpath(__file__)).parent |
| 10 | +REQUIREMENTS_FILE = PROJECT_ROOT / "requirements.txt" |
| 11 | +README_FILE = PROJECT_ROOT / "README.md" |
| 12 | +VERSION_FILE = PROJECT_ROOT / "pyinfraformat" / "__init__.py" |
13 | 13 |
|
14 | 14 |
|
15 | 15 | def get_requirements(): |
16 | 16 | """Read contents from requirements.txt.""" |
17 | | - with codecs.open(REQUIREMENTS_FILE) as buff: |
| 17 | + with open(REQUIREMENTS_FILE, encoding="utf-8") as buff: |
18 | 18 | return buff.read().splitlines() |
19 | 19 |
|
20 | 20 |
|
21 | 21 | def get_long_description(): |
22 | 22 | """Read contents from README.md.""" |
23 | | - with codecs.open(README_FILE, "rt") as buff: |
| 23 | + with open(README_FILE, encoding="utf-8") as buff: |
24 | 24 | return buff.read() |
25 | 25 |
|
26 | 26 |
|
27 | 27 | def get_version(): |
28 | 28 | """Read version info from __init__.py.""" |
29 | | - lines = open(VERSION_FILE).readlines() |
| 29 | + with open(VERSION_FILE, encoding="utf-8") as buff: |
| 30 | + lines = buff.readlines() |
30 | 31 | version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]" |
31 | 32 | for line in lines: |
32 | 33 | version_search = re.search(version_regex, line, re.MULTILINE) |
|
0 commit comments