| Conditions | 16 |
| Total Lines | 64 |
| Code Lines | 55 |
| 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 createmypypackage.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 |
||
| 74 | def uploadpackage(): |
||
| 75 | with tempfile.TemporaryDirectory() as tmpdirname: |
||
| 76 | os.chdir(tmpdirname) |
||
| 77 | rep_url=input("Copy-paste the link of the github repo of the project please: ") |
||
| 78 | if(not rep_url.lower().endswith(".git")): |
||
| 79 | rep_url=rep_url+".git" |
||
| 80 | exec(f"git clone -q {rep_url}") |
||
| 81 | dir_ = [i for i in os.listdir() if os.path.isdir(i)][0] |
||
| 82 | os.chdir(dir_) |
||
| 83 | exec(f"rm -rf ./dist") |
||
| 84 | |||
| 85 | print("Your package requires atleast these packages listed in requirements.txt and install_requires part of setup.cfg file.") |
||
| 86 | print("These are listed by pipreqs") |
||
| 87 | exec("pipreqs --print ./") |
||
| 88 | print("\n\nThese are the packages listed in requirements.txt : ") |
||
| 89 | exec("cat requirements.txt") |
||
| 90 | |||
| 91 | print("\n\nThese are the packages listed in install_requires part of setup.cfg file : ") |
||
| 92 | with open("setup.cfg","r") as f: |
||
| 93 | flag=False |
||
| 94 | for j in f: |
||
| 95 | if(not j[0].isspace()): |
||
| 96 | flag=False |
||
| 97 | if(flag): |
||
| 98 | print(j) |
||
| 99 | if(j.startswith("install_requires")): |
||
| 100 | flag=True |
||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | print("Abort now and update requirements.txt setup.cfg file(install_requires and python_requires) if you notice any discrepency") |
||
| 105 | if(check_("","abort","continue")): |
||
| 106 | raise NameError('Aborted as you wished!! \nMake necessary changes on the repo now.') |
||
| 107 | nft_=check_("Are you uploading this package to PyPi for the first time? Yes/No:","no","yes") |
||
| 108 | if(nft_): |
||
| 109 | with open("./setup.cfg","r") as f: |
||
| 110 | zz=f.read().split("\n") |
||
| 111 | if(zz[2].startswith("version")): |
||
| 112 | kindex=2 |
||
| 113 | else: |
||
| 114 | for jkl in range(len(zz)): |
||
| 115 | if(zz[jkl].startswith("version")): |
||
| 116 | kindex=jkl |
||
| 117 | break; |
||
| 118 | |||
| 119 | |||
| 120 | print(f"The old {zz[kindex]}") |
||
| 121 | new_version_number=input("Choose a new version number: ") |
||
| 122 | zz[kindex]="version = "+new_version_number |
||
| 123 | with open("./setup.cfg","w") as f: |
||
| 124 | f.write("\n".join(zz)) |
||
| 125 | exec("python3 -m build") |
||
| 126 | exec("git add -A") |
||
| 127 | exec("git commit -m 'First commit in the new package'") |
||
| 128 | if(nft_): |
||
| 129 | exec(f"git tag v{new_version_number}") |
||
| 130 | exec(f"git push origin v{new_version_number}") |
||
| 131 | else: |
||
| 132 | exec("git tag v0.0.1") |
||
| 133 | exec("git push origin v0.0.1") |
||
| 134 | exec("git push -u origin main") |
||
| 135 | print("Updated github repo!") |
||
| 136 | exec("twine upload dist/*") |
||
| 137 | print("Updated to PyPi!") |
||
| 138 | |||
| 148 |