-
Notifications
You must be signed in to change notification settings - Fork 268
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
Improve info tool dependencies option #2303
Open
HealthyPear
wants to merge
11
commits into
cta-observatory:main
Choose a base branch
from
HealthyPear:improve_info_tool_dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
11fd153
Fallback to metadata.version before giving up
HealthyPear e539eb0
Read dependencies from setup.cfg, filter versions
HealthyPear a1adba0
Add pytest-console-scripts test dependency
HealthyPear c2cdb69
Test info tool properly
HealthyPear e9fc7a7
Remove old test for info tool
HealthyPear 7400781
Add news fragment for PR 2303
HealthyPear d53b9e3
Run isort on ctapipe/tools/info.py
HealthyPear ec02215
Merge branch 'main' into improve_info_tool_dependencies
HealthyPear f2e4c43
Fix isort complain in ctapipe/tools/info.py
HealthyPear 5c76087
Use importlib.metadata and print all extras
HealthyPear 1f34483
Merge branch 'main' into improve_info_tool_dependencies
HealthyPear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
""" print information about ctapipe and its command-line tools. """ | ||
import logging | ||
import os | ||
import re | ||
import sys | ||
from importlib.metadata import metadata, requires | ||
from importlib.resources import files | ||
|
||
from ..core import Provenance, get_module_version | ||
|
@@ -12,27 +14,6 @@ | |
|
||
__all__ = ["info"] | ||
|
||
# TODO: this list should be global (or generated at install time) | ||
_dependencies = sorted( | ||
[ | ||
"astropy", | ||
"matplotlib", | ||
"numpy", | ||
"traitlets", | ||
"sklearn", | ||
"scipy", | ||
"numba", | ||
"pytest", | ||
"iminuit", | ||
"tables", | ||
"eventio", | ||
] | ||
) | ||
|
||
_optional_dependencies = sorted( | ||
["ctapipe_resources", "pytest", "graphviz", "matplotlib"] | ||
) | ||
|
||
|
||
def main(args=None): | ||
parser = get_parser(info) | ||
|
@@ -78,6 +59,12 @@ def main(args=None): | |
info(**vars(args)) | ||
|
||
|
||
def pretty_print_requires(package): | ||
pack_name = re.split(";|=|>|<|@|~| ", package)[0] | ||
entry = f"{pack_name} -- {get_module_version(pack_name)}" | ||
return entry | ||
|
||
|
||
def info( | ||
version=False, | ||
tools=False, | ||
|
@@ -160,17 +147,32 @@ def _info_tools(): | |
|
||
def _info_dependencies(): | ||
"""Print info about dependencies.""" | ||
print("\n*** ctapipe core dependencies ***\n") | ||
|
||
for name in _dependencies: | ||
version = get_module_version(name) | ||
print(f"{name:>20s} -- {version}") | ||
meta = metadata("ctapipe") | ||
extras = [v for k, v in meta.items() if k == "Provides-Extra"] | ||
|
||
all_dependencies = set(requires("ctapipe")) | ||
|
||
print("\n*** ctapipe optional dependencies ***\n") | ||
optional_dependencies = {extra: [] for extra in extras} | ||
|
||
for name in _optional_dependencies: | ||
version = get_module_version(name) | ||
print(f"{name:>20s} -- {version}") | ||
required_dependencies = [] | ||
for package in all_dependencies: | ||
if "extra" in package: | ||
for extra in extras: | ||
if extra in package: | ||
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. there is the same if twice here |
||
optional_dependencies[extra].append(pretty_print_requires(package)) | ||
else: | ||
required_dependencies.append(pretty_print_requires(package)) | ||
|
||
print("\n*** ctapipe core dependencies ***\n") | ||
|
||
for package in required_dependencies: | ||
print(package) | ||
|
||
for extra in optional_dependencies: | ||
print(f"\n*** ctapipe optional dependencies [{extra}] ***\n") | ||
for package in optional_dependencies[extra]: | ||
print(package) | ||
|
||
|
||
def _info_resources(): | ||
|
@@ -215,7 +217,6 @@ def _info_system(): | |
system_prov = prov.current_activity.provenance["system"] | ||
|
||
for section in ["platform", "python"]: | ||
|
||
print("\n====== ", section, " ======== \n") | ||
sysinfo = system_prov[section] | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Test ctapipe-info functionality.""" | ||
|
||
|
||
def test_info_version(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--version", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_tools(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--tools", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_dependencies(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--dependencies", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_system(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--system", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_plugins(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--plugins", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_eventsources(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--event-sources", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" | ||
|
||
|
||
def test_info_all(script_runner): | ||
|
||
result = script_runner.run( | ||
"ctapipe-info", | ||
"--all", | ||
) | ||
|
||
assert result.success | ||
assert result.stderr == "" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Optimize ``ctapipe-info --dependencies`` by reading them from the package installation code. | ||
Use ``pytest-console-scripts`` to test this tool. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ tests = | |
tomli | ||
pytest_astropy_header | ||
h5py | ||
|
||
pytest-console-scripts | ||
|
||
docs = | ||
sphinx | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be: