1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-08-08 01:49:27 +03:00

setup: Move away from os.path to pathlib.Path

Drops usage of the glob module along the way as pathlib integrates glob
as well.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety
2023-06-07 16:58:31 +02:00
parent 8c9bc5d2d0
commit e749b4cf11

View File

@ -1,14 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import glob
import sys import sys
import os import os
import os.path
import re import re
import shutil import shutil
import subprocess import subprocess
import time import time
from pathlib import Path
from setuptools import setup, Extension, Command from setuptools import setup, Extension, Command
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
from setuptools.command.build_py import build_py from setuptools.command.build_py import build_py
@ -229,10 +228,9 @@ class my_sdist(sdist):
f2.close() f2.close()
def run(self): def run(self):
if not os.path.exists("build"): Path("build").mkdir(exist_ok=True)
os.mkdir("build")
if os.path.exists(".git"): if Path(".git").exists():
try: try:
self.gen_rpm_spec() self.gen_rpm_spec()
self.gen_authors() self.gen_authors()
@ -247,8 +245,10 @@ class my_sdist(sdist):
"ChangeLog" "ChangeLog"
] ]
for f in files: for f in files:
if os.path.exists(f): try:
os.unlink(f) Path(f).unlink()
except FileNotFoundError:
pass
else: else:
sdist.run(self) sdist.run(self)
@ -269,11 +269,12 @@ class my_test(Command):
if self.plat_name is not None: if self.plat_name is not None:
plat_specifier = f".{self.plat_name}-{sys.version_info[0]}.{sys.version_info[1]}" plat_specifier = f".{self.plat_name}-{sys.version_info[0]}.{sys.version_info[1]}"
return os.path.join(self.build_base, if hasattr(sys, "gettotalrefcount"):
'lib' + plat_specifier) plat_specifier += "-pydebug"
return Path(self.build_base, "lib" + plat_specifier).as_posix()
else: else:
dirs = glob.glob(os.path.join(self.build_base, dirs = [p.as_posix() for p in Path(self.build_base).glob("lib.*")]
"lib.*"))
if len(dirs) == 0: if len(dirs) == 0:
print("No build directory found, run 'setup.py build'") print("No build directory found, run 'setup.py build'")
sys.exit(1) sys.exit(1)