Conditions | 9 |
Total Lines | 55 |
Code Lines | 47 |
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 |
||
30 | def create_package(): |
||
31 | file_path=os.path.abspath(os.path.expanduser(input("Give python file location where all functions and import statements are written please: ").strip())) |
||
32 | if(check_("Will you like to add more python files which are imported by the main file? yes/no: ")): |
||
33 | extra_file_paths=set([os.path.abspath(os.path.expanduser(i)) for i in input("Give the location of extra_files seperated by space : ").split() if(i!="")]) |
||
34 | else: |
||
35 | extra_file_paths=[] |
||
36 | with tempfile.TemporaryDirectory() as tmpdirname: |
||
37 | os.chdir(tmpdirname) |
||
38 | exec("git clone -q https://github.com/Souvic/package_creator.git") |
||
39 | exec("rm -rf ./package_creator/.git") |
||
40 | |||
41 | package_name=input("Choose name of this package please: ") |
||
42 | author_name=input("Author's name please: ") |
||
43 | author_email=input("Author's EmailId please: ") |
||
44 | |||
45 | python_requires=input("Required minimum Python version to run this package please(e.g. 3.6): ") |
||
46 | |||
47 | rep_url=input("Go to github.com, create an empty repository(without any file) with project name, copy-paste the link here please: ") |
||
48 | if(not rep_url.lower().endswith(".git")): |
||
49 | rep_url=rep_url+".git" |
||
50 | format_readme(rep_url) |
||
51 | with open("./package_creator/src/package_name/__init__.py","w") as f: |
||
52 | f.write(open(file_path,"r").read()) |
||
53 | exec("pipreqs ./package_creator/") |
||
54 | print("install_requires in setup.cfg is filled up with minimum requirements from pipreqs package") |
||
55 | print("Feel free to change setup.cfg after this in your github repo directly in case of different versions to be used") |
||
56 | with open("./package_creator/requirements.txt") as f: |
||
57 | install_requires="".join(["\n\t"+i for i in f.read().replace("==",">=").split("\n")]) |
||
58 | |||
59 | with open("./package_creator/setup.cfg","r") as f: |
||
60 | su=f.read() |
||
61 | 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) |
||
62 | with open("./package_creator/setup.cfg","w") as f: |
||
63 | f.write(su) |
||
64 | for ii in extra_file_paths: |
||
65 | exec(f"cp {ii} ./package_creator/src/package_name/") |
||
66 | os.rename("./package_creator/src/package_name","./package_creator/src/"+package_name) |
||
67 | |||
68 | #exec("python3 -m twine upload --repository testpypi") |
||
69 | os.chdir("./package_creator/") |
||
70 | exec("python3 -m build") |
||
71 | exec("git init") |
||
72 | exec("git add -A") |
||
73 | #exec("git add .") |
||
74 | exec("git commit -m 'First commit in the new package'") |
||
75 | print("Uploading to github") |
||
76 | print("Get ready with your github username and passtoken") |
||
77 | exec("git branch -M main") |
||
78 | exec(f"git remote add origin {rep_url}") |
||
79 | exec("git push -u origin main") |
||
80 | print("Done!!") |
||
81 | print("All set up!!") |
||
82 | print(f"\n\n\n__________________________\nYou may now go to {rep_url[:-4]} and change atleast README.md and description in setup.cfg") |
||
83 | print("You may require to also change requirements.txt and install_requires,python_requires on setup.cfg if you feel so") |
||
84 | print("To upload to PyPI and reflect the new changes, run this command(pypack) once again! This time you already have a github repo.") |
||
85 | |||
161 |