-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Setup project #1
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: publish to PyPI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*.*.*" | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: lint | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| just-trigger: [ format, lint, mypy ] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: extractions/setup-just@v2 | ||
| - uses: astral-sh/setup-uv@v4 | ||
|
|
||
| - run: uv python install 3.12 | ||
| - run: uv sync --all-extras --dev | ||
| - run: just ${{ matrix.just-trigger }} | ||
|
|
||
| tests: | ||
| name: tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: extractions/setup-just@v2 | ||
| - uses: astral-sh/setup-uv@v4 | ||
|
|
||
| - run: uv python install 3.12 | ||
| - run: uv sync --all-extras --dev | ||
|
|
||
| - name: Run tests | ||
| run: just tests | ||
|
|
||
| publish: | ||
| name: publish to PyPI | ||
| runs-on: ubuntu-latest | ||
| needs: [ lint, tests ] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: astral-sh/setup-uv@v4 | ||
| - run: uv python install 3.12 | ||
| - run: uv sync --all-extras --dev | ||
|
|
||
| - name: Build package | ||
| run: uv build | ||
|
|
||
| - name: Publish to PyPI | ||
| run: uv publish | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
| push: | ||
| branches: [ main ] | ||
| tags: | ||
| - "v*.*.*" | ||
|
|
||
| jobs: | ||
| linters: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| just-trigger: [ format, lint, mypy ] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: extractions/setup-just@v2 | ||
| - uses: astral-sh/setup-uv@v4 | ||
| - run: uv python install 3.12 | ||
| - run: uv sync --all-extras --dev | ||
| - run: just ${{ matrix.just-trigger }} | ||
|
|
||
| tests: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: [ "3.10", "3.11", "3.12", "3.13" ] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: extractions/setup-just@v2 | ||
| - uses: astral-sh/setup-uv@v4 | ||
|
|
||
| - run: uv python install ${{ matrix.python-version }} | ||
| - run: uv sync --all-extras --dev | ||
|
|
||
| - name: Run tests | ||
| run: just tests | ||
|
|
||
| - name: Upload coverage to Coveralls | ||
| if: matrix.python-version == '3.12' | ||
| uses: coverallsapp/github-action@v2 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| path-to-lcov: tests.lcov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| SOURCE_PATH := "def_form" | ||
| TESTS_PATH := "tests" | ||
|
|
||
| upgrade: | ||
| uv lock --upgrade | ||
|
|
||
| format: | ||
| uv run ruff format {{ SOURCE_PATH }} | ||
|
|
||
| lint: | ||
| uv run ruff check {{ SOURCE_PATH }} | ||
|
|
||
| mypy: | ||
| uv run python -m mypy --pretty {{ SOURCE_PATH }} | ||
|
|
||
| fix: | ||
| uv run ruff check --fix --unsafe-fixes {{ SOURCE_PATH }} | ||
|
|
||
| tests: | ||
| uv run pytest \ | ||
| --cov=def_form \ | ||
| --cov-report=lcov:tests.lcov \ | ||
| tests/ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 TopNik073 | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,84 @@ | ||
| # def-form | ||
| # def-form | ||
|
|
||
| Python function definition formatter | ||
|
|
||
| [](https://github.com/astral-sh/ruff) | ||
| [](https://pypi.python.org/pypi/def-form) | ||
| [](https://pypi.python.org/pypi/def-form) | ||
| [](https://coveralls.io/github/TopNik073/def-form?branch=init) | ||
| ## Overview | ||
|
|
||
| `def-form` is a code formatting tool that focuses specifically on Python function definitions. It helps maintain consistent formatting of function signatures by automatically organizing arguments vertically when they exceed specified thresholds. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Automatic argument formatting**: Converts inline function arguments to vertical format based on configurable rules | ||
| - **CI/CD integration**: Provides both `format` and `check` commands for use in development pipelines | ||
| - **Configuration file support**: Uses `pyproject.toml` for project-specific settings | ||
| - **Customizable thresholds**: Control when arguments should be formatted vertically | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install def-form | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Format code | ||
|
|
||
| * Format all Python files in a directory: | ||
|
|
||
| ```bash | ||
| def-form format src/ | ||
| ``` | ||
|
|
||
| * Format a specific file: | ||
|
|
||
| ```bash | ||
| def-form format my_module.py | ||
| ``` | ||
|
|
||
| ### Check code without formatting | ||
|
|
||
| * Check if code follows formatting rules: | ||
|
|
||
| ```bash | ||
| def-form check src/ | ||
| ``` | ||
|
|
||
| ### Command line options | ||
|
|
||
| ```text | ||
| def-form format [OPTIONS] [PATH] | ||
|
|
||
| Options: | ||
| --max-def-length INTEGER Maximum length of function definition | ||
| --max-inline-args INTEGER Maximum number of inline arguments | ||
| --indent-size INTEGER indent size in spaces (default: 4) | ||
| --exclude TEXT Paths or files to exclude from checking/formatting | ||
| --show-skipped Show skipped files/directories | ||
| --config TEXT Path to pyproject.toml configuration file | ||
| ``` | ||
|
|
||
| ### Configuration | ||
|
|
||
| Create a pyproject.toml file in your project root: | ||
|
|
||
| ```toml | ||
| [tool.def-form] | ||
| max_def_length = 100 | ||
| max_inline_args = 2 | ||
| indent_size = 4 | ||
| exclude = [ | ||
| '.venv', | ||
| 'migrations' | ||
| ] | ||
| ``` | ||
|
|
||
| ### Configuration options | ||
|
|
||
| * max_def_length: Maximum allowed characters in a single-line function definition | ||
| * max_inline_args: Maximum number of arguments allowed in inline format | ||
| * indent_size: Indent for arguments in spaces | ||
| * exclude: Files or directories you want to exclude |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import sys | ||
|
|
||
| import click | ||
|
|
||
| from def_form.exceptions.base import BaseDefFormException | ||
| from def_form.formatters import DefManager | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.argument('path', type=str, default='src') | ||
| @click.option('--max-def-length', type=int, default=None, help='max length of your function definition') | ||
| @click.option('--max-inline-args', type=int, default=None, help='max number of inline arguments') | ||
| @click.option('--indent-size', type=int, default=None, help='indent size in spaces (default: 4)') | ||
| @click.option('--config', type=str, default=None, help='path to pyproject.toml') | ||
| @click.option('--exclude', multiple=True, help='paths to exclude from formatting') | ||
| @click.option('--show-skipped', is_flag=True, help='show skipped files/directories') | ||
| def format( # noqa: PLR0913 | ||
| path: str, | ||
| max_def_length: int | None, | ||
| max_inline_args: int | None, | ||
| indent_size: int | None, | ||
| config: str | None, | ||
| exclude: tuple[str, ...], | ||
| show_skipped: bool, | ||
| ) -> None: | ||
| click.echo('Start formatting your code') | ||
| try: | ||
| DefManager( | ||
| path=path, | ||
| excluded=exclude, | ||
| max_def_length=max_def_length, | ||
| max_inline_args=max_inline_args, | ||
| indent_size=indent_size, | ||
| config=config, | ||
| show_skipped=show_skipped, | ||
| ).format() | ||
| except Exception as e: | ||
| click.echo(f'Something went wrong: {e}', err=True) | ||
| sys.exit(1) | ||
| else: | ||
| click.echo('Formatted!') | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.argument('path', type=str, default='src') | ||
| @click.option('--max-def-length', type=int, default=None, help='max length of your function definition') | ||
| @click.option('--max-inline-args', type=int, default=None, help='max number of inline arguments') | ||
| @click.option('--indent-size', type=int, default=None, help='indent size in spaces (default: 4)') | ||
| @click.option('--config', type=str, default=None, help='path to pyproject.toml') | ||
| @click.option('--exclude', multiple=True, help='paths to exclude from checking') | ||
| @click.option('--show-skipped', is_flag=True, help='show skipped files/directories') | ||
| def check( # noqa: PLR0913 | ||
| path: str, | ||
| max_def_length: int | None, | ||
| max_inline_args: int | None, | ||
| indent_size: int | None, | ||
| config: str | None, | ||
| exclude: tuple[str, ...], | ||
| show_skipped: bool, | ||
| ) -> None: | ||
| click.echo('Start checking your code') | ||
| try: | ||
| DefManager( | ||
| path=path, | ||
| excluded=exclude, | ||
| max_def_length=max_def_length, | ||
| max_inline_args=max_inline_args, | ||
| indent_size=indent_size, | ||
| config=config, | ||
| show_skipped=show_skipped, | ||
| ).check() | ||
| except BaseDefFormException: | ||
| sys.exit(1) | ||
| except Exception as e: | ||
| click.echo(f'Something went wrong: {e}', err=True) | ||
| sys.exit(1) | ||
| else: | ||
| click.echo('All checks passed!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import click | ||
|
|
||
| from def_form.cli.cli import check | ||
| from def_form.cli.cli import format | ||
|
|
||
|
|
||
| @click.group(name='def-form') | ||
| def main() -> None: | ||
| click.help_option() | ||
|
|
||
|
|
||
| main.add_command(format) | ||
| main.add_command(check) | ||
|
|
||
| if __name__ == '__main__': | ||
| main() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass | ||
| class BaseDefFormException(Exception): | ||
| path: str | None = None | ||
| message: str | None = None | ||
| description: str | None = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from def_form.exceptions.base import BaseDefFormException | ||
|
|
||
|
|
||
| @dataclass | ||
| class BaseDefFormatterException(BaseDefFormException): | ||
| path: str | ||
| message: str | ||
| description: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class DefStringTooLongException(BaseDefFormException): | ||
| path: str | ||
| message: str = 'String is too long' | ||
| description: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class TooManyInlineArgumentsException(BaseDefFormException): | ||
| path: str | ||
| message: str = 'Too many inline arguments' | ||
| description: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class InvalidMultilineParamsIndentException(BaseDefFormException): | ||
| path: str | ||
| message: str = 'Invalid multiline params indentation' | ||
| description: str | None = None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.