### Install Development Dependencies Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Installs all project dependencies, including those for development, using uv. ```shell pre-commit install uv sync --all-groups ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Starts a local development server to preview the documentation site using mkdocs. ```shell uv run mkdocs serve ``` -------------------------------- ### Example pyproject.toml Configuration Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/configuration.md This TOML snippet shows a comprehensive example of configuring dbt-score, including rule namespaces, disabled rules, failure thresholds, badge settings, and specific rule configurations. ```toml [tool.dbt-score] rule_namespaces = ["dbt_score.rules", "dbt_score_rules", "custom_rules"] disabled_rules = ["dbt_score.rules.generic.columns_have_description"] inject_cwd_in_python_path = true fail_project_under = 7.5 fail_any_item_under = 8.0 [tool.dbt-score.badges] first.threshold = 10.0 first.icon = "🥇" second.threshold = 8.0 second.icon = "🥈" third.threshold = 6.0 third.icon = "🥉" wip.icon = "🏗️" [tool.dbt-score.rules."dbt_score.rules.generic.sql_has_reasonable_number_of_lines"] severity = 1 max_lines = 300 ``` -------------------------------- ### Get general help for dbt-score Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --help flag to display general help information for the dbt-score command-line tool. ```shell dbt-score --help ``` -------------------------------- ### Install dbt-score Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Install the dbt-score library using pip. Ensure it's in the same environment as dbt-core for full functionality. ```shell pip install dbt-score ``` -------------------------------- ### Create a Source Rule by Inheriting from Rule Class Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md This example demonstrates creating a rule for dbt sources by inheriting from the `Rule` class. It defines the rule's description and implements the `evaluate` method to check for the presence of a description. ```python class SourceHasDescription(Rule): description = "A source should have a description." def evaluate(self, source: Source) -> RuleViolation | None: """Evaluate the rule.""" if not source.description: return RuleViolation(message="Source lacks a description.") ``` -------------------------------- ### Rule Filter Configuration Example Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/configuration.md This TOML snippet demonstrates how to configure a specific rule, 'dbt_score.rules.generic.has_example_sql', to apply only to models materializing as tables using 'rule_filter_names'. ```toml [tool.dbt-score.rules."dbt_score.rules.generic.has_example_sql"] rule_filter_names=["dbt_score.rules.filters.is_table"] ``` -------------------------------- ### Lint Project with JSON Output Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/programmatic_invocations.md Use the `--format json` flag to get machine-readable output for programmatic use. This output includes detailed scores, badges, and rule results for each model and the project overall. ```shell $ dbt-score lint --format json { "models": { "model1": { "score": 8.666666666666668, "badge": "🥈", "pass": true, "results": { "dbt_score.rules.generic.columns_have_description": { "result": "OK", "severity": "medium", "message": null }, "dbt_score.rules.generic.has_description": { "result": "OK", "severity": "medium", "message": null }, "dbt_score.rules.generic.has_owner": { "result": "WARN", "severity": "medium", "message": "Model lacks an owner." }, "dbt_score.rules.generic.has_example_sql": { "result": "OK", "severity": "low", "message": null }, "dbt_score.rules.generic.sql_has_reasonable_number_of_lines": { "result": "OK", "severity": "medium", "message": null } } } }, "project": { "score": 8.666666666666668, "badge": "🥈", "pass": true } } ``` -------------------------------- ### Get help for dbt-score lint command Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --help flag with the lint command to display specific help for linting options. ```shell dbt-score lint --help ``` -------------------------------- ### Selective Linting with dbt-score Source: https://github.com/picnicsupermarket/dbt-score/blob/master/README.md Use dbt's selection and exclusion syntax to lint specific parts of dbt projects. Examples include linting staging models, a model and its dependencies, recently changed models, or all models except experimental ones. ```bash # Lint only staging models dbt-score lint --select staging.* # Lint a model and its dependencies dbt-score lint --select +my_important_model # Lint recently changed models dbt-score lint --select state:modified # Lint all models except experimental ones dbt-score lint --exclude my_experimental_model+ ``` -------------------------------- ### Create a Source Rule with @rule Decorator Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md This example shows how to create a rule specifically for dbt sources, ensuring they have a description. It uses the same `@rule` decorator pattern as model rules. ```python from dbt_score import rule, RuleViolation, Source @rule def source_has_description(source: Source) -> RuleViolation | None: """A source should have a description.""" if not source.description: return RuleViolation(message="Source lacks a description.") ``` -------------------------------- ### Import Custom Rule Module in Python Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/package_rules.md Python import statement to verify if a custom rule module is accessible. If this fails, rules may not be installed correctly or are not on the Python path. ```python import dbt_score_rules.dbtviz ``` -------------------------------- ### Define a Custom dbt-score Rule Source: https://github.com/picnicsupermarket/dbt-score/blob/master/README.md Create organization-specific rules by writing Python functions. This example defines a rule to check if a dbt model has a 'business_owner' in its metadata. ```python from dbt_score import Model, rule, RuleViolation @rule def model_has_business_owner(model: Model) -> RuleViolation: if model.meta.get("business_owner") is None: return RuleViolation("Model lacks a business owner.") ``` -------------------------------- ### Apply Filters to a dbt-score Rule Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Integrate defined filters into a dbt-score rule using the `@rule` decorator. This example shows how to apply the `only_schema_x` filter to a rule that enforces naming standards for models within a specific schema. ```python from dbt_score import Model, rule, RuleViolation from my_project import only_schema_x @rule(rule_filters={only_schema_x()}) def models_in_x_follow_naming_standard(model: Model) -> RuleViolation | None: """Models in schema X must follow the naming standard.""" if some_regex_fails(model.name): return RuleViolation("Invalid model name.") ``` -------------------------------- ### Build Documentation Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Builds the static documentation site using mkdocs. ```shell uv run mkdocs build ``` -------------------------------- ### Specify manifest file for linting Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --manifest option to specify a custom path to the manifest.json file. ```shell dbt-score lint --manifest path/to/manifest.json ``` -------------------------------- ### Run dbt parse before linting Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --run-dbt-parse option to automatically generate the manifest.json file before linting. ```shell dbt-score lint --run-dbt-parse ``` -------------------------------- ### Run dbt-score Lint with All Tests Shown Source: https://github.com/picnicsupermarket/dbt-score/blob/master/README.md Run the linting command and include passing tests in the output. This provides a more comprehensive view of your dbt project's quality. ```bash dbt-score lint --show all ``` -------------------------------- ### Execute Pre-commit Hooks Manually Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Manually runs all pre-commit hooks on all files in the repository. ```shell pre-commit run --all-files ``` -------------------------------- ### dbt-score Command Line Help Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/configuration.md This bash command displays the help information for the 'dbt-score lint' command, showing available command-line configuration options. ```bash dbt-score lint --help ``` -------------------------------- ### Run Linting with Tox Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Executes the linting process across multiple Python environments using tox. ```shell uv run tox -e lint ``` -------------------------------- ### Project Structure for Custom Rules Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/package_rules.md Recommended project structure for bundling custom dbt-Score rules within a dbt project. Ensures rules are importable in the Python environment. ```text my-dbt-project/ ├─ dbt_score_rules/ │ ├─ my_project_rules.py ├─ dbt_project.yml ├─ models/ ├─ ... ``` -------------------------------- ### List All Discovered dbt-Score Rules Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/package_rules.md Command to list all rules discovered and configured by dbt-Score. Useful for verifying rule availability. ```shell dbt-score list ``` -------------------------------- ### Run dbt-score lint command Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Execute the basic linting command for your dbt project. By default, it looks for manifest.json in the dbt target directory. ```shell dbt-score lint ``` -------------------------------- ### Run Ruff Linter and Formatter Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Checks code for linting errors and applies automatic fixes using ruff. ```shell uv run ruff check . uv run ruff check --fix ``` -------------------------------- ### Lint dbt models with all rules shown Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/index.md This command lints dbt models and displays all rule violations, including passing ones, using the `--show all` flag. It shows the score and medal awarded to the model. ```bash > dbt-score lint --show all 🥇 M: customers (score: 10.0) OK dbt_score.rules.generic.has_description OK dbt_score.rules.generic.has_owner OK dbt_score.rules.generic.sql_has_reasonable_number_of_lines Score: 10.0 🥇 ``` -------------------------------- ### List dbt-Score Rules by Namespace Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/package_rules.md Command to filter and list dbt-Score rules within a specific namespace. Helps in debugging or managing custom rule sets. ```shell dbt-score list --namespace dbt_score_rules.dbtviz ``` -------------------------------- ### Combine select and exclude for linting Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Combine --select and --exclude arguments to precisely control which dbt entities are linted. ```shell dbt-score lint --select +my_model+ --exclude my_model+ ``` -------------------------------- ### Run Mypy Type Checker Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Performs static type checking on the project using mypy. ```shell uv run mypy . ``` -------------------------------- ### Create a Configurable Rule with @rule Decorator Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Define a rule that accepts configurable parameters, such as `max_lines`. The default value for the parameter can be set directly in the function signature and overridden in configuration files. ```python from dbt_score import Model, rule, RuleViolation @rule def sql_has_reasonable_number_of_lines(model: Model, max_lines: int = 200) -> RuleViolation | None: """The SQL query of a model should not be too long.""" count_lines = len(model.raw_code.split("\n")) if count_lines > max_lines: return RuleViolation( message=f"SQL query too long: {count_lines} lines (> {max_lines})." ) ``` -------------------------------- ### Run Pytest with Coverage Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Runs the test suite and generates a code coverage report using pytest and coverage. ```shell uv run coverage run -m pytest ``` -------------------------------- ### Create a Model Rule by Inheriting from Rule Class Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md For advanced use cases, create a rule by inheriting from the `Rule` class. This allows for maintaining state between evaluations and defining the rule's description as a class attribute. ```python from dbt_score import Model, Rule, RuleViolation, Source class ModelHasDescription(Rule): description = "A model should have a description." def evaluate(self, model: Model) -> RuleViolation | None: """Evaluate the rule.""" if not model.description: return RuleViolation(message="Model lacks a description.") ``` -------------------------------- ### dbt-score Configuration in pyproject.toml Source: https://github.com/picnicsupermarket/dbt-score/blob/master/README.md Configure dbt-score settings, including failure thresholds, disabled rules, and badge customization, within the pyproject.toml file. ```toml [tool.dbt-score] fail_project_under = 7.5 fail_any_item_under = 8.0 # Disable specific rules disabled_rules = ["dbt_score.rules.generic.columns_have_description"] # Configure badges [tool.dbt-score.badges] first.threshold = 10.0 first.icon = "🥇" second.threshold = 8.0 second.icon = "🥈" third.threshold = 6.0 third.icon = "🥉" wip.icon = "🏗️" # Customize rule severity and parameters [tool.dbt-score.rules."dbt_score.rules.generic.sql_has_reasonable_number_of_lines"] severity = 1 max_lines = 300 ``` -------------------------------- ### Run Pytest Tests Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Executes the test suite using pytest. ```shell uv run tox -e py uv run pytest ``` -------------------------------- ### Define Model Filters with Decorator and Class Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Create filters for models using the `@rule_filter` decorator or by subclassing `RuleFilter`. The decorator is for simple functions, while the class is for more complex logic or when a description is needed. ```python from dbt_score import Model, RuleFilter, rule_filter @rule_filter def only_schema_x(model: Model) -> bool: """Only applies a rule to schema X.""" return model.schema.lower() == 'x' class SkipSchemaY(RuleFilter): description = "Applies a rule to every schema but Y." def evaluate(self, model: Model) -> bool: return model.schema.lower() != 'y' ``` -------------------------------- ### Define Source Filters with Decorator and Class Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Create filters specifically for dbt sources using the `@rule_filter` decorator or by subclassing `RuleFilter`. These filters leverage type annotations to ensure they are applied correctly to source entities. ```python from dbt_score import RuleFilter, rule_filter, Source @rule_filter def only_from_source_a(source: Source) -> bool: """Only applies a rule to source tables from source X.""" return source.source_name.lower() == 'a' class SkipSourceDatabaseB(RuleFilter): description = "Applies a rule to every source except Database B." def evaluate(self, source: Source) -> bool: return source.database.lower() != 'b' ``` -------------------------------- ### Bypass Pre-commit Hooks During Commit Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/contributing.md Creates a git commit while skipping the pre-commit hooks. ```shell git commit --no-verify ``` -------------------------------- ### Enable Debug Mode for Rule Analysis Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Run dbt-score with the `--debug` flag to automatically launch a `pdb` debugger when an exception occurs during rule evaluation. This aids in investigating rule failures or developing new rules. ```shell dbt-score lint --debug # --debug and -d are equivalent ``` -------------------------------- ### Create a Model Rule with @rule Decorator Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/create_rules.md Define a rule to check if a dbt model has a description. The function name becomes the rule name, and the docstring is the rule description. The argument type annotation determines the dbt entity type. ```python from dbt_score import Model, rule, RuleViolation @rule def model_has_description(model: Model) -> RuleViolation | None: """A model should have a description.""" if not model.description: return RuleViolation(message="Model lacks a description.") ``` -------------------------------- ### Integrate dbt-score into CI Pipelines Source: https://github.com/picnicsupermarket/dbt-score/blob/master/README.md Add dbt-score to CI pipelines for automated quality checks. The command `dbt-score lint --run-dbt-parse` can be used, and the tool exits with 0 or 1 to signal success or failure. ```yaml - name: Run dbt-score run: | dbt-score lint --run-dbt-parse ``` -------------------------------- ### Lint specific dbt entities Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --select argument with dbt node selection syntax to lint only a subset of dbt entities. ```shell dbt-score lint --select +my_model+ ``` -------------------------------- ### Exclude specific dbt entities from linting Source: https://github.com/picnicsupermarket/dbt-score/blob/master/docs/get_started.md Use the --exclude argument with dbt node exclusion syntax to exclude specific dbt entities from linting. ```shell dbt-score lint --exclude my_model+ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.