Skip to content

Commit

Permalink
Updated gitactions
Browse files Browse the repository at this point in the history
  • Loading branch information
VisLab committed Sep 27, 2024
1 parent 940f16e commit c68f542
Show file tree
Hide file tree
Showing 35 changed files with 157 additions and 174 deletions.
27 changes: 8 additions & 19 deletions .github/workflows/ci_cov.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CICOV
name: CI_COV

on:
push:
Expand Down Expand Up @@ -43,24 +43,15 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('docs/requirements.txt') }}

# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade --upgrade-strategy eager pip
pip install flake8
pip install coverage
pip install -r requirements.txt
pip install -r docs/requirements.txt
pip install flake8 coverage -r requirements.txt -r docs/requirements.txt
# Run flake8 only for Python 3.9
# Run flake8
- name: Lint with flake8
run: |
pip install flake8
flake8 . --count --show-source --statistics --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# Run unittest with coverage
Expand All @@ -77,14 +68,12 @@ jobs:
HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coverage run --append -m unittest discover spec_tests
coverage xml
ls -la
# Publish the coverages
- name: publish-coverages
with:
coverageCommand: coverage xml
debug: false
# Upload coverage to Code Climate
- name: Upload coverage to Code Climate
if: needs.check-secret.outputs.secrets-exist == 'true'
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

10 changes: 5 additions & 5 deletions hed/errors/schema_error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ def schema_error_SCHEMA_INVALID_CHILD(tag, child_tag_list):

@hed_error(SchemaAttributeErrors.SCHEMA_ATTRIBUTE_INVALID)
def schema_error_unknown_attribute(attribute_name, source_tag):
return f"Attribute '{attribute_name}' used by '{source_tag}' "
f"was not defined in the schema, or was used outside of it's defined class."
return f"Attribute '{attribute_name}' used by '{source_tag}' " + \
"was not defined in the schema, or was used outside of it's defined class."


@hed_error(SchemaWarnings.SCHEMA_PRERELEASE_VERSION_USED, default_severity=ErrorSeverity.WARNING)
def schema_error_SCHEMA_PRERELEASE_VERSION_USED(current_version, known_versions):
return f"Schema version {current_version} used, which is prerelease or unofficial. "
return f"Schema version {current_version} used, which is prerelease or unofficial. " + \
f"Known versions are: {', '.join(known_versions)}"


@hed_error(SchemaWarnings.SCHEMA_PROLOGUE_CHARACTER_INVALID, default_severity=ErrorSeverity.WARNING,
actual_code=SchemaWarnings.SCHEMA_CHARACTER_INVALID)
def schema_error_invalid_character_prologue(char_index, source_string, section_name):
invalid_char = source_string[char_index]
return f"'{section_name}' has invalid character '{invalid_char}' at "
return f"'{section_name}' has invalid character '{invalid_char}' at " + \
f"position {char_index} of string: {source_string}"


Expand Down Expand Up @@ -91,7 +91,7 @@ def schema_error_SCHEMA_CHILD_OF_DEPRECATED(deprecated_tag, non_deprecated_child
@hed_error(SchemaAttributeErrors.SCHEMA_ATTRIBUTE_VALUE_DEPRECATED,
actual_code=SchemaAttributeErrors.SCHEMA_DEPRECATION_ERROR)
def schema_error_SCHEMA_ATTRIBUTE_VALUE_DEPRECATED(tag, deprecated_suggestion, attribute_name):
return (f"Tag '{tag}' {attribute_name} uses '{deprecated_suggestion}' which has been deprecated "
return (f"Tag '{tag}' {attribute_name} uses '{deprecated_suggestion}' which has been deprecated " + \
f"and an alternative method of tagging should be used.")


Expand Down
4 changes: 2 additions & 2 deletions hed/schema/hed_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def get_library_data(library_name, cache_folder=None):
library_data = json.load(file)
specific_library = library_data[library_name]
return specific_library
except (OSError, CacheException, ValueError, URLError, KeyError) as e:
except (OSError, CacheException, ValueError, URLError, KeyError):
pass

# This failed to get any data for some reason
Expand Down Expand Up @@ -288,7 +288,7 @@ def _check_if_url(hed_xml_or_url):

def _create_xml_filename(hed_xml_version, library_name=None, hed_directory=None, prerelease=False):
"""Returns the default file name format for the given version"""
prerelease_prefix = f"prerelease/" if prerelease else ""
prerelease_prefix = "prerelease/" if prerelease else ""
if library_name:
hed_xml_basename = f"{prerelease_prefix}{HED_XML_PREFIX}_{library_name}_{hed_xml_version}{HED_XML_EXTENSION}"
else:
Expand Down
6 changes: 3 additions & 3 deletions hed/schema/schema_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def check_duplicate_names(self):
error_code = SchemaErrors.SCHEMA_DUPLICATE_NODE
if len(values) == 2:
error_code = SchemaErrors.SCHEMA_DUPLICATE_FROM_LIBRARY
issues_list += self.error_handler.format_error_with_context(error_code, name,
duplicate_tag_list=[entry.name for entry in duplicate_entries],
section=section_key)
issues_list += self.error_handler.format_error_with_context(
error_code, name, duplicate_tag_list=[entry.name for entry in duplicate_entries],
section=section_key)
return issues_list

def check_invalid_chars(self):
Expand Down
2 changes: 1 addition & 1 deletion hed/schema/schema_io/df_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def load_dataframes(filenames, include_prefix_dfs=False):
f"Required column(s) {list(columns_not_in_loaded)} missing from {filename}. "
f"The required columns are {list(dataframes[key].columns)}", filename=filename)
dataframes[key] = loaded_dataframe
except OSError as e:
except OSError:
# todo: consider if we want to report this error(we probably do)
pass # We will use a blank one for this
return dataframes
Expand Down
15 changes: 8 additions & 7 deletions hed/schema/schema_io/ontology_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,19 @@ def _verify_hedid_matches(section, df, unused_tag_ids):
try:
id_int = int(id_value)
if id_int not in unused_tag_ids:
hedid_errors += schema_util.format_error(row_number, row,
f"'{label}' has id {id_int} which is outside of the valid range for this type. Valid range is: {min(unused_tag_ids)} to {max(unused_tag_ids)}")
hedid_errors += schema_util.format_error(
row_number, row, f"'{label}' has id {id_int} which is outside " +
f"of the valid range for this type. Valid range is: " +
f"{min(unused_tag_ids)} to {max(unused_tag_ids)}")
continue
except ValueError:
hedid_errors += schema_util.format_error(row_number, row,
f"'{label}' has a non-numeric hedID in the dataframe.")
hedid_errors += schema_util.format_error(
row_number, row, f"'{label}' has a non-numeric hedID in the dataframe.")
continue

if entry_id and entry_id != df_id:
hedid_errors += schema_util.format_error(row_number, row,
f"'{label}' has hedID '{df_id}' in dataframe, but '{entry_id}' in schema.")
hedid_errors += schema_util.format_error(
row_number, row, f"'{label}' has hedID '{df_id}' in dataframe, but '{entry_id}' in schema.")
continue

return hedid_errors
Expand Down Expand Up @@ -437,4 +439,3 @@ def _add_annotation_lines(row, annotation_properties, annotation_terms):
def _get_property_type(row):
"""Gets the property type from the row."""
return row[constants.property_type] if constants.property_type in row.index else "Class"

9 changes: 4 additions & 5 deletions hed/schema/schema_io/schema2df.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,13 @@ def _get_subclass_of(self, tag_entry):
return tag_entry.parent.short_tag_name if tag_entry.parent else "HedTag"

base_objects = {
HedSectionKey.Units: f"HedUnit",
HedSectionKey.UnitClasses: f"HedUnitClass",
HedSectionKey.UnitModifiers: f"HedUnitModifier",
HedSectionKey.ValueClasses: f"HedValueClass"
HedSectionKey.Units: "HedUnit",
HedSectionKey.UnitClasses: "HedUnitClass",
HedSectionKey.UnitModifiers: "HedUnitModifier",
HedSectionKey.ValueClasses: "HedValueClass"
}
name, obj_id = self._get_object_name_and_id(base_objects[tag_entry.section_key], include_prefix=True)

if self._get_as_ids:
return obj_id
return name

4 changes: 2 additions & 2 deletions hed/schema/schema_io/wiki2schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ def _create_tag_entry(self, parent_tags, row_number, row):
long_tag_name = tag_name
return self._create_entry(row_number, row, HedSectionKey.Tags, long_tag_name)

self._add_fatal_error(row_number, row, "Schema term is empty or the line is malformed"
, error_code=HedExceptions.WIKI_DELIMITERS_INVALID)
self._add_fatal_error(row_number, row, "Schema term is empty or the line is malformed",
error_code=HedExceptions.WIKI_DELIMITERS_INVALID)

def _add_to_dict(self, row_number, row, entry, key_class):
if entry.has_attribute(HedKey.InLibrary) and not self._loading_merged and not self.appending_to_schema:
Expand Down
3 changes: 2 additions & 1 deletion hed/scripts/validate_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def main():
return 1
return 0


if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
28 changes: 14 additions & 14 deletions hed/tools/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
""" Basic analysis tools. """
from .file_dictionary import FileDictionary
from .annotation_util import (check_df_columns, df_to_hed, extract_tags, generate_sidecar_entry, get_bids_dataset,
hed_to_df, str_to_tabular, strs_to_sidecar, to_strlist)
from .event_manager import EventManager
from .hed_tag_manager import HedTagManager
from .hed_type_defs import HedTypeDefs
from .hed_type_factors import HedTypeFactors
from .hed_type import HedType
from .hed_type_manager import HedTypeManager
from .hed_type_counts import HedTypeCount
from .key_map import KeyMap
from .tabular_summary import TabularSummary
from .temporal_event import TemporalEvent
""" Basic analysis tools. """
from .file_dictionary import FileDictionary
from .annotation_util import (check_df_columns, df_to_hed, extract_tags, generate_sidecar_entry, get_bids_dataset,
hed_to_df, str_to_tabular, strs_to_sidecar, to_strlist)
from .event_manager import EventManager
from .hed_tag_manager import HedTagManager
from .hed_type_defs import HedTypeDefs
from .hed_type_factors import HedTypeFactors
from .hed_type import HedType
from .hed_type_manager import HedTypeManager
from .hed_type_counts import HedTypeCount
from .key_map import KeyMap
from .tabular_summary import TabularSummary
from .temporal_event import TemporalEvent
6 changes: 3 additions & 3 deletions hed/tools/bids/bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class BidsDataset:
""" A BIDS dataset representation primarily focused on HED evaluation.
Attributes:
root_path (str): Real root path of the BIDS dataset.
schema (HedSchema or HedSchemaGroup): The schema used for evaluation.
tabular_files (dict): A dictionary of BidsTabularDictionary objects containing a given type.
root_path (str): Real root path of the BIDS dataset.
schema (HedSchema or HedSchemaGroup): The schema used for evaluation.
tabular_files (dict): A dictionary of BidsTabularDictionary objects containing a given type.
"""

Expand Down
2 changes: 1 addition & 1 deletion hed/tools/remodeling/cli/run_remodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def main(arg_list=None):
if not args.no_summaries:
dispatch.save_summaries(args.save_formats, individual_summaries=args.individual_summaries,
summary_dir=save_dir, task_name=task)
except Exception as ex:
except Exception:
if args.log_dir:
log_name = io_util.get_alphanumeric_path(os.path.realpath(args.data_dir)) + '_' + timestamp + '.txt'
logging.basicConfig(filename=os.path.join(args.log_dir, log_name), level=logging.ERROR)
Expand Down
2 changes: 1 addition & 1 deletion hed/tools/remodeling/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_summary_save_dir(self):

if self.data_root:
return os.path.realpath(os.path.join(self.data_root, 'derivatives', Dispatcher.REMODELING_SUMMARY_PATH))
raise HedFileError("NoDataRoot", f"Dispatcher must have a data root to produce directories", "")
raise HedFileError("NoDataRoot", "Dispatcher must have a data root to produce directories", "")

def run_operations(self, file_path, sidecar=None, verbose=False):
""" Run the dispatcher operations on a file.
Expand Down
6 changes: 3 additions & 3 deletions hed/tools/remodeling/operations/summarize_definitions_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class SummarizeDefinitionsOp(BaseOp):
""" Summarize the definitions used in the dataset based on Def and Def-expand.
Required remodeling parameters:
- **summary_name** (*str*): The name of the summary.
- **summary_filename** (*str*): Base filename of the summary.
- **summary_name** (*str*): The name of the summary.
- **summary_filename** (*str*): Base filename of the summary.
Optional remodeling parameters:
- **append_timecode** (*bool*): If False (default), the timecode is not appended to the summary filename.
Expand All @@ -20,7 +20,7 @@ class SummarizeDefinitionsOp(BaseOp):
"""
NAME = "summarize_definitions"

PARAMS = {
"type": "object",
"properties": {
Expand Down
3 changes: 2 additions & 1 deletion hed/validator/def_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def validate_def_value_units(self, def_tag, hed_validator, allow_placeholders=Fa
error_code = ValidationErrors.DEF_EXPAND_INVALID

# Validate the def name vs the name class
def_issues = hed_validator._unit_validator._check_value_class(def_tag, tag_label, report_as=None, error_code=error_code, index_offset=0)
def_issues = hed_validator._unit_validator._check_value_class(def_tag, tag_label, report_as=None,
error_code=error_code, index_offset=0)
# def_issues += hed_validator.validate_units(def_tag,
# tag_label,
# error_code=error_code)
Expand Down
6 changes: 4 additions & 2 deletions hed/validator/hed_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ def _validate_individual_tags_in_hed_string(self, hed_string_obj, allow_placehol
self._tag_validator.run_individual_tag_validators(hed_tag, allow_placeholders=allow_placeholders,
is_definition=is_definition)
if (hed_tag.short_base_tag == DefTagNames.DEF_KEY or
hed_tag.short_base_tag == DefTagNames.DEF_EXPAND_KEY):
validation_issues += self._def_validator.validate_def_value_units(hed_tag, self, allow_placeholders=allow_placeholders)
hed_tag.short_base_tag == DefTagNames.DEF_EXPAND_KEY):
validation_issues += (
self._def_validator.validate_def_value_units(hed_tag,
self, allow_placeholders=allow_placeholders))
elif (hed_tag.short_base_tag == DefTagNames.DEFINITION_KEY) and hed_tag.extension.endswith("/#"):
validation_issues += self.validate_units(hed_tag, hed_tag.extension[:-2])
elif not (allow_placeholders and '#' in hed_tag.extension):
Expand Down
4 changes: 0 additions & 4 deletions hed/validator/util/class_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
""" Utilities to support HED validation. """
import datetime
import re
import json

from hed.schema import schema_validation_util
from hed.schema import schema_validation_util_deprecated
from hed.errors.error_reporter import ErrorHandler
from hed.errors.error_types import ValidationErrors
from hed.validator.util.char_util import CharRexValidator
Expand Down Expand Up @@ -182,7 +179,6 @@ def _check_value_class(self, original_tag, stripped_value, report_as, error_code
"""


if not original_tag.is_takes_value_tag():
return []

Expand Down
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# dummy setup file for versioneer

import versioneer
from setuptools import setup

if __name__ == "__main__":
setup(version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass())
# dummy setup file for versioneer

import versioneer
from setuptools import setup

if __name__ == "__main__":
setup(version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass())
4 changes: 2 additions & 2 deletions spec_tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _run_single_combo_test(self, info, schema, def_dict, error_code, all_codes,
except HedFileError:
print(f"{error_code}: {description}")
print(f"Improper data for test {name}: {test}")
print(f"This is probably a missing set of square brackets.")
print("This is probably a missing set of square brackets.")
continue
issues += file.validate(hed_schema=schema, extra_def_dicts=def_dict, error_handler=error_handler)
self.report_result(result, issues, error_code, all_codes, description, name, test, "combo_tests")
Expand All @@ -208,7 +208,7 @@ def _run_single_schema_test(self, info, error_code, all_codes, description, name
def test_errors(self):
for test_file in self.test_files:
self.run_single_test(test_file)
#test_file = './temp.json'
# test_file = './temp.json'
self.run_single_test(test_file)
print(f"{len(self.fail_count)} tests got an unexpected result")
print("\n".join(self.fail_count))
Expand Down
10 changes: 6 additions & 4 deletions spec_tests/test_hed_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def setUpClass(cls):
cls.semantic_version_three = '1.2.5'
cls.semantic_version_list = ['1.2.3', '1.2.4', '1.2.5']
cls.specific_base_url = "https://api.github.com/repos/hed-standard/hed-schemas/contents/standard_schema/hedxml"
cls.specific_hed_url = "https://raw.githubusercontent.com/hed-standard/hed-schemas/master/standard_schema/hedxml/HED8.0.0.xml"
cls.specific_hed_url = \
"https://raw.githubusercontent.com/hed-standard/hed-schemas/master/standard_schema/hedxml/HED8.0.0.xml"
try:
hed_cache.cache_xml_versions(cache_folder=cls.hed_cache_dir)
except HedFileError as e:
Expand Down Expand Up @@ -152,15 +153,17 @@ class TestLibraryDataCache(unittest.TestCase):
# Verify get_library_data properly caches from the internet and locally
@classmethod
def setUpClass(cls):
hed_cache_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../schema_cache_test_get_library_data/')
hed_cache_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'../schema_cache_test_get_library_data/')
if os.path.exists(hed_cache_dir) and os.path.isdir(hed_cache_dir):
shutil.rmtree(hed_cache_dir)
hed_cache.get_library_data.cache_clear()
cls.hed_cache_dir = hed_cache_dir
cls.saved_cache_folder = hed_cache.HED_CACHE_DIRECTORY
schema.set_cache_directory(cls.hed_cache_dir)
cls.saved_install_cache = hed_cache.INSTALLED_CACHE_LOCATION
cls.empty_source_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../schema_install_empty_local/")
cls.empty_source_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"../schema_install_empty_local/")
if os.path.exists(cls.empty_source_dir) and os.path.isdir(cls.empty_source_dir):
shutil.rmtree(cls.empty_source_dir)
os.makedirs(cls.empty_source_dir)
Expand Down Expand Up @@ -214,4 +217,3 @@ def test_url_cache(self):

if __name__ == '__main__':
unittest.main()

Loading

0 comments on commit c68f542

Please sign in to comment.