Skip to content

Commit

Permalink
additional updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Apr 21, 2024
1 parent 84f85f9 commit 5433278
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/config/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ They are, in order of parsing / precidence (last location wins):
- GitHub Action arguments
- Environment variables
- Command-line flags (CLI)
- Rich-codex config files
- Rich-codex config files (`.rich-codex.yml`)
- Per-image:
- Rich-codex config files
- Rich-codex config files (`.rich-codex.yml`)
- Markdown config

<!-- prettier-ignore-end -->
Expand Down
75 changes: 75 additions & 0 deletions docs/inputs/config_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,78 @@ outputs:
There are many other config keys also available.
See the [configuration docs](../config/overview.md) for more details.
### Install IDE Validation
You can validate your `.rich-codex.yml` files in your IDEs using JSONSchema.

#### VSCode

1. Install the [VSCode-YAML extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml)

2. In your repo, create a `.vscode/settings.jsonc` or `.vscode/settings.template.jsonc` file containing the following data. This is what tells the extension which schema to associate with each file.

```json
{
"yaml.schemas": {
"https://raw.githubusercontent.com/ewels/rich-codex/main/src/rich_codex/config-schema.yml": [
".rich-codex.yml",
".rich-codex.yaml"
]
}
}
```

3. To prompt other users to install the YAML extension, create a `.vscode/extensions.json` file containing the following data inside your repo:

```json
{
"recommendations": ["redhat.vscode-yaml"]
}
```

#### JetBrains (PyCharm, IntelliJ, etc.)

There are two ways to set this up.

You can either add the following data to your `.idea/jsonSchemas.xml`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JsonSchemaMappingsProjectConfiguration">
<state>
<map>
<entry key="rich_codex">
<value>
<SchemaInfo>
<option name="generatedName" value="New Schema" />
<option name="name" value="rich-codex" />
<option name="relativePathToSchema" value="https://raw.githubusercontent.com/ewels/rich-codex/main/src/rich_codex/config-schema.yml" />
<option name="patterns">
<list>
<Item>
<option name="path" value=".rich-codex.yml" />
</Item>
<Item>
<option name="path" value=".rich-codex.yaml" />
</Item>
</list>
</option>
</SchemaInfo>
</value>
</entry>
</map>
</state>
</component>
</project>
```

Or you can do this manually in **Preferences > Languages & Frameworks > Schemas and DTDs > Json Schema Mappings**:

- **Name**: `rich-codex`
- **Schema File or URL**: `https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_project.json`
- **Schema Version:** JSON schema version 4
- **Mappings**:
- `.rich-codex.yml`
- `.rich-codex.yaml`
12 changes: 11 additions & 1 deletion src/rich_codex/codex_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
no_confirm,
snippet_syntax,
timeout,
working_dir,
before_command,
after_command,
hide_command,
Expand All @@ -53,12 +54,20 @@ def __init__(
self.search_exclude = ["**/.git*", "**/.git*/**", "**/node_modules/**"]
if search_exclude is not None:
self.search_exclude.extend(self._clean_list(search_exclude.splitlines()))
self.configs = [".rich-codex.yml", ".github/rich-codex.yml", "docs/img/rich-codex.yml"]
self.configs = [
".rich-codex.yml",
".rich-codex.yaml",
".github/rich-codex.yml",
".github/rich-codex.yaml",
"docs/img/rich-codex.yml",
"docs/img/rich-codex.yaml",
]
if configs is not None:
self.configs.extend(self._clean_list(configs.splitlines()))
self.no_confirm = no_confirm
self.snippet_syntax = snippet_syntax
self.timeout = timeout
self.working_dir = working_dir
self.before_command = before_command
self.after_command = after_command
self.hide_command = hide_command
Expand All @@ -83,6 +92,7 @@ def __init__(
self.class_config_attrs = [
"snippet_syntax",
"timeout",
"working_dir",
"before_command",
"after_command",
"hide_command",
Expand Down
7 changes: 5 additions & 2 deletions src/rich_codex/config-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ properties:
# Shared config options
snippet_syntax: { "$ref": "#/$defs/snippet_syntax" }
timeout: { "$ref": "#/$defs/timeout" }
working_dir: { "$ref": "#/$defs/working_dir" }
before_command: { "$ref": "#/$defs/before_command" }
after_command: { "$ref": "#/$defs/after_command" }
hide_command: { "$ref": "#/$defs/hide_command" }
Expand Down Expand Up @@ -56,8 +57,6 @@ properties:
type: string
message:
required: Either command or snippet is required
working_dir:
title: Working directory to run command in
snippet:
title: Code snippet to use
type: string
Expand Down Expand Up @@ -89,6 +88,7 @@ properties:
# Shared config options
snippet_syntax: { "$ref": "#/$defs/snippet_syntax" }
timeout: { "$ref": "#/$defs/timeout" }
working_dir: { "$ref": "#/$defs/working_dir" }
before_command: { "$ref": "#/$defs/before_command" }
after_command: { "$ref": "#/$defs/after_command" }
hide_command: { "$ref": "#/$defs/hide_command" }
Expand All @@ -114,6 +114,9 @@ properties:
timeout:
title: Maximum run time for command (seconds)
type: integer
working_dir:
title: Working directory to run command in
type: string
before_command:
title: Setup commands to run before running main output command
type: string
Expand Down
10 changes: 10 additions & 0 deletions src/rich_codex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def check_git_status():
return (True, "Git repo looks good.")


def clean_list(unclean_lines):
"""Remove empty strings from a list."""
clean_lines = []
for line in unclean_lines:
line = line.strip()
if not line.startswith("#") and line:
clean_lines.append(line)
return clean_lines


def validate_config(schema, config, filename, line_number=None):
"""Validate a config file string against the rich-codex JSON schema."""
ln_text = f"line {line_number} " if line_number else ""
Expand Down

0 comments on commit 5433278

Please sign in to comment.