-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.ps1
More file actions
88 lines (77 loc) · 2.34 KB
/
package.ps1
File metadata and controls
88 lines (77 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# =========================
# PowerShell: Build Python Package
# =========================
# -------------------------
# CONFIG
# -------------------------
$packageName = "PyUtils"
$version = "1.0.0"
$author = "Shahm Najeeb"
$authorEmail = "Shahm_Najeeb@outlook.com"
$description = "Utility modules for terminal printing, exception handling, and updates."
$pythonVersion = ">=3.8"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
Set-Location $repoRoot
# -------------------------
# CLEAN OLD BUILDS
# -------------------------
$dirsToRemove = @("build", "dist", "$packageName.egg-info")
foreach ($dir in $dirsToRemove) {
if (Test-Path $dir) {
Remove-Item $dir -Recurse -Force
Write-Host "Removed old folder: $dir"
}
}
# -------------------------
# READ REQUIREMENTS
# -------------------------
$requirements = @()
$reqFile = Join-Path $repoRoot "requirements.txt"
if (Test-Path $reqFile) {
$requirements = Get-Content $reqFile | Where-Object { $_ -and ($_ -notmatch '^\s*#') }
$reqString = ($requirements | ForEach-Object { "'$_'" }) -join ", "
} else {
$reqString = ""
}
# -------------------------
# CREATE setup.py
# -------------------------
$setupContent = @"
from setuptools import setup, find_packages
setup(
name='$packageName',
version='$version',
author='$author',
author_email='$authorEmail',
description='$description',
packages=find_packages(),
install_requires=[$reqString],
python_requires='$pythonVersion',
include_package_data=True,
)
"@
$setupFile = Join-Path $repoRoot "setup.py"
$setupContent | Out-File -Encoding UTF8 $setupFile -Force
Write-Host "Generated setup.py"
# -------------------------
# INSTALL BUILD MODULE
# -------------------------
Write-Host "Ensuring build module is installed..."
python -m pip install --upgrade build
# -------------------------
# BUILD PACKAGE
# -------------------------
Write-Host "Building package..."
python -m build --sdist --wheel
Write-Host "Build finished."
# -------------------------
# CLEAN POST-BUILD
# -------------------------
$dirsToRemovePost = @("build", "$packageName.egg-info")
foreach ($dir in $dirsToRemovePost) {
if (Test-Path $dir) {
Remove-Item $dir -Recurse -Force
Write-Host "Removed post-build folder: $dir"
}
}
Write-Host "Build complete. Check the 'dist' folder for your wheel and sdist."