Skip to content

Instantly share code, notes, and snippets.

@cdeil
Last active January 9, 2017 20:47
Show Gist options
  • Save cdeil/78fe6edc9bd540445a2ebfcd370d0d2f to your computer and use it in GitHub Desktop.
Save cdeil/78fe6edc9bd540445a2ebfcd370d0d2f to your computer and use it in GitHub Desktop.
"""
Check Python version status in Macports.
"""
from pathlib import Path
from astropy.table import Table
def has_version(version, text):
lines = text.split('\n')
for line in lines:
if 'python.versions' in line:
tokens = line.split()
if version in tokens:
return True
return False
def compute_status():
paths = Path('python').glob('*/Portfile')
# print(list(filenames))
table = []
for path in paths:
# print('Processing {}'.format(str(path)))
text = path.read_text()
row = dict()
row['port'] = str(path).split('/')[1]
row['py35'] = has_version('35', text)
row['py36'] = has_version('36', text)
table.append(row)
# import IPython; IPython.embed(); 1/0
return Table(table)
def report_status(table):
table['port'].format = '<'
# table.pprint(max_lines=-1)
print('Number of Python ports: {}'.format(len(table)))
# table2 = table[table['py35']]
print('Number of Python ports supporting version 3.5: {}'.format(sum(table['py35'])))
print('Number of Python ports supporting version 3.6: {}'.format(sum(table['py36'])))
needs_36 = table['py35'] & (~table['py36'])
print('Number of Python ports that need 3.6 added: {}'.format(sum(needs_36)))
print('List of ports where 3.6 should be added:\n')
table[needs_36]['port'].pprint(max_lines=-1)
# import IPython; IPython.embed(); 1/0
if __name__ == '__main__':
table = compute_status()
report_status(table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment