Skip to content

Instantly share code, notes, and snippets.

@di
Created July 15, 2020 20:59
Show Gist options
  • Save di/1db107493a2ca0d2886d821faa171e03 to your computer and use it in GitHub Desktop.
Save di/1db107493a2ca0d2886d821faa171e03 to your computer and use it in GitHub Desktop.
Specifier vs LegacySpecifier analysis
import csv
from collections import defaultdict
import packaging.requirements
totals = defaultdict(int)
with open('specifiers.csv') as f:
reader = csv.reader(f)
with open('out.csv', 'w') as o:
writer = csv.writer(o)
for row in reader:
req, count = row
try:
rrr = packaging.requirements.Requirement(req)
specs = rrr.specifier._specs
if 'LegacySpecifier' in [type(x).__name__ for x in specs]:
totals['LegacySpecifier'] += int(count)
else:
totals['Specifier'] += int(count)
except packaging.requirements.InvalidRequirement:
totals['invalid'] += int(count)
print(totals)
copy (
select
specifier,
count(specifier)
from
release_dependencies
group by
specifier
) to STDOUT CSV;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment