-
Notifications
You must be signed in to change notification settings - Fork 99
/
generate_list.py
193 lines (168 loc) · 8.59 KB
/
generate_list.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import json
from datetime import datetime, timedelta
def format_date(date_str):
try:
date_obj = datetime.fromisoformat(date_str.replace("Z", "+00:00"))
return date_obj.strftime("%y-%m-%d")
except ValueError:
return "no date"
def is_date_old(date_str):
try:
date_obj = datetime.fromisoformat(date_str.replace("Z", "+00:00"))
return datetime.now() - date_obj > timedelta(days=365)
except ValueError:
return False
def is_date_recent(date_str):
try:
date_obj = datetime.fromisoformat(date_str.replace("Z", "+00:00"))
return datetime.now() - date_obj <= timedelta(days=365)
except ValueError:
return False
def generate_list():
with open("list.json", "r") as file:
data = json.load(file)
with open("README.md", "w") as file:
file.write("# Open Source Python Packages in Hydrology\n")
file.write(
"My attempt to list interesting open source python projects that can be used in the field of Hydrology. In a 2024 update, I automated various tasks to maintain the quality of this list, and added more information about the packages that can serve as quality indicators. The description now lists when the last update on Pypi/Conda was, to highlight whether a package is probably active (🟢) or inactive (🔴). Also information about the FAIR repository, description paper, and Continuous Integration testing (CI) is included. All this in the hope that more and more packages develop according to common research software developement best practices. Suggestions as issues or pull requests are welcome! \n\n"
)
file.write("Raoul A. Collenteur, Eawag.\n\n")
categories = {}
legacy_packages = []
for package_name, package in data.items():
if package.get("legacy", False):
legacy_packages.append((package_name, package))
continue
category = package["category"]
if category not in categories:
categories[category] = []
categories[category].append((package_name, package))
# Write the menu with links to categories
file.write("## Categories\n")
for category in sorted(categories.keys()):
file.write(f"- [{category}](#{category.lower().replace(' ', '-')})\n")
if legacy_packages:
file.write("- [Legacy Packages](#legacy-packages)\n")
file.write("\n")
for category, packages in categories.items():
packages.sort(
key=lambda x: x[0].lower()
) # Sort packages alphabetically by name
file.write(f"## {category}\n")
file.write(
"| Name | Description | PyPI Conda | Docs | CI | Paper |\n"
)
file.write(
"| ---- | ------------------------------------------ | ---------- | ---- | -- | ----- |\n"
)
for package_name, package in packages:
description = package["description"]
url = package["url"]
pypi_url = package.get("pypi", "")
conda_url = package.get("conda", "")
docs_url = package.get("docs", "")
ci_status = package.get("CI", 0)
version = package.get("version", "")
last_update = package.get("last_update", "")
if version or last_update:
if last_update:
formatted_date = format_date(last_update)
if is_date_old(last_update):
formatted_date = f"🔴 {formatted_date}"
elif is_date_recent(last_update):
formatted_date = f"🟢 {formatted_date}"
else:
formatted_date = "🔴 No date"
description += (
f" (Version: {version}, Last Update: {formatted_date})"
)
pypi_logo = (
f"[![PyPI](https://img.shields.io/badge/-3776AB?logo=python&logoColor=white)]({pypi_url})"
if pypi_url
else ""
)
conda_logo = (
f"[![Conda](https://img.shields.io/badge/-44A833?logo=anaconda&logoColor=white)]({conda_url})"
if conda_url
else ""
)
docs_logo = (
f"[![Docs](https://img.shields.io/badge/-217346?logo=readthedocs&logoColor=white)]({docs_url})"
if docs_url
else ""
)
ci_logo = "🟢" if ci_status else ""
doi_paper_logo = (
f"[![DOI](https://img.shields.io/badge/DOI-10.1000/xyz123-blue)]({package.get('doi_paper', '')})"
if package.get("doi_paper", "")
else ""
)
file.write(
f"| [{package_name}]({url}) | {description} | {pypi_logo} {conda_logo} | {docs_logo} | {ci_logo} | {doi_paper_logo} |\n"
)
if legacy_packages:
legacy_packages.sort(
key=lambda x: x[0].lower()
) # Sort legacy packages alphabetically by name
file.write("\n## Legacy Packages\n")
file.write(
"These packages are not maintained anymore, or might not meet a minimum set of requirements, but might still be useful for some users.\n"
)
file.write(
"| Name | Description | PyPI Conda | Docs | CI | Paper |\n"
)
file.write(
"| ---- | ------------------------------------------ | ---------- | ---- | -- | ----- |\n"
)
for package_name, package in legacy_packages:
description = package["description"]
url = package["url"]
pypi_url = package.get("pypi", "")
conda_url = package.get("conda", "")
docs_url = package.get("docs", "")
ci_status = package.get("CI", 0)
version = package.get("version", "")
last_update = package.get("last_update", "")
if version or last_update:
if last_update:
formatted_date = format_date(last_update)
if is_date_old(last_update):
formatted_date = f"🔴 {formatted_date}"
elif is_date_recent(last_update):
formatted_date = f"🟢 {formatted_date}"
else:
formatted_date = "🔴 No date"
description += (
f" (Version: {version}, Last Update: {formatted_date})"
)
pypi_logo = (
f"[![PyPI](https://img.shields.io/badge/-3776AB?logo=python&logoColor=white)]({pypi_url})"
if pypi_url
else ""
)
conda_logo = (
f"[![Conda](https://img.shields.io/badge/-44A833?logo=anaconda&logoColor=white)]({conda_url})"
if conda_url
else ""
)
docs_logo = (
f"[![Docs](https://img.shields.io/badge/-217346?logo=readthedocs&logoColor=white)]({docs_url})"
if docs_url
else ""
)
ci_logo = "🟢" if ci_status else ""
doi_paper_logo = (
f"[![DOI](https://img.shields.io/badge/DOI-10.1000/xyz123-blue)]({package.get('doi_paper', '')})"
if package.get("doi_paper", "")
else ""
)
file.write(
f"| [{package_name}]({url}) | {description} | {pypi_logo} {conda_logo} | {docs_logo} | {ci_logo} | {doi_paper_logo} |\n"
)
file.write("\n# Background Info\n")
file.write(
'UPDATE: The Pypa package authority has now added ["Hydrology" as a classifier](https://github.com/pypa/warehouse/issues/5728) so we can start [collecting python packages](https://pypi.org/search/?q=&o=&c=Topic+%3A%3A+Scientific%2FEngineering+%3A%3A+Hydrology) used by the hydrological community! If you are maintaining a python package, please add `Topic :: Scientific/Engineering :: Hydrology` to your setup.py so people can find your package.\n\n'
)
file.write("\n")
if __name__ == "__main__":
generate_list()