From 685da415fe4a40c7765fc1ead4bc88e12108cb3c Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Sun, 10 Jul 2016 17:48:56 -0300 Subject: [PATCH] Cria script para atualizar *requirements.txt --- scripts/atualizar_requirements.py | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 scripts/atualizar_requirements.py diff --git a/scripts/atualizar_requirements.py b/scripts/atualizar_requirements.py new file mode 100755 index 000000000..5b8e22d22 --- /dev/null +++ b/scripts/atualizar_requirements.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +# Este script altera os arquivos requirements/*requirements.txt +# atualizando as versões fixadas neles para coincidirem com as do venv. +# +# Rode esse script após atualizar as dependências do venv usando, p. ex.: +# pip-review +# +# Após usá-lo confira sempre o resultado com `git diff` e teste as mudanças + +import glob +import re +import subprocess + +freeze_output = subprocess.Popen( + 'pip freeze', shell=True, + stdout=subprocess.PIPE).stdout.read().decode('ascii') +freeze = freeze_output.strip().split('\n') +freeze = {name.lower(): version + for name, version in [re.split('==+', s) for s in freeze]} +req_files = glob.glob('requirements/*requirements.txt') +requirements = [(f, open(f).read().strip().split('\n')) + for f in req_files] + + +def novas_linhas(linhas): + for linha in linhas: + split = re.split('==', linha) + if len(split) == 1: + yield split[0] + else: + nome, versao = split + nome = nome.lower() + yield '%s==%s' % (nome, freeze[nome]) + +for arq, linhas in requirements: + with open(arq, 'w') as f: + f.writelines(l + '\n' for l in novas_linhas(linhas))