Skip to content

Commit 538ead9

Browse files
Enhance setup.py: add function to retrieve latest wheel file and improve cleanup process
Updated SECURITY.md
1 parent 25ef6e9 commit 538ead9

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed

.idea/misc.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
| Version | Supported | Release Date |
44
|---------|-----------|--------------|
5+
| 0.2.x || 7th Aug 2025 |
56
| 0.1.x || 7th Aug 2025 |
67

78
## Reporting a Vulnerability

tool/setup.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
except ImportError:
1313
sys.exit(
1414
f"[x] Missing required dependencies (either wheel or setuptools)\n"
15-
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building."
15+
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building."
1616
)
1717

1818
print("[*] Starting setup.py script for pyCTools...\n")
@@ -25,24 +25,37 @@ def prompt_version():
2525
try:
2626
pattern = re.compile(r"^\d+\.\d+\.\d+(-[A-Za-z0-9]+)?$")
2727
while True:
28-
version = input("[?] Enter package version (format x.x.x or x.x.x-suffix): ").strip()
29-
if pattern.match(version):
28+
version_ = input("[?] Enter package version (format x.x.x or x.x.x-suffix): ").strip()
29+
if pattern.match(version_):
3030
print("\033[90m")
31-
return version
31+
return version_
3232
else:
3333
print("[!] Invalid version format. Expected something like 1.0.0 or 1.0.0-beta => Trying again...\n")
3434
except KeyboardInterrupt:
3535
sys.exit("\n[!] Version input interrupted. Exiting setup.\n")
3636

3737

38+
def get_latest_wheel(dist_dir: str, package_name: str):
39+
dist_path = pathlib.Path(dist_dir)
40+
pattern = f"{package_name}-*.whl"
41+
wheel_files = sorted(
42+
dist_path.glob(pattern),
43+
key=lambda p: p.stat().st_mtime,
44+
reverse=True
45+
)
46+
if not wheel_files:
47+
sys.exit(f"[x] No wheel files matching '{pattern}' found in {dist_dir}??")
48+
return wheel_files[0]
49+
50+
3851
# Path to the bin folder inside pyCTools
3952
bin_path = os.path.join("pyCTools", "bin")
4053

4154
# Check that bin exists and has x86 & x64 DLLs
4255
if not os.path.isdir(bin_path):
4356
sys.exit(
4457
"[x] 'pyCTools/bin/' folder not found.\n"
45-
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n"
58+
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n"
4659
)
4760

4861
# Check subfolders and DLL presence
@@ -51,17 +64,19 @@ def prompt_version():
5164
if not os.path.isdir(arch_path) or not any(f.lower().endswith(".dll") for f in os.listdir(arch_path)):
5265
sys.exit(
5366
f"[x] Missing DLLs in pyCTools/bin/{arch}/\n"
54-
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n"
67+
" Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n"
5568
)
5669

5770
# Ensure ../dist/pip/ exists
5871
output_dir = pathlib.Path(__file__).parent.parent / "dist" / "pip"
5972
output_dir.mkdir(parents=True, exist_ok=True)
6073

6174
try:
75+
version = prompt_version()
76+
6277
setup(
6378
name="pyCTools",
64-
version=prompt_version(),
79+
version=version,
6580
packages=find_packages(),
6681
include_package_data=True,
6782
package_data={
@@ -81,20 +96,8 @@ def prompt_version():
8196
},
8297
)
8398

84-
print("\033[0m\n[*] Completed setup.py execution successfully [To cleanup now].")
85-
if not os.path.isfile("../dist/bin.zip"):
86-
print(
87-
" Suggested action: Run 'distributionHelper.ps1' to create the distribution package for github releases.")
88-
print(" Suggested action: Execute the following to test in VENV:\n\033[96m"
89-
" cd ..\n"
90-
" python -m venv dist/venv_test\n"
91-
" dist\\venv_test\\Scripts\\Activate.ps1\n"
92-
" python -m pip install --upgrade pip\n"
93-
" pip install dist/pip/pyctools-0.2.0b0-py3-none-any.whl\n"
94-
" python example/hwrng_example.py\n"
95-
" python example/process_inspect_example.py\n"
96-
" deactivate\n"
97-
" Remove-Item -Recurse -Force dist\\venv_test\n\033[0m")
99+
whl_filename = get_latest_wheel("dist/pip", "pyctools")
100+
whl_filename = str(whl_filename).replace("\\", "/")
98101
except Exception as e:
99102
sys.exit(f"\033[0m[x] An error occurred during setup: {e}\n")
100103

@@ -103,4 +106,27 @@ def prompt_version():
103106
cleanup_path = pathlib.Path(__file__).parent / cleanup_dir
104107
if cleanup_path.exists() and cleanup_path.is_dir():
105108
shutil.rmtree(cleanup_path)
106-
print("\033[90m[*] Completed setup.py script cleanup successfully.\033[0m")
109+
print("\033[90m[*] Completed setup.py script cleanup successfully.\033[0m\n")
110+
111+
print("\033[0m\n[*] Completed setup.py execution.")
112+
if not os.path.isfile("../dist/bin.zip"):
113+
print(
114+
" Suggested action: Run 'distributionHelper.ps1' to create the distribution package for github releases.")
115+
print(" Suggested action: Execute the following to test in VENV:\n\033[96m"
116+
" cd ..\n"
117+
" python -m venv dist/venv_test\n"
118+
" dist\\venv_test\\Scripts\\Activate.ps1\n"
119+
" python -m pip install --upgrade pip\n"
120+
f" pip install dist/pip/{whl_filename}\n"
121+
" python example/hwrng_example.py\n"
122+
" python example/process_inspect_example.py\n"
123+
" deactivate\n"
124+
" Remove-Item -Recurse -Force dist\\venv_test\n\033[0m")
125+
126+
127+
print("[*] For local installation, run:")
128+
print(f" \033[96mpython -m pip install dist/pip/{whl_filename}\033[0m")
129+
print("[*] If you place the WHL file on the GitHub releases page, users can download it and install it with:")
130+
print(
131+
f" \033[96mpip install https://github.com/DefinetlyNotAI/PyCTools/releases/download/{version}/{whl_filename}\033[0m")
132+
print(f" > Assuming the version[{version}] entered earlier is the same as the tag release.\n")

0 commit comments

Comments
 (0)