-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_package_info.py
94 lines (77 loc) · 2.55 KB
/
delete_package_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
This script deletes the package folders of Build and Dist made when creating the package.
It also deletes the .egg-info folder created when installing the package.
This script is useful when you want to delete the package folders to avoid confusion when creating a new package.
Also because, twine will not allow you to upload a package with the same version number and when there's more
than one package folder it will try to upload all of them.
This script is also useful when you want to delete the documentation files generated by Sphinx.
"""
import os
import shutil
def delete_folder(folder_name: str) -> None:
"""
Deletes the folder with the given name.
Parameters
----------
folder_name : str
Name of the folder to be deleted.
Returns
-------
None
"""
#Get current working directory
cwd = os.getcwd()
#Join the current working directory with the folder name
folder = os.path.join(cwd, folder_name)
if os.path.exists(folder):
shutil.rmtree(folder)
print(f"Deleted {folder_name}")
else:
print(f"{folder_name} does not exist")
def delete_package_info() -> None:
"""
Deletes the package folders of Build and Dist and the .egg-info folder.
Returns
-------
None
"""
delete_folder("build")
delete_folder("dist")
delete_folder("melanoma_segmentation.egg-info")
def delete_rst_files() -> None:
"""
Deletes the .rst files in the source folder.
Returns
-------
None
"""
#Get current working directory
cwd = os.getcwd()
#Join the current working directory with the source folder
source_folder = os.path.join(cwd, "docs", "source")
#Get all the files in the source folder
files = os.listdir(source_folder)
#Iterate over the files
for file in files:
#Check if the file is a .rst file and is not index.rst
if file.endswith(".rst") and file != "index.rst":
#Join the source folder with the file
file_path = os.path.join(source_folder, file)
#Delete the file
os.remove(file_path)
print(f"Deleted {file}")
def delete_documentation_files() -> None:
"""
Deletes the documentation files generated by Sphinx.
This is a two step process:
1. Delete the folder build in the docs folder
2. Delete inside source folder the files: .rst, except index.rst
Returns
-------
None
"""
delete_folder("docs/build")
delete_rst_files()
if __name__ == "__main__":
#delete_package_info()
delete_documentation_files()