Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d514f21

Browse files
committed
Dedent package processing
We only need to be in the context manager for the file reading.
1 parent 76d1f31 commit d514f21

1 file changed

Lines changed: 61 additions & 63 deletions

File tree

python/build.py

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,70 +23,68 @@
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()]
30-
31-
print(f" {package['repo']} -> {package['section']}")
32-
try:
33-
package['user'], package['repo_name'] = package['repo'].split('/')
34-
except:
35-
raise Warning('Package.repo is not in correct format', package)
36-
continue
37-
package['conda_package'] = package.get('conda_package', package['repo_name'])
38-
package['pypi_name'] = package.get('pypi_name', package['repo_name'])
39-
40-
if package.get('badges'):
41-
package['badges'] = [x.strip() for x in package['badges'].split(',')]
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()]
30+
31+
print(f" {package['repo']} -> {package['section']}")
32+
try:
33+
package['user'], package['repo_name'] = package['repo'].split('/')
34+
except:
35+
raise Warning('Package.repo is not in correct format', package)
36+
continue
37+
package['conda_package'] = package.get('conda_package', package['repo_name'])
38+
package['pypi_name'] = package.get('pypi_name', package['repo_name'])
39+
40+
if package.get('badges'):
41+
package['badges'] = [x.strip() for x in package['badges'].split(',')]
42+
else:
43+
package['badges'] = ['pypi', 'conda']
44+
45+
needs_newline = False
46+
if 'pypi' in package['badges']:
47+
needs_newline = True
48+
print(' pypi: ', end='', flush=True)
49+
response = requests.get(f"https://pypi.org/pypi/{package['pypi_name']}/json/")
50+
if response.status_code == 200:
51+
print('found')
4252
else:
43-
package['badges'] = ['pypi', 'conda']
44-
45-
needs_newline = False
46-
if 'pypi' in package['badges']:
47-
needs_newline = True
48-
print(' pypi: ', end='', flush=True)
49-
response = requests.get(
50-
f"https://pypi.org/pypi/{package['pypi_name']}/json/")
51-
if response.status_code == 200:
52-
print('found')
53-
else:
54-
print('not found')
55-
package['badges'].remove('pypi')
56-
if package.get('conda_channel') and 'conda' not in package['badges']:
57-
package['badges'].append('conda')
58-
if 'conda_channel' not in package:
59-
package['conda_channel'] = 'conda-forge'
60-
if 'conda' in package['badges']:
61-
needs_newline = True
62-
print(' conda: ', end='')
63-
response = requests.get(
64-
f"https://anaconda.org/{package['conda_channel']}/{package['conda_package']}/",
65-
allow_redirects=False)
66-
if response.status_code == 200:
67-
print('found', end='')
68-
else:
69-
print('not found', end='')
70-
package['badges'].remove('conda')
71-
if needs_newline:
72-
print()
73-
74-
if package.get('sponsors') and 'sponsor' not in package['badges']:
75-
package['badges'].append('sponsor')
76-
if package.get('site') and 'site' not in package['badges'] and 'rtd' not in package['badges']:
77-
package['badges'].append('site')
78-
if package.get('dormant') and 'dormant' not in package['badges']:
79-
package['badges'].append('dormant')
80-
81-
82-
if 'rtd' in package['badges'] and 'rtd_name' not in package:
83-
package['rtd_name'] = package['repo_name']
84-
85-
if 'site' in package['badges']:
86-
if 'site' not in package:
87-
package['site'] = f'https://{package["repo_name"]}.org'
88-
else:
89-
package['site'] = package['site'].rstrip('/')
53+
print('not found')
54+
package['badges'].remove('pypi')
55+
if package.get('conda_channel') and 'conda' not in package['badges']:
56+
package['badges'].append('conda')
57+
if 'conda_channel' not in package:
58+
package['conda_channel'] = 'conda-forge'
59+
if 'conda' in package['badges']:
60+
needs_newline = True
61+
print(' conda: ', end='')
62+
response = requests.get(
63+
f"https://anaconda.org/{package['conda_channel']}/{package['conda_package']}/",
64+
allow_redirects=False)
65+
if response.status_code == 200:
66+
print('found', end='')
67+
else:
68+
print('not found', end='')
69+
package['badges'].remove('conda')
70+
if needs_newline:
71+
print()
72+
73+
if package.get('sponsors') and 'sponsor' not in package['badges']:
74+
package['badges'].append('sponsor')
75+
if package.get('site') and 'site' not in package['badges'] and 'rtd' not in package['badges']:
76+
package['badges'].append('site')
77+
if package.get('dormant') and 'dormant' not in package['badges']:
78+
package['badges'].append('dormant')
79+
80+
if 'rtd' in package['badges'] and 'rtd_name' not in package:
81+
package['rtd_name'] = package['repo_name']
82+
83+
if 'site' in package['badges']:
84+
if 'site' not in package:
85+
package['site'] = f'https://{package["repo_name"]}.org'
86+
else:
87+
package['site'] = package['site'].rstrip('/')
9088

9189
config[package['section']].append(package)
9290

0 commit comments

Comments
 (0)