Skip to content

Commit 1ea063b

Browse files
eumirophibos
authored andcommitted
Use pathlib.Path
1 parent 1aeeb4b commit 1ea063b

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

docs/source/conf.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,13 @@
55
# serve to show the default.
66

77
import sys
8-
import os
8+
from pathlib import Path
99

1010
# If extensions (or modules to document with autodoc) are in another directory,
1111
# add these directories to sys.path here. If the directory is relative to the
1212
# documentation root, use os.path.abspath to make it absolute, like shown here.
1313
#sys.path.insert(0, os.path.abspath('.'))
14-
sys.path.insert(
15-
0,
16-
os.path.abspath(
17-
os.path.join(
18-
os.path.dirname(__file__),
19-
'../../'
20-
)
21-
)
22-
)
14+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
2315

2416
# -- General configuration ------------------------------------------------
2517

setup.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
#!/usr/bin/env python
22
import os
33
import sys
4+
from pathlib import Path
45
from setuptools import setup, find_packages
56

6-
base_dir = os.path.dirname(__file__)
7+
HERE = Path(__file__).resolve().parent
78

89
about = {}
9-
with open(os.path.join(base_dir, "overpy", "__about__.py")) as f:
10-
exec(f.read(), about)
10+
exec((HERE / "overpy" / "__about__.py").read_text(), about)
1111

12-
filename_readme = os.path.join(base_dir, "README.rst")
13-
if sys.version_info[0] == 2:
14-
import io
15-
fp = open(filename_readme, encoding="utf-8")
16-
else:
17-
fp = open(filename_readme, encoding="utf-8")
18-
long_description = fp.read()
12+
long_description = (HERE / "README.rst").read_text()
1913

2014
setup(
2115
name=about["__title__"],

tests/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import os
21
import sys
32
import threading
3+
from pathlib import Path
44
from threading import Lock
55

66
from socketserver import BaseRequestHandler, TCPServer, ThreadingMixIn
@@ -26,8 +26,7 @@ def get_response():
2626

2727

2828
def read_file(filename, mode="r"):
29-
filename = os.path.join(os.path.dirname(__file__), filename)
30-
return open(filename, mode).read()
29+
return (Path(__file__).resolve().parent / filename).open(mode).read()
3130

3231

3332
def new_server_thread(handle_cls, port=None):

0 commit comments

Comments
 (0)