Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ updates:
patterns:
- "*"

- package-ecosystem: "pip"
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"
26 changes: 17 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.x"
- uses: astral-sh/setup-uv@v6
- run: |
uv run ruff check .

Expand All @@ -27,9 +25,7 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.x"
- uses: astral-sh/setup-uv@v6
- run: uv run pytest
env:
UV_PYTHON: ${{ matrix.python-version }}
Expand Down Expand Up @@ -57,6 +53,20 @@ jobs:
- run: |
deno check src/higlass/widget.js

Schema:
name: Check higlass-schema against viewconfs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- run: |
uv run --package higlass-schema higlass-schema export > schema.json
- uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm install -g ajv-cli
- run: ajv validate --spec=draft2020 -s schema.json -d "packages/higlass-schema/tests/fixtures/{docs/examples/viewconfs,test/{view-configs,view-configs-more}}/*.json"

Release:
needs: [Lint, Test]
runs-on: ubuntu-latest
Expand All @@ -66,9 +76,7 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
version: "0.5.x"
- uses: astral-sh/setup-uv@v6
- run: uv build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ and understanding are greatly appreciated.

## Development

**higlass-python** is primarily a Python project, but it includes JavaScript for
the anywidget-based front-end code (`src/higlass/widget.js`). We use
[uv](https://github.com/astral-sh/uv) for Python development and
[deno](https://github.com/denoland/deno) for linting and type-checking
JavaScript.
**higlass-python** is a uv workspace monorepo that includes the main library and
additional packages (e.g., **higlass-schema**). It's primarily a Python project,
but includes JavaScript for the anywidget-based front-end code
(`src/higlass/widget.js`). We use [uv](https://github.com/astral-sh/uv) for
Python development and [deno](https://github.com/denoland/deno) for linting and
type-checking JavaScript.

All formatting, linting, and tests are enforced in CI.

Expand All @@ -84,15 +85,25 @@ All commands are run from the root of the project, from a terminal:

#### Python

**Workspace-wide commands** (runs across all packages):

| Command | Action |
| ----------------------------------------------- | --------------------------------------------- |
| `uv run jupyter lab` | Run Jupyter lab with current package state |
| `uv run ruff check --fix && uv run ruff format` | Lint and apply formatting |
| `uv run check` | Check linting rules |
| `uv run ruff format --check` | Check formatting |
| `uv run pytest` | Run unit tests |
| `uv run ruff check --fix && uv run ruff format` | Lint and apply formatting across all packages |
| `uv run ruff format --check` | Check formatting across all packages |
| `uv run pytest` | Run unit tests across all packages |
| `uv run docs/build.py` | Build the documentation in `docs/_build/html` |

**Package-specific commands** (run a command within a specific package):

| Command | Action |
| ------------------------------------------------ | ------------------------------------ |
| `uv run --package higlass-schema pytest` | Run tests for higlass-schema package |
| `uv run --package higlass-schema ruff check` | Lint higlass-schema package |
| `uv run --package higlass-schema ruff format` | Format higlass-schema package |
| `uv run --package higlass-schema higlass-schema` | Run higlass-schema CLI |

#### JavaScript

| Command | Action |
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
}
},
"fmt": {
"exclude": ["examples"]
"exclude": ["examples", "docs", "packages/higlass-schema/tests/fixtures"]
}
}
21 changes: 21 additions & 0 deletions packages/higlass-schema/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Trevor James Manz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions packages/higlass-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# higlass-schema

[![PyPI](https://img.shields.io/pypi/v/higlass-schema.svg?color=green)](https://pypi.org/project/higlass-schema)
[![License](https://img.shields.io/pypi/l/gosling.svg?color=green)](https://github.com/higlass/higlass-schema/raw/main/LICENSE)

Pydantic models for HiGlass

```bash
pip install higlass-schema
```

## Development

Try it out:

```bash
$ uv run higlass-schema check ./example.json # [--verbose]
$ uv run higlass-schema export # prints JSON schema to stdout
```

Testing, linting, & formatting are enforced in CI. Locally, you can run:

```sh
uv run pytest # tests
uv run ruff check # linting
uv run ruff format --check # formatting (remove --check to apply)
```
23 changes: 23 additions & 0 deletions packages/higlass-schema/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[project]
name = "higlass-schema"
version = "0.2.1"
description = "Pydantic models for HiGlass"
readme = "README.md"
requires-python = ">=3.8"
license = { text = "MIT" }
authors = [{ name = "Trevor Manz", email = "trevor.j.manz@gmail.com" }]
dependencies = ["pydantic>=2.0", "rich>=13.0.0"]

[project.urls]
homepage = "https://github.com/higlass/higlass-schema"

[project.scripts]
higlass-schema = "higlass_schema.cli:main"

[build-system]
requires = ["uv_build>=0.8.0,<0.9"]
build-backend = "uv_build"

[tool.ruff]
extend = "../../pyproject.toml"
src = ["src", "tests"]
12 changes: 12 additions & 0 deletions packages/higlass-schema/src/higlass_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
try:
from importlib.metadata import PackageNotFoundError, version
except ImportError:
from importlib_metadata import PackageNotFoundError, version # type: ignore

try:
__version__ = version("higlass-schema")
except PackageNotFoundError:
__version__ = "uninstalled"


from .schema import *
57 changes: 57 additions & 0 deletions packages/higlass-schema/src/higlass_schema/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import argparse
import sys

from pydantic import ValidationError
from rich.console import Console

from .schema import Track, View, Viewconf, schema_json

console = Console()


def export(args: argparse.Namespace) -> None:
print(schema_json(indent=args.indent))


def check(args: argparse.Namespace) -> None:
try:
if args.path == "-":
raw = "\n".join(sys.stdin.readlines())
Viewconf[View[Track]].model_validate_json(raw)
else:
with open(args.path) as file:
raw = file.read()
Viewconf[View[Track]].model_validate_json(raw)
console.print("✅ valid viewconf.", style="green")
except ValidationError:
msg = "❌ Invalid viewconf."
if args.verbose:
console.print(msg, style="yellow")
console.print_exception()

console.print(
f"{msg} Run [white]`higlass-schema check --verbose`[/white] for "
"more details.",
style="yellow",
)
sys.exit(1)


def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="command")
subparsers.required = True

# export
parser_export = subparsers.add_parser("export")
parser_export.add_argument("--indent", type=int)
parser_export.set_defaults(func=export)

# check
parser_check = subparsers.add_parser("check")
parser_check.add_argument("path")
parser_check.add_argument("--verbose", action="store_true")
parser_check.set_defaults(func=check)

ns = parser.parse_args(sys.argv[1:])
ns.func(ns)
Loading