Skip to content

Commit

Permalink
Minor fixups around pathlib usage
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed May 14, 2024
1 parent c539ebc commit 7f9ac68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 7 additions & 10 deletions komodoenv/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ def distro_versions():


def read_config() -> dict:
with open(
Path(__file__).parent / ".." / ".." / "komodoenv.conf", encoding="utf-8"
) as f:
with open(Path(__file__).parents[2] / "komodoenv.conf", encoding="utf-8") as f:
lines = f.readlines()
config = {}
for line in lines:
Expand Down Expand Up @@ -272,6 +270,7 @@ def get_pkg_version(
matches.append(match[1])
if len(matches) > 0:
return max(matches)
return None


def can_update(config: dict) -> bool:
Expand All @@ -294,9 +293,7 @@ def can_update(config: dict) -> bool:


def write_config(config: dict):
with open(
Path(__file__).parent / ".." / ".." / "komodoenv.conf", "w", encoding="utf-8"
) as f:
with open(Path(__file__).parents[2] / "komodoenv.conf", "w", encoding="utf-8") as f:
for key, val in config.items():
f.write(f"{key} = {val}\n")

Expand Down Expand Up @@ -341,7 +338,7 @@ def update_enable_script(komodo_prefix: Path, komodoenv_prefix: Path):

def rewrite_executable(path: Path, python: str, text: bytes):
path = path.resolve()
root = (path / ".." / "..").resolve()
root = path.parents[1]
libs = os.pathsep.join([str(root / "lib"), str(root / "lib64")])

newline_pos = text.find(b"\n")
Expand Down Expand Up @@ -369,7 +366,7 @@ def update_bins(srcpath: Path, dstpath: Path):
if shimdir.is_dir():
shutil.rmtree(shimdir)

os.mkdir(shimdir)
shimdir.mkdir()
for entry in (srcpath / "root" / "bin").iterdir():
if (dstpath / "root" / "bin" / entry.name).is_file():
continue
Expand All @@ -385,7 +382,7 @@ def update_bins(srcpath: Path, dstpath: Path):
text = f.read()
with open(shimpath, "wb") as f:
f.write(rewrite_executable(path, str(python), text))
os.chmod(shimpath, 0o755)
shimpath.chmod(0o755)


def create_pth(config: dict, srcpath: Path, dstpath: Path):
Expand Down Expand Up @@ -465,7 +462,7 @@ def main(args: List[str] = None):
if not (srcpath / "root").is_dir():
srcpath = Path(str(srcpath) + rhel_version_suffix())

dstpath = (Path(__file__).parent / ".." / "..").resolve()
dstpath = Path(__file__).resolve().parents[2] # komodoenv/root/bin/update.py
update_bins(srcpath, dstpath)
update_enable_script(srcpath, dstpath)
create_pth(config, srcpath, dstpath)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import sys
from pathlib import Path
from subprocess import check_output

from setuptools import setup


def download_bundled_wheels() -> None:
dest = os.path.join(os.path.dirname(__file__), "komodoenv", "bundle")
print(f"Downloading wheels to {os.path.realpath(dest)}")
dest = Path(__file__).parent / "komodoenv" / "bundle"
print(f"Downloading wheels to {dest.resolve()}")
check_output(
[
sys.executable,
Expand Down

0 comments on commit 7f9ac68

Please sign in to comment.