From d4aacb45a070f05eddb5fbfec191b440e381e268 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 3 Jan 2025 09:59:53 -0500 Subject: Don't rely on git for version information The version information for the nsploit distribution is now defined in pyproject.toml, and we no longer attempt to obtain details via git-describe. As previously, the library version is made available via `nsploit.__version__`. The main benefit of working this way is to allow a proper install of nsploit from a simple tarball of the source code, or even a shallow git clone. In each of these cases, tag information will not usually be present. As an added feature over the previous system, nsploit will now report in its version string if the running version is from a source tree, rather than an installed copy. Signed-off-by: Malfurious --- hooks/bake_version.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 hooks/bake_version.py (limited to 'hooks') diff --git a/hooks/bake_version.py b/hooks/bake_version.py deleted file mode 100644 index f4cd935..0000000 --- a/hooks/bake_version.py +++ /dev/null @@ -1,26 +0,0 @@ -from hatchling.builders.hooks.plugin.interface import BuildHookInterface - -import os -import re - -filename = os.path.normpath(os.path.join("nsploit","__init__.py")) - -#put the file back when the build ends -class RestoreVersionFile: - def __init__(self,contents): - self.contents = contents - def __del__(self): - with open(filename,"w") as f: - f.write(self.contents) - -class BakeVersionBuildHook(BuildHookInterface): - def initialize(self,version,build_data): - with open(filename,"r") as f: - self.restore = RestoreVersionFile(f.read()) - pattern = r'(?i)^__version__ *= *(?P.+?)$' - match = re.search(pattern, self.restore.contents, flags=re.MULTILINE) - if not match: - raise ValueError("regex of version file failed") - span = match.span('version') - with open(filename,"w") as f: - f.write(f'{self.restore.contents[:span[0]]}"v{self.metadata.version}"{self.restore.contents[span[1]:]}') -- cgit v1.2.3