Skip to content

Docs for fomin.py

Docs for fomin.py #41

Workflow file for this run

name: Update requirements.txt
on:
push:
branches:
- main
jobs:
update-reqs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Backup current requirements
run: |
if [ -f requirements.txt ]; then
mv requirements.txt requirements.old
else
touch requirements.old
fi
- name: Install pipreqs
run: pip install pipreqs
- name: Generate new requirements
run: pipreqs . --force --ignore .venv --mode gt
- name: Restore old versions if they exist
shell: python
run: |
import os
def parse_reqs(filename):
data = {}
if not os.path.exists(filename):
return data
with open(filename, 'r') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'): continue
parts = line.split('>=') if '>=' in line else line.split('==')
if len(parts) > 1:
data[parts[0].lower()] = line
return data
old_versions = parse_reqs('requirements.old')
new_lines = []
if os.path.exists('requirements.txt'):
with open('requirements.txt', 'r') as f:
for line in f:
line = line.strip()
if not line: continue
pkg_name = line.split('>=')[0].split('==')[0].strip().lower()
if pkg_name in old_versions:
new_lines.append(old_versions[pkg_name])
else:
new_lines.append(line)
with open('requirements.txt', 'w') as f:
f.write('\n'.join(new_lines) + '\n')
if os.path.exists('requirements.old'):
os.remove('requirements.old')
- name: Commit and push if changed
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add requirements.txt
if git diff --cached --quiet; then
echo "No changes in requirements.txt"
else
git commit -m "Updated requirements.txt"
git push
fi