Skip to content

Commit b444334

Browse files
committed
Use dictionary methods to simplify things a bit
1 parent d514f21 commit b444334

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

python/build.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@
2323
with path.open('r') as fin:
2424
package = safe_load(fin)
2525

26-
# Divide the yml files into sections based on the section tag...
27-
if 'section' not in package:
28-
package['section'] = 'miscellaneous'
29-
package['section'] = section_names[package['section'].lower()]
26+
package['section'] = section_names[package.get('section', 'miscellaneous').lower()]
3027

3128
print(f" {package['repo']} -> {package['section']}")
3229
try:
3330
package['user'], package['repo_name'] = package['repo'].split('/')
3431
except:
3532
raise Warning('Package.repo is not in correct format', package)
3633
continue
37-
package['conda_package'] = package.get('conda_package', package['repo_name'])
38-
package['pypi_name'] = package.get('pypi_name', package['repo_name'])
34+
package.setdefault('conda_package', package['repo_name'])
35+
package.setdefault('pypi_name', package['repo_name'])
3936

4037
if package.get('badges'):
4138
package['badges'] = [x.strip() for x in package['badges'].split(',')]
@@ -54,8 +51,7 @@
5451
package['badges'].remove('pypi')
5552
if package.get('conda_channel') and 'conda' not in package['badges']:
5653
package['badges'].append('conda')
57-
if 'conda_channel' not in package:
58-
package['conda_channel'] = 'conda-forge'
54+
package.setdefault('conda_channel', 'conda-forge')
5955
if 'conda' in package['badges']:
6056
needs_newline = True
6157
print(' conda: ', end='')
@@ -77,15 +73,16 @@
7773
if package.get('dormant') and 'dormant' not in package['badges']:
7874
package['badges'].append('dormant')
7975

80-
if 'rtd' in package['badges'] and 'rtd_name' not in package:
81-
package['rtd_name'] = package['repo_name']
76+
if 'rtd' in package['badges']:
77+
package.setdefault('rtd_name', package['repo_name'])
8278

8379
if 'site' in package['badges']:
8480
if 'site' not in package:
8581
package['site'] = f'https://{package["repo_name"]}.org'
8682
else:
8783
package['site'] = package['site'].rstrip('/')
8884

85+
# Divide the yml files into sections based on the section tag...
8986
config[package['section']].append(package)
9087

9188
# Turn defaultdict into plain dict.

0 commit comments

Comments
 (0)