Created
February 12, 2020 20:30
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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