Skip to content

Instantly share code, notes, and snippets.

@samba
Last active May 5, 2017 23:18
Show Gist options
  • Save samba/d143dfd3478dc8cf3ab70e2dc0235300 to your computer and use it in GitHub Desktop.
Save samba/d143dfd3478dc8cf3ab70e2dc0235300 to your computer and use it in GitHub Desktop.
Python requirements based on Operating System
# 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.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment