Skip to content

Instantly share code, notes, and snippets.

@Pebaz
Created February 12, 2020 20:30
Show Gist options
  • Save Pebaz/9a01defe1775084ec7aef44dd7aa14c4 to your computer and use it in GitHub Desktop.
Save Pebaz/9a01defe1775084ec7aef44dd7aa14c4 to your computer and use it in GitHub Desktop.
Python: Know whether package is being installed via Pip or an archive is being built (sdist, bdist, bdist_wheel)
import sys
def is_pip_installing():
return '--python-tag' in sys.argv
def is_building_archive():
archive_cmds = 'sdist', 'bdist', 'bdist_wheel'
return (
not pip_installing() and
any(cmd in sys.argv for cmd in archive_cmds)
)
"""
Example Usage:
Add different keyword arguments to setup() based on command.
"""
from check_setup_method import is_pip_installing, is_building_archive
from setuptools import setup
def check():
kwarguments = {}
if is_building_archive():
"Library maintainer is building archive."
kwarguments['foo'] = 'bar'
elif is_pip_installing():
"End user is installing this library."
kwarguments['foozle'] = 'barzle'
return kwarguments
setup(
...,
**check()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment