samba
5/5/2017 - 7:29 PM

Python requirements based on Operating System

Python requirements based on Operating System

#!/usr/bin/env python
# Generates a list of requirements files suitable to this operating system.
# USAGE:
#   pip install -r $(DEVEL=0 python requirements.py)
# 
# Ensure that you have suitable files in path "./requirements/"
# See attached example for Makefile usage.


import sys
import os

LINUX = 'requirements/linux.txt'
MACOS = 'requirements/mac.txt'
DEV_MISC = 'requirements/dev.txt'

CONTEXT = {
    (LINUX): ('linux',),
    (MACOS): ('darwin',)
}

CURRENT_PLATFORM = str(sys.platform).lower()

for filename, parts in CONTEXT.iteritems():
    matches = [1 for p in parts if p in CURRENT_PLATFORM]
    if sum(matches) == len(parts):
        print filename

# also the general development...

if int(os.environ.get('DEVEL', '0')):
    print DEV_MISC
# Example dynamic selection of Python requirements files

dependencies:  $(shell python requirements.py)
	for req in $^; do \
		pip install --upgrade -r $$req ; \
	done
	

test: dependencies
	echo run your tests.