Skip to content

Commit

Permalink
Merge pull request #892 from tsalo/schema-package
Browse files Browse the repository at this point in the history
[SCHEMA] Reorganize schema code into a package
  • Loading branch information
effigies authored Jan 5, 2022
2 parents 21b7725 + 97794d5 commit 9d31e2d
Show file tree
Hide file tree
Showing 23 changed files with 3,321 additions and 208 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
command: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ~/project/tools/schemacode/
- run:
name: generate docs
command: mkdocs build --clean --strict --verbose
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.png -text
*.jpg -text
*.webm -text
tools/schemacode/schemacode/_version.py export-subst
94 changes: 94 additions & 0 deletions .github/workflows/schemacode_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: "schemacode_ci"

on:
push:
branches:
- "master"
paths:
- "tools/schemacode/**"
- "src/schema/**"
pull_request:
branches:
- "*"
paths:
- "tools/schemacode/**"
- "src/schema/**"

jobs:
check_skip:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.result_step.outputs.ci-skip }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: result_step
uses: mstachniuk/ci-skip@master
with:
commit-filter: "[skip ci];[ci skip];[skip github]"
commit-filter-separator: ";"

run_tests:
needs: check_skip
if: ${{ needs.check_skip.outputs.skip == 'false' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2

- name: "Set up Python"
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: "Display Python version"
shell: bash {0}
run: python -c "import sys; print(sys.version)"

- name: "Install the schemacode package"
shell: bash {0}
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install -e ./tools/schemacode[tests]
- name: "Run tests"
shell: bash {0}
run: |
python -m pytest --pyargs schemacode --cov=schemacode ./tools/schemacode/
- name: "Upload coverage to CodeCov"
uses: codecov/codecov-action@v1
if: success()

flake8-lint:
runs-on: ubuntu-latest
name: Lint schemacode
steps:
- name: Check out source repository
uses: actions/checkout@v2

- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: "3.7"

- name: "Install the schemacode package"
shell: bash {0}
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install -e ./tools/schemacode[tests]
- name: "Run flake8"
working-directory: ./tools/schemacode/
shell: bash {0}
run: |
flake8 .
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
/src/05-derivatives/05-functional-derivatives.md @effigies
/src/05-derivatives/06-diffusion-derivatives.md @francopestilli @oesteban @Lestropie
/src/99-appendices/06-meg-file-formats.md @monkeyman192

# The schema
/src/schema/ @tsalo
/tools/schemacode/ @tsalo
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ pymdown-extensions>=7.0.0
mkdocs-branchcustomization-plugin~=0.1.3
mkdocs-macros-plugin
numpy
pandas
PYYaml
tabulate
tools/schemacode/
17 changes: 9 additions & 8 deletions tools/mkdocs_macros_bids/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import os
import sys

from schemacode import render, schema, utils

code_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(code_path)

from examplecode import example
from schemacode import schema, utils


def make_filename_template(**kwargs):
Expand All @@ -28,7 +29,7 @@ def make_filename_template(**kwargs):
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
codeblock = schema.make_filename_template(schema_obj, **kwargs)
codeblock = render.make_filename_template(schema_obj, **kwargs)
return codeblock


Expand All @@ -50,7 +51,7 @@ def make_entity_table(**kwargs):
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
table = schema.make_entity_table(schema_obj, **kwargs)
table = render.make_entity_table(schema_obj, **kwargs)
return table


Expand All @@ -66,7 +67,7 @@ def make_entity_definitions():
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
text = schema.make_entity_definitions(schema_obj)
text = render.make_entity_definitions(schema_obj)
return text


Expand All @@ -81,7 +82,7 @@ def make_glossary():
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
text = schema.make_glossary(schema_obj)
text = render.make_glossary(schema_obj)
return text


Expand All @@ -101,7 +102,7 @@ def make_suffix_table(suffixes):
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
table = schema.make_suffix_table(schema_obj, suffixes)
table = render.make_suffix_table(schema_obj, suffixes)
return table


Expand All @@ -126,7 +127,7 @@ def make_metadata_table(field_info):
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
table = schema.make_metadata_table(schema_obj, field_info)
table = render.make_metadata_table(schema_obj, field_info)
return table


Expand All @@ -151,7 +152,7 @@ def make_columns_table(column_info):
"""
schemapath = utils.get_schema_path()
schema_obj = schema.load_schema(schemapath)
table = schema.make_columns_table(schema_obj, column_info)
table = render.make_columns_table(schema_obj, column_info)
return table


Expand Down
2 changes: 2 additions & 0 deletions tools/schemacode/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include versioneer.py
include schemacode/_version.py
6 changes: 6 additions & 0 deletions tools/schemacode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# schemacode

A Python library for working with the BIDS schema.

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![codecov](https://codecov.io/gh/bids-standard/bids-specification/branch/master/graph/badge.svg)](https://codecov.io/gh/bids-standard/bids-specification)
7 changes: 0 additions & 7 deletions tools/schemacode/__init__.py

This file was deleted.

27 changes: 27 additions & 0 deletions tools/schemacode/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[build-system]
requires = ["setuptools", "wheel"]

[tool.black]
line-length = 99
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.github
| \.hg
| \.pytest_cache
| _build
| build
| dist
)/
| versioneer.py
| schemacode/_version.py
)
'''

[tool.isort]
profile = "black"
multi_line_output = 3
12 changes: 12 additions & 0 deletions tools/schemacode/schemacode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""A Python package for working with the BIDS schema."""
from . import render, schema, utils

__all__ = [
"render",
"schema",
"utils",
]

from . import _version

__version__ = _version.get_versions()["version"]
Loading

0 comments on commit 9d31e2d

Please sign in to comment.