forked from repo-mirrors/sqlfluff
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
879a60554c | ||
|
|
05982f04e4 | ||
|
|
b71b1cb8fc | ||
|
|
b7d21b3680 | ||
|
|
dd34cb9fe1 | ||
|
|
3bae3f97e8 | ||
|
|
1df70a22a4 |
@@ -20,7 +20,13 @@ jobs:
|
||||
pip install twine wheel --upgrade
|
||||
|
||||
- name: Build Distribution (dbt plugin)
|
||||
# Run this in the right directory so that we get the right Manifest
|
||||
working-directory: plugins/sqlfluff-templater-dbt
|
||||
run: python plugins/sqlfluff-templater-dbt/setup.py sdist bdist_wheel
|
||||
|
||||
- name: Copy builds to main dist folder
|
||||
# We move them here so that the github action can still access them
|
||||
run: cp plugins/sqlfluff-templater-dbt/dist/. dist/.
|
||||
|
||||
- name: Publish Python distribution to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@master
|
||||
|
||||
@@ -304,8 +304,13 @@ dbt Project Configuration
|
||||
-------------------------
|
||||
|
||||
.. note::
|
||||
dbt templating is a new feature added in 0.4.0 and has not benefited
|
||||
from widespread use and testing yet! If you encounter an issue, please
|
||||
From sqlfluff version 0.7.0 onwards, the dbt templater has been moved
|
||||
to a seperate plugin and python package. You may find that projects
|
||||
already using the templater may initially fail after an upgrade to
|
||||
0.7.0+. See install instructions below to install the dbt templater.
|
||||
|
||||
dbt templating is still a relatively new feature added in 0.4.0 and
|
||||
is still in very active development! If you encounter an issue, please
|
||||
let us know in a GitHub issue or on the SQLFluff slack workspace.
|
||||
|
||||
dbt is not the default templater for *SQLFluff* (it is Jinja). For using
|
||||
@@ -326,8 +331,14 @@ A simple rule of thumb might be:
|
||||
of response may be more important, then the `jinja` templater may
|
||||
be more appropriate.
|
||||
|
||||
Installation & Configuration
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
In order to get started using *SQLFluff* with a dbt project you will
|
||||
need the following configuration:
|
||||
first need to install the :code:`sqlfluff-templater-dbt` package using
|
||||
your package manager of choice (e.g.
|
||||
:code:`pip install sqlfluff-templater-dbt`) and then will need the
|
||||
following configuration:
|
||||
|
||||
In *.sqlfluff*:
|
||||
|
||||
|
||||
7
plugins/sqlfluff-templater-dbt/README.md
Normal file
7
plugins/sqlfluff-templater-dbt/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# dbt plugin for SQLFluff
|
||||
|
||||
This plugin works with [SQLFluff](https://pypi.org/project/sqlfluff/), the
|
||||
SQL linter for humans, to correctly parse and compile SQL projects using
|
||||
[dbt](https://pypi.org/project/dbt/).
|
||||
|
||||
For more details on how to use this plugin, [see the documentation](https://docs.sqlfluff.com/en/stable/configuration.html#id1).
|
||||
@@ -1,39 +1,31 @@
|
||||
"""Setup file for example plugin."""
|
||||
from setuptools import find_packages, setup
|
||||
from os.path import dirname, join
|
||||
import configparser
|
||||
|
||||
|
||||
# Get the global config info as currently stated
|
||||
# (we use the config file to avoid actually loading any python here)
|
||||
config = configparser.ConfigParser()
|
||||
config.read(["src/sqlfluff/config.ini"])
|
||||
version = config.get("sqlfluff", "version")
|
||||
|
||||
|
||||
long_description = """
|
||||
# dbt plugin for SQLFluff
|
||||
|
||||
This plugin works with [SQLFluff](https://pypi.org/project/sqlfluff/), the
|
||||
SQL linter for humans, to correctly parse and compile SQL projects using
|
||||
[dbt](https://pypi.org/project/dbt/).
|
||||
"""
|
||||
def read(*names, **kwargs):
|
||||
"""Read a file and return the contents as a string."""
|
||||
return open(
|
||||
join(dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8")
|
||||
).read()
|
||||
|
||||
|
||||
setup(
|
||||
name="sqlfluff-templater-dbt",
|
||||
version=version,
|
||||
include_package_data=True,
|
||||
version="0.7.0a4",
|
||||
include_package_data=False,
|
||||
license="MIT License",
|
||||
description="Lint your dbt project SQL.",
|
||||
long_description=long_description,
|
||||
long_description=read("README.md"),
|
||||
# Make sure pypi is expecting markdown!
|
||||
long_description_content_type="text/markdown",
|
||||
package_dir={"": "src"},
|
||||
package_dir={"": join(dirname(__file__), "src")},
|
||||
packages=find_packages(where="src"),
|
||||
# Make sure sqlfluff is at least as updated at this plugin.
|
||||
# We might break this in the future, but for now while
|
||||
# the two are bundled, this makes sense given the release
|
||||
# cycles are coupled.
|
||||
install_requires=[f"sqlfluff>={version}", "dbt>=0.17"],
|
||||
install_requires=[f"sqlfluff>=0.7.0a2", "dbt>=0.17"],
|
||||
entry_points={"sqlfluff": ["sqlfluff_templater_dbt = sqlfluff_templater_dbt"]},
|
||||
)
|
||||
|
||||
@@ -226,7 +226,16 @@ def get_config(**kwargs) -> FluffConfig:
|
||||
sys.exit(66)
|
||||
# Instantiate a config object (filtering out the nulls)
|
||||
overrides = {k: kwargs[k] for k in kwargs if kwargs[k] is not None}
|
||||
return FluffConfig.from_root(overrides=overrides)
|
||||
try:
|
||||
return FluffConfig.from_root(overrides=overrides)
|
||||
except SQLFluffUserError as err:
|
||||
click.echo(
|
||||
colorize(
|
||||
f"Error loading config: {str(err)}",
|
||||
color=Color.red,
|
||||
)
|
||||
)
|
||||
sys.exit(66)
|
||||
|
||||
|
||||
def get_linter_and_formatter(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Config file for SQLFluff, mostly for version info for now
|
||||
[sqlfluff]
|
||||
version=0.7.0a2
|
||||
version=0.7.0a4
|
||||
stable_version=0.6.9
|
||||
|
||||
@@ -9,6 +9,7 @@ from itertools import chain
|
||||
from typing import Dict, List, Tuple, Any, Optional, Union, Iterable
|
||||
from pathlib import Path
|
||||
from sqlfluff.core.plugin.host import get_plugin_manager
|
||||
from sqlfluff.core.errors import SQLFluffUserError
|
||||
|
||||
import appdirs
|
||||
|
||||
@@ -538,7 +539,7 @@ class FluffConfig:
|
||||
"Starting in sqlfluff version 0.7.0 the dbt templater is distributed as a "
|
||||
"seperate python package. Please pip install sqlfluff-templater-dbt to use it."
|
||||
)
|
||||
raise ValueError(
|
||||
raise SQLFluffUserError(
|
||||
"Requested templater {!r} which is not currently available. Try one of {}".format(
|
||||
templater_name, ", ".join(templater_lookup.keys())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user