Skip to main content

No project description provided

Project description

lkmlfmt

lkmlfmt formats your LookML files including embedded SQL and HTML.

Installation

pip install lkmlfmt

CLI

Use lkmlfmt command to format your LookML file(s). For further information, use --help option.

lkmlfmt [OPTIONS] [FILE]...

API

from lkmlfmt import fmt

lkml = fmt("""\
view: view_name {
  derived_table: {
    sql:
    with cte as (
      select col1, col2 from tablename
      where ts between current_date()-7 and current_date())
    select {% if true %} col1 {% elsif %} col2 {% endif %} from cte
    ;;
  }
}
""")

assert lkml == """\
view: view_name {
  derived_table: {
    sql:
      with
        cte as (
          select col1, col2
          from tablename
          where ts between current_date() - 7 and current_date()
        )
      select
        {% if true %} col1
        {% elsif %} col2
        {% endif %}
      from cte
    ;;
  }
}
"""

GitHub Actions

To check if your LookML files are formatted.

on: [pull_request]
jobs:
  format-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          # '>=3.11' is required
          python-version: '3.11'

      # you should specify the version of lkmlfmt!
      - run: pip install lkmlfmt
      - run: lkmlfmt --check path/to/lookml/file/or/directory

To format arbitrary branch and create pull request.

on: [workflow_dispatch]
jobs:
  format-pr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          # '>=3.11' is required
          python-version: '3.11'

      # you should specify the version of lkmlfmt!
      - run: pip install lkmlfmt
      - run: lkmlfmt path/to/lookml/file/or/directory

      # check the documentation especially about workflow permissions
      # https://github.com/marketplace/actions/create-pull-request
      - uses: peter-evans/create-pull-request@v5
        with:
          branch: format/${{ github.ref_name }}

Feedback

I'm not ready to accept pull requests, but your feedback is always welcome. If you find any bugs, please feel free to create an issue.

See also

In default, lkmlfmt formats embedded sql using sqlfmt.

You can install plugins to change the format of embeded looker expression, sql or html. They are distributed under their own licenses, so please check if they are suitable for your purpose.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lkmlfmt-0.0.8.tar.gz (9.8 kB view hashes)

Uploaded Source

Built Distribution

lkmlfmt-0.0.8-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page