| 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 |
||
| 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 | |||
| 113 |