|
1
|
|
|
import os |
|
2
|
|
|
import tempfile |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
def create_package(): |
|
6
|
|
|
file_path=os.path.abspath(input("Give python file location where all functions and import statements are written please: ").strip()) |
|
7
|
|
|
if(input("Will you like to add more python files which are imported by the main file? Yes/No:").lower().strip()=="yes"): |
|
8
|
|
|
extra_file_paths=[i for i in input("Give the location of extra_files seperated by space").split() if(i!="")] |
|
9
|
|
|
else: |
|
10
|
|
|
extra_file_paths=[] |
|
11
|
|
|
with tempfile.TemporaryDirectory() as tmpdirname: |
|
12
|
|
|
os.chdir(tmpdirname) |
|
13
|
|
|
os.system("git clone https://github.com/Souvic/package_creator.git") |
|
14
|
|
|
os.system("rm -rf ./package_creator/.git") |
|
15
|
|
|
|
|
16
|
|
|
package_name=input("Choose name of this package please: ") |
|
17
|
|
|
author_name=input("Author's name please: ") |
|
18
|
|
|
author_email=input("Author's EmailId please: ") |
|
19
|
|
|
|
|
20
|
|
|
python_requires=input("Required minimum Python version to run this package please(e.g. 3.6): ") |
|
21
|
|
|
|
|
22
|
|
|
rep_url=input("Go to github.com, create an empty repository with project name, copy-paste the link here please: ") |
|
23
|
|
|
if(not rep_url.lower().endswith(".git")): |
|
24
|
|
|
rep_url=rep_url+".git" |
|
25
|
|
|
with open("./package_creator/src/package_name/__init__.py","w") as f: |
|
26
|
|
|
f.write(open(file_path,"r").read()) |
|
27
|
|
|
os.system("pipreqs ./package_creator/") |
|
28
|
|
|
print("install_requires in setup.cfg is filled up with minimum requirements from pipreqs package") |
|
29
|
|
|
print("Feel free to change setup.cfg after this in your github repo directly in case of different versions to be used") |
|
30
|
|
|
with open("./package_creator/requirements.txt") as f: |
|
31
|
|
|
install_requires="".join(["\n\t"+i for i in f.read().replace("==",">=").split("\n")]) |
|
32
|
|
|
|
|
33
|
|
|
with open("./package_creator/setup.cfg","r") as f: |
|
34
|
|
|
su=f.read() |
|
35
|
|
|
su=su.format(package_name=package_name,author_name=author_name,author_email=author_email,python_requires=python_requires,install_requires=install_requires,rep_url=rep_url) |
|
36
|
|
|
with open("./package_creator/setup.cfg","w") as f: |
|
37
|
|
|
f.write(su) |
|
38
|
|
|
for ii in extra_file_paths: |
|
39
|
|
|
os.system(f"cp {ii} ./package_creator/src/package_name/") |
|
40
|
|
|
os.rename("./package_creator/src/package_name","./package_creator/src/"+package_name) |
|
41
|
|
|
|
|
42
|
|
|
#os.system("python3 -m twine upload --repository testpypi") |
|
43
|
|
|
os.chdir("./package_creator/") |
|
44
|
|
|
os.system("python3 -m build") |
|
45
|
|
|
os.system("git init") |
|
46
|
|
|
os.system("git add -A") |
|
47
|
|
|
#os.system("git add .") |
|
48
|
|
|
os.system("git commit -m 'First commit in the new package'") |
|
49
|
|
|
print("Uploading to github") |
|
50
|
|
|
print("Get ready with your github username and passtoken") |
|
51
|
|
|
os.system("git branch -M main") |
|
52
|
|
|
os.system(f"git remote add origin {rep_url}") |
|
53
|
|
|
os.system("git push -u origin main") |
|
54
|
|
|
print("Done!!") |
|
55
|
|
|
print("All set up!!") |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
def uploadpackage(): |
|
59
|
|
|
with tempfile.TemporaryDirectory() as tmpdirname: |
|
60
|
|
|
os.chdir(tmpdirname) |
|
61
|
|
|
rep_url=input("Copy-paste the link of the github repo of the project please: ") |
|
62
|
|
|
if(not rep_url.lower().endswith(".git")): |
|
63
|
|
|
rep_url=rep_url+".git" |
|
64
|
|
|
os.system(f"git clone {rep_url}") |
|
65
|
|
|
dir_ = [i for i in os.listdir() if os.path.isdir(i)][0] |
|
66
|
|
|
os.chdir(dir_) |
|
67
|
|
|
os.system(f"rm -rf ./dist") |
|
68
|
|
|
ft_=input("Are you uploading this package to PyPi for the first time? Yes/No:").lower().strip()=="no" |
|
69
|
|
|
if(): |
|
70
|
|
|
with open("./setup.cfg","r") as f: |
|
71
|
|
|
zz=f.read().split("\n") |
|
72
|
|
|
|
|
73
|
|
|
print(f"The old version number is : {zz[2][len('version = '):]}") |
|
74
|
|
|
new_version_number=input("Choose a new version number: ") |
|
75
|
|
|
zz[2][len("version = "):]=new_version_number |
|
|
|
|
|
|
76
|
|
|
with open("./setup.cfg","r") as f: |
|
77
|
|
|
f.write("\n".join(zz)) |
|
78
|
|
|
os.system("python3 -m build") |
|
79
|
|
|
os.system("git add -A") |
|
80
|
|
|
os.system("git commit -m 'First commit in the new package'") |
|
81
|
|
|
if(ft_): |
|
82
|
|
|
os.system(f"git tag v{new_version_number}") |
|
83
|
|
|
os.system("git push -u origin main") |
|
84
|
|
|
print("Updated github repo!") |
|
85
|
|
|
os.system("twine upload dist/*") |
|
86
|
|
|
print("Updated to PyPi!") |
|
87
|
|
|
|
|
88
|
|
|
if(input("Do you already have a github repo for the project? Yes/No:").lower().strip()=="yes"): |
|
89
|
|
|
uploadpackage() |
|
90
|
|
|
else: |
|
91
|
|
|
create_package() |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|