Skip to content

Commit 6d79733

Browse files
authored
Gh actions (#4)
* fix parsing issue * add cli to get default module list names
1 parent 2f0026a commit 6d79733

File tree

5 files changed

+93
-35
lines changed

5 files changed

+93
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ The easiest way to use obspy_github_api is via its command line interface.
1010
obshub make_config 101 --path obspy_config.json
1111

1212
# Read a specified option.
13-
obshub read_config_value module_list --path obspy_config.json
13+
obshub read-config-value module_list --path obspy_config.json
1414

1515
# Use a value in the config in another command line utility.
16-
export BUILDDOCS=`bshub read_config_value module_list --path obspy_config.json`
16+
export BUILDDOCS=`obshub read-config-value module_list --path obspy_config.json`
1717
some-other-command --docs $BUILDDOCS
1818
```
1919

obspy_github_api/cli.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import typer
88

9-
from obspy_github_api.obspy_github_api import make_ci_json_config
9+
from obspy_github_api.obspy_github_api import (
10+
make_ci_json_config,
11+
get_obspy_module_lists,
12+
_append_obspy,
13+
)
1014

1115
app = typer.Typer()
1216

@@ -44,6 +48,27 @@ def read_config_value(name: str, path: str = DEFAULT_CONFIG_PATH):
4448
return value
4549

4650

51+
@app.command()
52+
def get_module_list(group: str = "default", sep=" "):
53+
"""
54+
Print and return module lists for use with coverage.
55+
56+
Parameters
57+
----------
58+
group
59+
The name of the module group. Options are:
60+
default
61+
all
62+
network
63+
sep
64+
Character to separate modules, ' ' else ','
65+
"""
66+
mod_list = get_obspy_module_lists()[group]
67+
with_obspy = _append_obspy(mod_list)
68+
print(sep.join(with_obspy))
69+
return with_obspy
70+
71+
4772
def main():
4873
app()
4974

obspy_github_api/obspy_github_api.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import json
55
import os
66
import re
7-
import time
87
import warnings
98
from functools import lru_cache
109
from pathlib import Path
@@ -38,7 +37,7 @@ def get_github_client(token=None):
3837
return gh
3938

4039

41-
def check_specific_module_tests_requested(issue_number, token=None):
40+
def get_requested_modules(issue_number, token=None):
4241
"""
4342
Checks if tests of specific modules are requested for given issue number
4443
(e.g. by magic string '+TESTS:clients.fdsn,clients.arclink' or '+TESTS:ALL'
@@ -79,8 +78,21 @@ def check_specific_module_tests_requested(issue_number, token=None):
7978
return modules_to_test
8079

8180

81+
def get_obspy_module_lists(module_path="./obspy/core/util/base.py"):
82+
"""Return a dict of lists of obspy's default, network, and all modules."""
83+
try: # If ObsPy is installed just use module list from expected place.
84+
from obspy.core.util.base import DEFAULT_MODULES, ALL_MODULES, NETWORK_MODULES
85+
except (ImportError, ModuleNotFoundError): # Else parse the module.
86+
names = {"DEFAULT_MODULES", "NETWORK_MODULES"}
87+
values = get_values_from_module(module_path, names)
88+
DEFAULT_MODULES = values["DEFAULT_MODULES"]
89+
NETWORK_MODULES = values["NETWORK_MODULES"]
90+
ALL_MODULES = DEFAULT_MODULES + NETWORK_MODULES
91+
return dict(all=ALL_MODULES, default=DEFAULT_MODULES, network=NETWORK_MODULES)
92+
93+
8294
def get_module_test_list(
83-
issue_number, token=None, module_path="./obspy/core/util/base.py"
95+
issue_number, token=None, module_path="./obspy/core/util/base.py",
8496
):
8597
"""
8698
Gets the list of modules that should be tested for the given issue number.
@@ -92,23 +104,16 @@ def get_module_test_list(
92104
:rtype: list
93105
:returns: List of modules names to test for given issue number.
94106
"""
95-
try: # If ObsPy is installed just use module list from expected place.
96-
from obspy.core.util.base import DEFAULT_MODULES, ALL_MODULES
97-
except (ImportError, ModuleNotFoundError): # Else parse the module.
98-
names = {"DEFAULT_MODULES", "NETWORK_MODULES"}
99-
values = get_values_from_module(module_path, names)
100-
DEFAULT_MODULES = values["DEFAULT_MODULES"]
101-
NETWORK_MODULES = values["NETWORK_MODULES"]
102-
ALL_MODULES = DEFAULT_MODULES + NETWORK_MODULES
103-
104-
modules_to_test = check_specific_module_tests_requested(issue_number, token)
105-
107+
mod_dict = get_obspy_module_lists(module_path)
108+
modules_to_test = get_requested_modules(issue_number, token)
109+
# Set to default or all
106110
if modules_to_test is False:
107-
return DEFAULT_MODULES
111+
modules_to_test = mod_dict["default"]
108112
elif modules_to_test is True:
109-
return ALL_MODULES
110-
else:
111-
return sorted(list(set.union(set(DEFAULT_MODULES), modules_to_test)))
113+
modules_to_test = mod_dict["all"]
114+
# filter out any modules which don't exist
115+
modules_to_test = set(modules_to_test) & set(mod_dict["all"])
116+
return sorted(list(set.union(set(mod_dict["default"]), modules_to_test)))
112117

113118

114119
def get_values_from_module(node, names):
@@ -449,6 +454,14 @@ def get_docker_build_targets(
449454
return " ".join(targets)
450455

451456

457+
def _append_obspy(module_list):
458+
"""
459+
Append the string 'obspy.' to each string in module list for use in coverage.
460+
"""
461+
module_list_obspy_prepended = [f"obspy.{x}" for x in module_list]
462+
return module_list_obspy_prepended
463+
464+
452465
def make_ci_json_config(issue_number, path="obspy_ci_conf.json", token=None):
453466
"""
454467
Make a json file for configuring additional actions in CI.
@@ -459,7 +472,7 @@ def make_ci_json_config(issue_number, path="obspy_ci_conf.json", token=None):
459472
# comment string to use for later actions.
460473
module_list = get_module_test_list(issue_number, token=token)
461474
docs = check_docs_build_requested(issue_number, token=token)
462-
module_list_obspy_prepended = [f"obspy.{x}" for x in module_list]
475+
module_list_obspy_prepended = _append_obspy(module_list)
463476

464477
out = dict(
465478
module_list=",".join(module_list_obspy_prepended),

obspy_github_api/tests/test_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ def test_read_config_value(self, populated_config):
4545
run_str = f"obshub read-config-value docs --path {populated_config}"
4646
out = run(run_str, shell=True, capture_output=True)
4747
assert out.stdout.decode("utf8").rstrip() == "False"
48+
49+
def test_get_module_lists(self):
50+
"""Ensure module lists are retrievable. """
51+
run_str = f"obshub get-module-list --sep ' '"
52+
out = run(run_str, shell=True, capture_output=True)
53+
mod_list = out.stdout.decode("utf8").rstrip().split(" ")
54+
assert len(mod_list) > 5
55+
for mod in mod_list:
56+
assert mod.startswith("obspy.")

obspy_github_api/tests/test_obspy_github_api.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from obspy_github_api import (
55
check_docs_build_requested,
6-
check_specific_module_tests_requested,
6+
get_requested_modules,
77
get_commit_status,
88
get_commit_time,
99
get_issue_numbers_that_request_docs_build,
@@ -23,9 +23,9 @@ def test_check_docs_build_requested():
2323

2424

2525
def test_check_specific_module_tests_requested():
26-
assert check_specific_module_tests_requested(100) is False
27-
assert check_specific_module_tests_requested(101) is True
28-
assert check_specific_module_tests_requested(102) == [
26+
assert get_requested_modules(100) is False
27+
assert get_requested_modules(101) is True
28+
assert get_requested_modules(102) == [
2929
"clients.arclink",
3030
"clients.fdsn",
3131
]
@@ -34,8 +34,8 @@ def test_check_specific_module_tests_requested():
3434
@mock.patch("obspy.core.util.base.DEFAULT_MODULES", MOCK_DEFAULT_MODULES)
3535
@mock.patch("obspy.core.util.base.ALL_MODULES", MOCK_ALL_MODULES)
3636
def test_get_module_test_list():
37-
assert get_module_test_list(100) == MOCK_DEFAULT_MODULES
38-
assert get_module_test_list(101) == MOCK_ALL_MODULES
37+
assert get_module_test_list(100) == sorted(MOCK_DEFAULT_MODULES)
38+
assert get_module_test_list(101) == sorted(MOCK_ALL_MODULES)
3939
assert get_module_test_list(102) == sorted(
4040
set.union(set(MOCK_DEFAULT_MODULES), ["clients.arclink", "clients.fdsn"])
4141
)
@@ -73,10 +73,21 @@ def test_get_issue_numbers_that_request_docs_build():
7373
assert isinstance(issue, int)
7474

7575

76-
def test_json_ci_config():
77-
"""Tests contents of configuration dict."""
78-
config_dict = make_ci_json_config(100, path=None)
79-
assert isinstance(config_dict, dict)
80-
# ensure module list elements don't end in '.'
81-
module_list_split = config_dict["module_list"].split(",")
82-
assert all([not x.endswith(".") for x in module_list_split])
76+
class TestConfig:
77+
"""Tests for creating the configuration file"""
78+
79+
def test_json_ci_config(self):
80+
"""Tests contents of configuration dict."""
81+
config_dict = make_ci_json_config(100, path=None)
82+
assert isinstance(config_dict, dict)
83+
# ensure module list elements don't end in '.'
84+
module_list_split = config_dict["module_list"].split(",")
85+
assert all([not x.endswith(".") for x in module_list_split])
86+
87+
def test_no_ellipses(self):
88+
"""Ensure the literal 'obspy....' is not in the module list. """
89+
config_dict = make_ci_json_config(2591, path=None)
90+
module_list = config_dict["module_list"]
91+
module_list_split = module_list.split(",")
92+
# There should never be more than one consecutive dot
93+
assert not any([".." in x for x in module_list_split])

0 commit comments

Comments
 (0)