Skip to content

Commit

Permalink
Merge branch 'feature/v0.3.14' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Oct 19, 2019
2 parents efa7963 + 7f951ee commit a625637
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ API Reference
~~~~~~~~~~~~~

The main technical reference for **Colour** and its API is the
`Colour Manual <https://colour.readthedocs.io/en/latest/manual.html>`__
`Colour Manual <https://colour.readthedocs.io/en/latest/manual.html>`__.

Jupyter Notebooks
~~~~~~~~~~~~~~~~~
Expand Down
14 changes: 7 additions & 7 deletions colour/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
tsplit, row_as_diagonal, dot_vector, dot_matrix, orient,
centroid, linear_conversion, lerp, fill_nan, ndarray_write)
from .metrics import metric_mse, metric_psnr
from .verbose import (ColourWarning, ColourUsageWarning, ColourRuntimeWarning,
message_box, show_warning, warning, runtime_warning,
usage_warning, filter_warnings, suppress_warnings,
numpy_print_options, ANCILLARY_COLOUR_SCIENCE_PACKAGES,
ANCILLARY_RUNTIME_PACKAGES,
ANCILLARY_DEVELOPMENT_PACKAGES, describe_environment)
from .verbose import (
ColourWarning, ColourUsageWarning, ColourRuntimeWarning, message_box,
show_warning, warning, runtime_warning, usage_warning, filter_warnings,
suppress_warnings, numpy_print_options, ANCILLARY_COLOUR_SCIENCE_PACKAGES,
ANCILLARY_RUNTIME_PACKAGES, ANCILLARY_DEVELOPMENT_PACKAGES,
ANCILLARY_EXTRAS_PACKAGES, describe_environment)

__all__ = ['Lookup', 'Structure', 'CaseInsensitiveMapping']
__all__ += [
Expand Down Expand Up @@ -53,5 +53,5 @@
'usage_warning', 'filter_warnings', 'suppress_warnings',
'numpy_print_options', 'ANCILLARY_COLOUR_SCIENCE_PACKAGES',
'ANCILLARY_RUNTIME_PACKAGES', 'ANCILLARY_DEVELOPMENT_PACKAGES',
'describe_environment'
'ANCILLARY_EXTRAS_PACKAGES', 'describe_environment'
]
8 changes: 8 additions & 0 deletions colour/utilities/tests/test_verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def test_describe_environment(self):
sorted(environment.keys()),
['Development', 'Interpreter', 'Runtime', 'colour-science.org'])

environment = describe_environment(
development_packages=True, extras_packages=True)
self.assertListEqual(
sorted(environment.keys()), [
'Development', 'Extras', 'Interpreter', 'Runtime',
'colour-science.org'
])


if __name__ == '__main__':
unittest.main()
168 changes: 110 additions & 58 deletions colour/utilities/verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'usage_warning', 'filter_warnings', 'suppress_warnings',
'numpy_print_options', 'ANCILLARY_COLOUR_SCIENCE_PACKAGES',
'ANCILLARY_RUNTIME_PACKAGES', 'ANCILLARY_DEVELOPMENT_PACKAGES',
'describe_environment'
'ANCILLARY_EXTRAS_PACKAGES', 'describe_environment'
]


Expand Down Expand Up @@ -447,9 +447,17 @@ def numpy_print_options(*args, **kwargs):
ANCILLARY_DEVELOPMENT_PACKAGES : OrderedDict
"""

ANCILLARY_EXTRAS_PACKAGES = OrderedDict()
"""
Ancillary extras packages to describe.
ANCILLARY_EXTRAS_PACKAGES : OrderedDict
"""


def describe_environment(runtime_packages=True,
development_packages=False,
extras_packages=False,
print_environment=True,
**kwargs):
"""
Expand All @@ -462,6 +470,8 @@ def describe_environment(runtime_packages=True,
Whether to return the runtime packages versions.
development_packages : bool, optional
Whether to return the development packages versions.
extras_packages : bool, optional
Whether to return the extras packages versions.
print_environment : bool, optional
Whether to print the environment.
Expand All @@ -488,56 +498,66 @@ def describe_environment(runtime_packages=True,
===========================================================================
* *
* Interpreter : *
* python : 2.7.14 | packaged by conda-forge | (default, Dec 25 *
* 2017, 01:18:54) *
* [GCC 4.2.1 Compatible Apple LLVM 6.1.0 *
* (clang-602.0.53)] *
* python : 3.7.4 (default, Sep 7 2019, 18:27:02) *
* [Clang 10.0.1 (clang-1001.0.46.4)] *
* *
* colour-science.org : *
* colour : v0.3.11-323-g380c1838 *
* colour : v0.3.13-293-gecf1dc8a *
* *
* Runtime : *
* numpy : 1.14.3 *
* scipy : 1.0.0 *
* pandas : 0.22.0 *
* matplotlib : 2.2.2 *
* notebook : 5.4.0 *
* ipywidgets : 7.2.1 *
* imageio : 2.6.1 *
* numpy : 1.17.2 *
* scipy : 1.3.1 *
* six : 1.12.0 *
* pandas : 0.24.2 *
* matplotlib : 3.0.3 *
* networkx : 2.3 *
* pygraphviz : 1.5 *
* *
===========================================================================
>>> environment = describe_environment(True, True, width=75)
>>> environment = describe_environment(True, True, True, width=75)
... # doctest: +SKIP
===========================================================================
* *
* Interpreter : *
* python : 2.7.14 | packaged by conda-forge | (default, Dec 25 *
* 2017, 01:18:54) *
* [GCC 4.2.1 Compatible Apple LLVM 6.1.0 *
* (clang-602.0.53)] *
* python : 3.7.4 (default, Sep 7 2019, 18:27:02) *
* [Clang 10.0.1 (clang-1001.0.46.4)] *
* *
* colour-science.org : *
* colour : v0.3.11-323-g380c1838 *
* colour : v0.3.13-293-gecf1dc8a *
* *
* Runtime : *
* numpy : 1.14.3 *
* scipy : 1.0.0 *
* pandas : 0.22.0 *
* matplotlib : 2.2.2 *
* notebook : 5.4.0 *
* ipywidgets : 7.2.1 *
* imageio : 2.6.1 *
* numpy : 1.17.2 *
* scipy : 1.3.1 *
* six : 1.12.0 *
* pandas : 0.24.2 *
* matplotlib : 3.0.3 *
* networkx : 2.3 *
* pygraphviz : 1.5 *
* *
* Development : *
* coverage : 4.5.1 *
* flake8 : 3.5.0 *
* invoke : 0.22.1 *
* mock : 2.0.0 *
* biblib-simple : 0.1.1 *
* coverage : 4.5.4 *
* coveralls : 1.8.2 *
* flake8 : 3.7.8 *
* invoke : 1.3.0 *
* jupyter : 1.0.0 *
* mock : 3.0.5 *
* nose : 1.3.7 *
* restructuredtext_lint : 1.1.3 *
* six : 1.11.0 *
* sphinx : 1.7.5 *
* sphinx_rtd_theme : 0.2.4 *
* twine : 1.10.0 *
* yapf : 0.20.2 *
* pre-commit : 1.18.3 *
* pytest : 5.2.1 *
* restructuredtext-lint : 1.3.0 *
* sphinx : 2.2.0 *
* sphinx_rtd_theme : 0.4.3 *
* sphinxcontrib-bibtex : 1.0.0 *
* toml : 0.10.0 *
* twine : 1.15.0 *
* yapf : 0.23.0 *
* *
* Extras : *
* ipywidgets : 7.5.1 *
* notebook : 6.0.1 *
* *
===========================================================================
"""
Expand All @@ -550,6 +570,9 @@ def describe_environment(runtime_packages=True,

import colour

# TODO: Implement support for "pyproject.toml" file whenever "TOML" is
# supported in the standard library.

# NOTE: A few clauses are not reached and a few packages are not available
# during continuous integration and are thus ignored for coverage.
try: # pragma: no cover
Expand All @@ -565,8 +588,10 @@ def describe_environment(runtime_packages=True,
environment['colour-science.org'].update(ANCILLARY_COLOUR_SCIENCE_PACKAGES)

if runtime_packages:
for package in ('numpy', 'scipy', 'pandas', 'matplotlib', 'notebook',
'ipywidgets'):
for package in [
'imageio', 'numpy', 'scipy', 'six', 'pandas', 'matplotlib',
'networkx', 'pygraphviz'
]:
try:
namespace = __import__(package)
environment['Runtime'][package] = namespace.__version__
Expand All @@ -582,39 +607,66 @@ def describe_environment(runtime_packages=True,

environment['Runtime'].update(ANCILLARY_RUNTIME_PACKAGES)

def _get_package_version(package, mapping):
"""
Returns given package version.
"""

namespace = __import__(package)

if package in mapping:
import pkg_resources

distributions = [
distribution for distribution in pkg_resources.working_set
]

for distribution in distributions:
if distribution.project_name == mapping[package]:
return distribution.version

return namespace.__version__

if development_packages:
for package in ('coverage', 'flake8', 'invoke', 'mock', 'nose',
'restructuredtext_lint', 'six', 'sphinx',
'sphinxcontrib.bibtex', 'sphinx_rtd_theme', 'twine',
'yapf'):
mapping = {
'biblib.bib': 'biblib-simple',
'pre_commit': 'pre-commit',
'restructuredtext_lint': 'restructuredtext-lint',
'sphinxcontrib.bibtex': 'sphinxcontrib-bibtex'
}
for package in [
'biblib.bib', 'coverage', 'coveralls', 'flake8', 'invoke',
'jupyter', 'mock', 'nose', 'pre_commit', 'pytest',
'restructuredtext_lint', 'sphinx', 'sphinx_rtd_theme',
'sphinxcontrib.bibtex', 'toml', 'twine', 'yapf'
]:
try:
namespace = __import__(package)
if package == 'restructuredtext_lint': # pragma: no cover
with open(
os.path.join(
os.path.dirname(namespace.__file__),
'VERSION'), 'r') as version_file:
version = version_file.read().strip()
elif package == 'sphinxcontrib.bibtex': # pragma: no cover
import pip

for distribution in pip.get_installed_distributions():
if distribution.name == package:
version = distribution.version
break
else:
version = namespace.__version__
version = _get_package_version(package, mapping)
package = mapping.get(package, package)

environment['Development'][package] = version
except (AttributeError, ImportError):
except Exception:
continue

environment['Development'].update(ANCILLARY_DEVELOPMENT_PACKAGES)

if extras_packages:
mapping = {}
for package in ['ipywidgets', 'notebook']:
try:
version = _get_package_version(package, mapping)
package = mapping.get(package, package)

environment['Extras'][package] = version
except Exception:
continue

environment['Extras'].update(ANCILLARY_EXTRAS_PACKAGES)

if print_environment:
message = str()
for category in ('Interpreter', 'colour-science.org', 'Runtime',
'Development'):
'Development', 'Extras'):
elements = environment.get(category)
if not elements:
continue
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ API Reference
~~~~~~~~~~~~~

The main technical reference for **Colour** and its API is the
`Colour Manual <https://colour.readthedocs.io/en/latest/manual.html>`__
`Colour Manual <https://colour.readthedocs.io/en/latest/manual.html>`__.

.. toctree::
:maxdepth: 4
Expand Down

0 comments on commit a625637

Please sign in to comment.