Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: accept a regular GitHub URL as a style #361

Merged
merged 19 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ with at least one Python (``.py``) file::
flake8 .

Nitpick will download and use the opinionated `default style
file <https://raw.githubusercontent.com/andreoliwa/nitpick/v0.26.0/nitpick-style.toml>`__.
file <https://github.com/andreoliwa/nitpick/blob/v0.26.0/nitpick-style.toml>`__.

You can use it as a template to configure your own style.

Expand Down
13 changes: 6 additions & 7 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Main options
-p, --project DIRECTORY Path to project root
--offline Offline mode: no style will be downloaded (no HTTP
requests at all)

--help Show this message and exit.

Commands:
Expand Down Expand Up @@ -73,7 +72,7 @@ At the end of execution, this command displays:
You can use partial and multiple file names in the FILES argument.

Options:
-v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG)
-v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG) [x>=0]
--help Show this message and exit.

.. _cli_cmd_check:
Expand All @@ -89,11 +88,11 @@ At the end of execution, this command displays:
Don't modify files, just print the differences.

Return code 0 means nothing would change. Return code 1 means some files
would be modified. You can use partial and multiple file names in the
FILES argument.
would be modified. You can use partial and multiple file names in the FILES
argument.

Options:
-v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG)
-v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG) [x>=0]
--help Show this message and exit.

.. _cli_cmd_ls:
Expand All @@ -108,8 +107,8 @@ At the end of execution, this command displays:

List of files configured in the Nitpick style.

Display existing files in green and absent files in red. You can use
partial and multiple file names in the FILES argument.
Display existing files in green and absent files in red. You can use partial
and multiple file names in the FILES argument.

Options:
--help Show this message and exit.
Expand Down
42 changes: 41 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,47 @@ You can set ``style`` with any local file or URL.
Remote style
------------

Use the URL of the remote file. If it's hosted on GitHub, use the raw GitHub URL:
Use the URL of the remote file.

If it's hosted on GitHub, use any of the following formats:

GitHub URL scheme (``github://`` or ``gh://``) pinned to a specific version:

.. code-block:: toml

[tool.nitpick]
style = "github://andreoliwa/nitpick@v0.26.0/nitpick-style.toml"
# or
style = "gh://andreoliwa/nitpick@v0.26.0/nitpick-style.toml"

The ``@`` syntax is used to get a Git reference (commit, tag, branch).
It is similar to the syntax used by ``pip`` and ``pipx``:

- `pip install - VCS Support - Git <https://pip.pypa.io/en/stable/cli/pip_install/?highlight=git#git>`_;
- `pypa/pipx: Installing from Source Control <https://pypa.github.io/pipx/#installing-from-source-control>`_.

If no Git reference is provided, the default GitHub branch will be used (for Nitpick, it's ``develop``):

.. code-block:: toml

[tool.nitpick]
style = "github://andreoliwa/nitpick/nitpick-style.toml"
# or
style = "gh://andreoliwa/nitpick/nitpick-style.toml"

# It has the same effect as providing the default branch explicitly:
style = "github://andreoliwa/nitpick@develop/nitpick-style.toml"
# or
style = "gh://andreoliwa/nitpick@develop/nitpick-style.toml"

A regular GitHub URL also works. The corresponding raw URL will be used.

.. code-block:: toml

[tool.nitpick]
style = "https://github.com/andreoliwa/nitpick/blob/v0.26.0/nitpick-style.toml"

Or use the raw GitHub URL directly:

.. code-block:: toml

Expand Down
4 changes: 2 additions & 2 deletions docs/flake8_plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ This in intentional, because `Nitpick is not a conventional flake8 plugin <flake
Since flake8 only lints Python files, the pre-commit hook will only run when a Python file is modified.
It won't run when a config/text changes.

An example: suppose you're using a remote Nitpick style (`like the style from WeMake <https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/nitpick-style.toml>`_).
An example: suppose you're using a remote Nitpick style (`like the style from WeMake <https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/nitpick-style.toml>`_).

At the moment, their style currently checks ``setup.cfg`` only.

Suppose they change or add an option on their `isort.toml <https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/isort.toml>`_ file.
Suppose they change or add an option on their `isort.toml <https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/isort.toml>`_ file.

If the nitpick pre-commit hook had ``always_run: false`` and ``pass_filenames: true``, your local ``setup.cfg`` would only be verified:

Expand Down
10 changes: 5 additions & 5 deletions docs/generate_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
from slugify import slugify
from sortedcontainers import SortedDict

from nitpick import __version__
from nitpick import PROJECT_NAME, __version__
from nitpick.constants import (
CONFIG_FILES,
EDITOR_CONFIG,
GITHUB_BASE_URL,
PACKAGE_JSON,
PRE_COMMIT_CONFIG_YAML,
PROJECT_OWNER,
PYLINTRC,
PYPROJECT_TOML,
READ_THE_DOCS_URL,
SETUP_CFG,
)
from nitpick.core import Nitpick
from nitpick.style.fetchers.github import GitHubURL

RST_DIVIDER_FROM_HERE = ".. auto-generated-from-here"
RST_DIVIDER_START = ".. auto-generated-start-{}"
Expand Down Expand Up @@ -221,7 +222,7 @@ def write_examples() -> int:
{header}
{dashes}

Contents of `{toml_file} <{base_url}v{version}/{toml_file}>`_:
Contents of `{toml_file} <{url}>`_:

.. code-block::{language}

Expand All @@ -245,8 +246,7 @@ def write_examples() -> int:
header=header,
dashes="-" * len(header),
toml_file=base_name,
base_url=GITHUB_BASE_URL,
version=__version__,
url=GitHubURL(PROJECT_OWNER, PROJECT_NAME, f"v{__version__}", base_name).url,
# Skip TOML with JSON inside, to avoid this error message:
# nitpick/docs/examples.rst:193: WARNING: Could not lex literal_block as "toml". Highlighting skipped.
language="" if "contains_json" in toml_content else " toml",
Expand Down
3 changes: 2 additions & 1 deletion docs/ideas/toml.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pep257 = "{{ nit.absent() }}" # Jinja
pycodestyle = "{{ nit.absent() }}" # Jinja
pur = "{{ nit.absent() }}" # Jinja

# TODO: pre-processing with Jinja to generate multiple sections with the same config? ["pyproject.toml".tool.poetry.{{ ['dependencies', 'dev-dependencies'] }}]
# Pre-processing with Jinja to generate multiple sections with the same config? ["pyproject.toml".tool.poetry.{{ ['dependencies', 'dev-dependencies'] }}]
# https://github.com/andreoliwa/nitpick/issues/283

# Keys are present, with the expected types
["pyproject.toml".build-system]
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Enforce config on TOML files.
E.g.: `pyproject.toml (PEP 518) <https://www.python.org/dev/peps/pep-0518/#file-format>`_.

See also `the [tool.poetry] section of the pyproject.toml file
<https://github.com/python-poetry/poetry/blob/master/docs/docs/pyproject.md>`_.
<https://github.com/python-poetry/poetry/blob/master/docs/pyproject.md>`_.

Style example: :ref:`Python 3.8 version constraint <example-python-3-8>`.
There are :ref:`many other examples here <examples>`.
2 changes: 1 addition & 1 deletion nitpick-style.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default style file for nitpick
# https://raw.githubusercontent.com/andreoliwa/nitpick/v0.26.0/nitpick-style.toml
# https://github.com/andreoliwa/nitpick/blob/v0.26.0/nitpick-style.toml

[nitpick]
minimum_version = "0.10.0"
Expand Down
Loading