summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hooks/bake_version.py26
-rw-r--r--pyproject.toml11
-rw-r--r--sploit/__init__.py2
-rw-r--r--sploit/util.py20
4 files changed, 54 insertions, 5 deletions
diff --git a/hooks/bake_version.py b/hooks/bake_version.py
new file mode 100644
index 0000000..4d43228
--- /dev/null
+++ b/hooks/bake_version.py
@@ -0,0 +1,26 @@
+from hatchling.builders.hooks.plugin.interface import BuildHookInterface
+
+import os
+import re
+
+filename = os.path.normpath(os.path.join("sploit","__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<version>.+?)$'
+ 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]:]}')
diff --git a/pyproject.toml b/pyproject.toml
index 385c6ce..d4aa8b3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,5 @@
[project]
name = "sploit"
-version = "0.1"
description = "sploit is a process interaction automation tool with software exploitation focused utilities."
readme = "README.txt"
requires-python = ">=3.8"
@@ -10,6 +9,7 @@ authors = [
{name="dusoleil",email="howcansocksbereal@gmail.com"},
{name="Malfurious",email="m@lfurio.us"},
]
+dynamic = ["version"]
[project.urls]
"Homepage" = "https://github.com/dusoleil/sploit"
@@ -20,3 +20,12 @@ sploit = "sploit.main:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
+
+[tool.hatch.version]
+source = "code"
+path = "sploit/__init__.py"
+search-paths = ["."]
+expression = "__version__"
+
+[tool.hatch.build.hooks.custom]
+path = "hooks/bake_version.py"
diff --git a/sploit/__init__.py b/sploit/__init__.py
index f5a82fc..5bac38f 100644
--- a/sploit/__init__.py
+++ b/sploit/__init__.py
@@ -8,3 +8,5 @@ from sploit import (
util,
rev,
)
+
+__version__ = util.git_version()
diff --git a/sploit/util.py b/sploit/util.py
index c44ab78..3a2b842 100644
--- a/sploit/util.py
+++ b/sploit/util.py
@@ -1,14 +1,26 @@
+from os import path
from subprocess import run
-def run_cmd(cmd):
- return run(cmd,capture_output=True).stdout.decode('utf-8').split('\n')[:-1]
+def run_cmd(cmd,cwd=None):
+ return run(cmd,cwd=cwd,capture_output=True,text=True,check=True).stdout.split('\n')[:-1]
__RUN_CACHE__ = {}
-def run_cmd_cached(cmd):
+def run_cmd_cached(cmd,cwd=None):
key = ''.join(cmd)
if key in __RUN_CACHE__:
return __RUN_CACHE__[key]
else:
- result = run_cmd(cmd)
+ result = run_cmd(cmd,cwd)
__RUN_CACHE__[key] = result
return result
+
+#try to get the version through git
+def git_version():
+ try:
+ cwd = path.dirname(path.realpath(__file__))
+ version = run_cmd(["git","describe","--always","--first-parent","--dirty"],cwd=cwd)[0]
+ #PEP440 compliance
+ version = version.replace('-','+',1).replace('-','.')
+ return version
+ except:
+ return "0+unknown.version"