Skip to content

Commit

Permalink
Modify pyta-template-file config path resolution (#1140)
Browse files Browse the repository at this point in the history
Absolute paths are now supported. Relative paths are resolved relative to the current working directory.
  • Loading branch information
DanielDervishi authored Feb 9, 2025
1 parent 061d852 commit 16face6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### ✨ Enhancements

- Added custom error message for `comparison-with-callable`
- Changed `pyta-template-file` argument to now resolve the file path relative to the CWD.
- Added a watch configuration option to the HTML reporter for persistent server mode.
- Added `server-port` configuration option to specify the port number to use when serving the PyTA HTML report.
- Added new checker option `mypy-options` in `static-type-checker` to let users override default mypy command-line arguments
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Simon Chen,
Freeman Cheng,
Ivan Chepelev,
Yianni Culmone,
Daniel Dervishi,
Nigel Fong,
Adam Gleizer,
Ibrahim Hasan,
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ The maximum number of occurrences of each check to report.
This option can be used to limit the size of the output report.
If set to 0 (the default), all occurrences are shown.

### `pyta-template-file` (default: `"template.html.jinja"`)
### `pyta-template-file` (default: Path to PythonTA's `template.html.jinja`)

HTML template file for the HTMLReporter.
Path to HTML template file for the HTMLReporter.

### `allow-pylint-comments` (default: `false`)

Expand Down
3 changes: 2 additions & 1 deletion python_ta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def reset_linter(
- If the config argument is a dictionary, apply those options afterward.
Do not re-use a linter object. Returns a new linter.
"""

# Tuple of custom options. Note: 'type' must map to a value equal a key in the pylint/config/option.py `VALIDATORS` dict.
new_checker_options = (
(
Expand Down Expand Up @@ -314,7 +315,7 @@ def reset_linter(
(
"pyta-template-file",
{
"default": "template.html.jinja",
"default": "",
"type": "string",
"metavar": "<pyta_reporter>",
"help": "HTML template file for the HTMLReporter.",
Expand Down
5 changes: 3 additions & 2 deletions python_ta/config/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pyta-number-of-messages = 0
# (DEPRECATED: Use output-format option below.) Set the [REPORTS] output-format option instead.
# pyta-reporter = HTMLReporter

# Set the location of the template for HTMLReporter.
pyta-template-file = template.html.jinja
# Set the path of the template for HTMLReporter. Ex:
# pyta-template-file = ../../templates/template.html.jinja
# pyta-template-file = /Users/user/pyta/python_ta/reporters/templates/template.html.jinja

#Set whether you wish to opt-in to anonymous data collection of errors reported when you run PyTA.
pyta-error-permission = no
Expand Down
10 changes: 9 additions & 1 deletion python_ta/reporters/html_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ def display_messages(self, layout: BaseLayout) -> None:
grouped_messages = {path: self.group_messages(msgs) for path, msgs in self.messages.items()}

template_f = self.linter.config.pyta_template_file
template = Environment(loader=FileSystemLoader(TEMPLATES_DIR)).get_template(template_f)
template_f = (
template_f if template_f != "" else os.path.join(TEMPLATES_DIR, "template.html.jinja")
)
path = os.path.abspath(template_f)
filename, file_parent_directory = os.path.basename(path), os.path.dirname(path)

template = Environment(loader=FileSystemLoader(file_parent_directory)).get_template(
filename
)

# Embed resources so the output html can go anywhere, independent of assets.
# with open(os.path.join(TEMPLATES_DIR, 'pyta_logo_markdown.png'), 'rb+') as image_file:
Expand Down
5 changes: 3 additions & 2 deletions tests/test.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pyta-number-of-messages = 0
# (DEPRECATED: Use output-format option below.) Set the [REPORTS] output-format option instead.
# pyta-reporter = HTMLReporter

# Set the location of the template for HTMLReporter.
pyta-template-file = template.html.jinja
# Set the path of the template for HTMLReporter. Ex:
# pyta-template-file = ../../templates/template.html.jinja
# pyta-template-file = /Users/user/pyta/python_ta/reporters/templates/template.html.jinja

#Set whether you wish to opt-in to anonymous data collection of errors reported when you run PyTA.
pyta-error-permission = no
Expand Down

0 comments on commit 16face6

Please sign in to comment.