Skip to content

Commit

Permalink
v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhi33 committed Jun 3, 2022
1 parent 950a95d commit 13b2878
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 119 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="spkg",
version="0.3.6",
version="0.4.0",
author="xuanzhi33",
author_email="[email protected]",
url="https://github.com/xuanzhi33/spkg",
Expand Down
242 changes: 124 additions & 118 deletions spkg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
import os
import sys

def output(text):
print("\033[44m SPKG \033[0m " + text)

def print_done(text):
output("\033[42m DONE \033[0m " + text)

def print_error(text):
output("\033[41m ERROR \033[0m " + text)

def run_cmd(cmd):
output("\033[45m RUNNING \033[0m " + cmd)
os.system(cmd)

def help():
print("""
SPKG by xuanzhi33
Usage: spkg [COMMAND]
print("""\033[44m SPKG \033[0m by \033[1;92mxuanzhi33\033[0m
Usage: spkg [COMMAND]
Commands:
help, -h: show this help message and exit (default)
upload, -u: upload the package to pypi (equals to 'twine upload dist/*')
setup, -s: setup the package (equals to 'python3 setup.py sdist')
clear, -c: delete all .tar.gz files in 'dist' folder
pkg, -p: clear, setup, and upload the package
info, -in: show package info
setver [version] , -sv [version]: set package version
install [package] , -i [package]: install a package from pypi using 'pip3 install --upgrade [package]'
Options:
help, -h: show this help message and exit (default)
upload, -u: upload the package to pypi (equals to 'twine upload dist/*')
setup, -s: setup the package (equals to 'python3 setup.py sdist')
clear, -c: delete all .tar.gz files in 'dist' folder
pkg, -p: clear, setup, and upload the package
info, -i: show package info
pkgver, -pv: show package version
setver, -sv: set package version
The commands below can change package version quickly and then run 'pkg' command:
(They will modify the version in 'setup.py')
patch, -pa: Release patch update (e.g. 1.0.1 -> 1.0.2)
minor, -mi : Release minor update (e.g. 1.0.3 -> 1.1.0)
major, -ma: Release major update (e.g. 1.1.1 -> 2.0.0)
""")
The commands below can change package version quickly and then run 'pkg' command:
(They will modify the version in 'setup.py')
patch, -pa: Release patch update (e.g. 1.0.1 -> 1.0.2)
minor, -mi : Release minor update (e.g. 1.0.3 -> 1.1.0)
major, -ma: Release major update (e.g. 1.1.1 -> 2.0.0)""")

def upload():
print("\033[1;34mUploading package to pypi...\033[0m")
print("\033[1;30mRunning 'twine upload dist/*'...\033[0m")

os.system("twine upload dist/*")

print("\033[1;32mDone.\033[0m")
output("Uploading package to \033[34mpypi\033[0m...")
run_cmd("twine upload dist/*")
print_done("Package uploaded.")


def setup():
print("Setting up package")
print("Running 'python3 setup.py sdist'...")
os.system("python3 setup.py sdist")
print("Done.")

output("Setting up package...")
run_cmd("python3 setup.py sdist")
print_done("Setup successfully.")

def clear():
print("Deleting all .tar.gz files in 'dist' folder...")
output("Deleting all .tar.gz files in 'dist' folder...")
if os.path.exists("dist"):
files = os.listdir("dist")
for file in files:
if file.endswith(".tar.gz"):
os.remove("dist/" + file)
print("Removed:", file)
output("\033[41m REMOVED \033[0m " + file)
else:
print("No dist folder found.")
output("No dist folder found.")

print_done("All .tar.gz files in 'dist' folder deleted.")


def getAttrs(attrlist):
valList = []
Expand Down Expand Up @@ -82,109 +93,104 @@ def setAttr(attr, new):
else:
return False

def setver(ver):
info = getAttrs(["name", "version"])
if info[0] == "":
print("Package name not found in setup.py")
elif info[1] == "":
print("Package version not found in setup.py")
def setver(ver, info):
if setAttr("version", ver):
print_done("Verson of package '" + info[0] + "' changed from '" + info[1] + "' to '" + ver + "'")
else:
if setAttr("version", ver):
print("Verson of package '" + info[0] + "' changed from '" + info[1] + "' to '" + ver + "'")
else:
print("Failed to set package version.")
print_error("Failed to set package version.")

def getver():
info = getAttrs(["name", "version"])
if info[0] == "":
print("Package name not found in setup.py")
elif info[1] == "":
print("Package version not found in setup.py")
else:
print("Package name:", info[0])
print("Package version:", info[1])
def pkg_info(info):
output("Package name:", info[0])
output("Package version:", info[1])

def pkg():
clear()
setup()
upload()

def patch():
info = getAttrs(["name", "version"])
if info[0] == "":
print("Package name not found in setup.py")
elif info[1] == "":
print("Package version not found in setup.py")
else:
ver = info[1].split(".")
ver[-1] = str(int(ver[-1]) + 1)
ver = ".".join(ver)
setver(ver)
pkg()
def patch(info):
ver = info[1].split(".")
ver[-1] = str(int(ver[-1]) + 1)
ver = ".".join(ver)
setver(ver, info)
pkg()

def minor():
info = getAttrs(["name", "version"])
if info[0] == "":
print("Package name not found in setup.py")
elif info[1] == "":
print("Package version not found in setup.py")
else:
ver = info[1].split(".")
ver[-2] = str(int(ver[-2]) + 1)
ver[-1] = "0"
ver = ".".join(ver)
setver(ver)
pkg()

def major():
def minor(info):
ver = info[1].split(".")
ver[-2] = str(int(ver[-2]) + 1)
ver[-1] = "0"
ver = ".".join(ver)
setver(ver, info)
pkg()

def major(info):
ver = info[1].split(".")
ver[-3] = str(int(ver[-3]) + 1)
ver[-2] = "0"
ver[-1] = "0"
ver = ".".join(ver)
setver(ver, info)
pkg()

def check_pkg():
if not os.path.exists("setup.py"):
print_error("No setup.py found in current folder.")
return None

info = getAttrs(["name", "version"])
if info[0] == "":
print("Package name not found in setup.py")
elif info[1] == "":
print("Package version not found in setup.py")
else:
ver = info[1].split(".")
ver[-3] = str(int(ver[-3]) + 1)
ver[-2] = "0"
ver[-1] = "0"
ver = ".".join(ver)
setver(ver)
pkg()
print_error("Package name not found in setup.py")
return None
if info[1] == "":
print_error("Package version not found in setup.py")
return None

return info

def install_pkg(pkg):
run_cmd("pip3 install --upgrade " + pkg)

def main():
argv = sys.argv
if len(argv) == 1:
help()
elif argv[1] == "-h" or argv[1] == "help":
help()
elif argv[1] == "-u" or argv[1] == "upload":
upload()
elif argv[1] == "-s" or argv[1] == "setup":
setup()
elif argv[1] == "-c" or argv[1] == "clear":
clear()
elif argv[1] == "-p" or argv[1] == "pkg":
pkg()
elif argv[1] == "-i" or argv[1] == "info":
print("spkg by xuanzhi33")
elif argv[1] == "-pv" or argv[1] == "pkgver":
getver()
elif argv[1] == "-sv" or argv[1] == "setver":
if len(argv) == 3:
setver(argv[2])
else:
ver = input("new version: ")
setver(ver)
elif argv[1] == "-mi" or argv[1] == "minor":
minor()
elif argv[1] == "-ma" or argv[1] == "major":
major()
elif argv[1] == "-pa" or argv[1] == "patch":
patch()
else:
print("Unknown command:", argv[1])
help()
pkginfo = check_pkg()
if pkginfo is not None:
if argv[1] == "-u" or argv[1] == "upload":
upload()
elif argv[1] == "-s" or argv[1] == "setup":
setup()
elif argv[1] == "-c" or argv[1] == "clear":
clear()
elif argv[1] == "-p" or argv[1] == "pkg":
pkg()
elif argv[1] == "-in" or argv[1] == "info":
pkg_info(pkginfo)
elif argv[1] == "-sv" or argv[1] == "setver":
if len(argv) == 3:
setver(argv[2], pkginfo)
else:
ver = input("new version: ")
setver(ver, pkginfo)

elif argv[1] == "-mi" or argv[1] == "minor":
minor(pkginfo)
elif argv[1] == "-ma" or argv[1] == "major":
major(pkginfo)
elif argv[1] == "-pa" or argv[1] == "patch":
patch(pkginfo)
elif argv[1] == "-i" or argv[1] == "install":
if len(argv) == 3:
install_pkg(argv[2])
else:
pkg = input("package name: ")
install_pkg(pkg)
else:
print_error("Unknown command: " + argv[1])
help()

if __name__ == "__main__":
main()

0 comments on commit 13b2878

Please sign in to comment.