-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
setup.py: Recommend installation command for pkgs #6575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import glob | ||
| import multiprocessing | ||
| import os | ||
| import platform | ||
| import re | ||
| import subprocess | ||
| from subprocess import check_output | ||
|
|
@@ -412,6 +413,14 @@ class CheckFailed(Exception): | |
|
|
||
| class SetupPackage(object): | ||
| optional = False | ||
| pkg_names = { | ||
| "apt-get": None, | ||
| "yum": None, | ||
| "dnf": None, | ||
| "brew": None, | ||
| "port": None, | ||
| "windows_url": None | ||
| } | ||
|
|
||
| def check(self): | ||
| """ | ||
|
|
@@ -531,6 +540,56 @@ def do_custom_build(self): | |
| """ | ||
| pass | ||
|
|
||
| def install_help_msg(self): | ||
| """ | ||
| Do not override this method ! | ||
|
|
||
| Generate the help message to show if the package is not installed. | ||
| To use this in subclasses, simply add the dictionary `pkg_names` as | ||
| a class variable: | ||
|
|
||
| pkg_names = { | ||
| "apt-get": <Name of the apt-get package>, | ||
| "yum": <Name of the yum package>, | ||
| "dnf": <Name of the dnf package>, | ||
| "brew": <Name of the brew package>, | ||
| "port": <Name of the port package>, | ||
| "windows_url": <The url which has installation instructions> | ||
| } | ||
|
|
||
| All the dictionary keys are optional. If a key is not present or has | ||
| the value `None` no message is provided for that platform. | ||
| """ | ||
| def _try_managers(*managers): | ||
| for manager in managers: | ||
| pkg_name = self.pkg_names.get(manager, None) | ||
| if pkg_name: | ||
| try: | ||
| # `shutil.which()` can be used when Python 2.7 support | ||
| # is dropped. It is available in Python 3.3+ | ||
| _ = check_output(["which", manager], | ||
| stderr=subprocess.STDOUT) | ||
| return ('Try installing {0} with `{1} install {2}`' | ||
| .format(self.name, manager, pkg_name)) | ||
| except subprocess.CalledProcessError: | ||
| pass | ||
|
|
||
| message = None | ||
| if sys.platform == "win32": | ||
| url = self.pkg_names.get("windows_url", None) | ||
| if url: | ||
| message = ('Please check {0} for instructions to install {1}' | ||
| .format(url, self.name)) | ||
| elif sys.platform == "darwin": | ||
| message = _try_managers("brew", "port") | ||
| elif sys.platform.startswith("linux"): | ||
| release = platform.linux_distribution()[0].lower() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a note I wanted to mention here. I found the package https://pypi.python.org/pypi/distro which makes a pypi package out of this, but I am not sure of a good way to install this to use it in the setup.py. Suggestions ? (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a 'fun' bug report. |
||
| if release in ('debian', 'ubuntu'): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do on Debian/Ubuntu derivatives like Linux Mint?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The supported distros in that function are: If this is run on a non-supported distro, it returns empty strings There are also some issues with Ubuntu btw ... Some Ubuntu systems are detected as "debian" - http://bugs.python.org/issue9514 |
||
| message = _try_managers('apt-get') | ||
| elif release in ('centos', 'redhat', 'fedora'): | ||
| message = _try_managers('dnf', 'yum') | ||
| return message | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need two blank lines between classes. |
||
|
|
||
| class OptionalPackage(SetupPackage): | ||
| optional = True | ||
|
|
@@ -953,6 +1012,14 @@ def add_flags(self, ext, add_sources=True): | |
|
|
||
| class FreeType(SetupPackage): | ||
| name = "freetype" | ||
| pkg_names = { | ||
| "apt-get": "libfreetype6-dev", | ||
| "yum": "freetype-devel", | ||
| "dnf": "freetype-devel", | ||
| "brew": "freetype", | ||
| "port": "freetype", | ||
| "windows_url": "http://gnuwin32.sourceforge.net/packages/freetype.htm" | ||
| } | ||
|
|
||
| def check(self): | ||
| if options.get('local_freetype'): | ||
|
|
@@ -1167,6 +1234,14 @@ def get_extension(self): | |
|
|
||
| class Png(SetupPackage): | ||
| name = "png" | ||
| pkg_names = { | ||
| "apt-get": "libpng12-dev", | ||
| "yum": "libpng-devel", | ||
| "dnf": "libpng-devel", | ||
| "brew": "libpng", | ||
| "port": "libpng", | ||
| "windows_url": "http://gnuwin32.sourceforge.net/packages/libpng.htm" | ||
| } | ||
|
|
||
| def check(self): | ||
| if sys.platform == 'win32': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a
shutil.which, but unfortunately, it's 3.3+. It's probably not worth it to conditionally call it, but can you add a comment about switching to it when we drop 2.7?