Conditions | 16 |
Total Lines | 64 |
Code Lines | 57 |
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:
Complex classes like pypacklib.uploadpackage() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import os |
||
87 | def uploadpackage(): |
||
88 | with tempfile.TemporaryDirectory() as tmpdirname: |
||
89 | os.chdir(tmpdirname) |
||
90 | rep_url=input("Copy-paste the link of the github repo of the project please: ") |
||
91 | if(not rep_url.lower().endswith(".git")): |
||
92 | rep_url=rep_url+".git" |
||
93 | exec(f"git clone -q {rep_url}") |
||
94 | dir_ = [i for i in os.listdir() if os.path.isdir(i)][0] |
||
95 | os.chdir(dir_) |
||
96 | exec(f"rm -rf ./dist") |
||
97 | |||
98 | print("\n\n\n_____________________________IMPORTANT________________________________\n\nYour package requires atleast these packages listed in requirements.txt and install_requires part of setup.cfg file.") |
||
99 | print("These are listed by pipreqs") |
||
100 | exec("pipreqs --print ./") |
||
101 | print("\n\nThese are the packages listed in requirements.txt : ") |
||
102 | exec("cat requirements.txt") |
||
103 | tempprint="" |
||
104 | print("\n\nThese are the packages listed in install_requires part of setup.cfg file : ") |
||
105 | with open("setup.cfg","r") as f: |
||
106 | flag=False |
||
107 | for j in f: |
||
108 | if(not j[0].isspace()): |
||
109 | flag=False |
||
110 | if(flag): |
||
111 | tempprint+=j.strip()+"\n" |
||
112 | if(j.startswith("install_requires")): |
||
113 | flag=True |
||
114 | |||
115 | |||
116 | print(tempprint) |
||
117 | print("If you notice any discrepency, abort now and update requirements.txt setup.cfg file(install_requires and python_requires).\n") |
||
118 | if(check_("Abort/continue? (see above why..) Write 'abort' to stop exeution or 'continue' to go ahead uploading with current settings : ","abort","continue")): |
||
119 | raise NameError('Aborted as you wished!! \nMake necessary changes on the repo now.') |
||
120 | nft_=check_("Are you uploading this package to PyPi for the first time? yes/no: ","no","yes") |
||
121 | if(nft_): |
||
122 | with open("./setup.cfg","r") as f: |
||
123 | zz=f.read().split("\n") |
||
124 | if(zz[2].startswith("version")): |
||
125 | kindex=2 |
||
126 | else: |
||
127 | for jkl in range(len(zz)): |
||
128 | if(zz[jkl].startswith("version")): |
||
129 | kindex=jkl |
||
130 | break; |
||
131 | |||
132 | |||
133 | print(f"The old {zz[kindex]}") |
||
134 | new_version_number=input("Choose a new version number: ") |
||
135 | zz[kindex]="version = "+new_version_number |
||
136 | with open("./setup.cfg","w") as f: |
||
137 | f.write("\n".join(zz)) |
||
138 | exec("python3 -m build") |
||
139 | exec("git add -A") |
||
140 | exec("git commit -m 'New version is released now'") |
||
141 | if(nft_): |
||
142 | exec(f"git tag v{new_version_number}") |
||
143 | exec(f"git push origin v{new_version_number}") |
||
144 | else: |
||
145 | exec("git tag v0.0.1") |
||
146 | exec("git push origin v0.0.1") |
||
147 | exec("git push -u origin main") |
||
148 | print("Updated github repo!") |
||
149 | exec("twine upload dist/*") |
||
150 | print("Updated to PyPi! New version has been released!") |
||
151 | |||
161 |