From d6d426107725b0e0dbd1baf51ddbdd7317a097db Mon Sep 17 00:00:00 2001 From: Marc White Date: Tue, 3 Dec 2024 15:59:38 +1100 Subject: [PATCH] Remove os path from _version.py --- src/access_nri_intake/_version.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/access_nri_intake/_version.py b/src/access_nri_intake/_version.py index 5fb8c37..a5cc03b 100644 --- a/src/access_nri_intake/_version.py +++ b/src/access_nri_intake/_version.py @@ -18,6 +18,7 @@ import re import subprocess import sys +from pathlib import Path from typing import Callable @@ -129,7 +130,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): rootdirs = [] for _ in range(3): - dirname = os.path.basename(root) + dirname = Path(root).name if dirname.startswith(parentdir_prefix): return { "version": dirname[len(parentdir_prefix) :], @@ -139,7 +140,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): "date": None, } rootdirs.append(root) - root = os.path.dirname(root) # up a level + root = Path(root).parent # up a level if verbose: print( @@ -658,12 +659,12 @@ def get_versions(): pass try: - root = os.path.realpath(__file__) + root = Path(__file__).resolve() # versionfile_source is the relative path from the top of the source # tree (where the .git directory might live) to this file. Invert # this to find the root from __file__. for _ in cfg.versionfile_source.split("/"): - root = os.path.dirname(root) + root = Path(root).parent except NameError: return { "version": "0+unknown",