Conditions | 9 |
Total Lines | 51 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import os |
||
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 | |||
95 |