Passed
Push — main ( 087672...e77fa0 )
by Souvic
01:10
created

createmypypackage.exec()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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