Skip to content

Commit

Permalink
Merge pull request #2 from carstencodes:bugs/list-values-have-wrong-f…
Browse files Browse the repository at this point in the history
…ormat

Fixing configuration of list values
  • Loading branch information
carstencodes authored Sep 1, 2021
2 parents 1a1e4f0 + 7ce8e34 commit 4f23e83
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Create release

on:
push:
tags:
- 'v*'

jobs:
changelog:
name: Generate changelog
runs-on: ubuntu-latest
outputs:
changelog: ${{ steps.changelog.outputs.changelog }}
steps:
- name: Generate changelog
id: changelog
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
deploy:
name: Deploy wheel to pypi
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine pdm
pdm install -G:all
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
pdm build
twine upload dist/*
release:
name: Create Release
runs-on: ubuntu-latest
needs: [ changelog, deploy ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get tag name
uses: battila7/get-version-action@v2
id: tag_name
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
changelog: ${{ needs.changelog.outputs.changelog }}
branch: ${{ steps.tag_name.outputs.version }}
with:
tag_name: ${{ steps.tag_name.outputs.version }}
release_name: Release ${{ steps.tag_name.outputs.version }}
body: ${{ needs.changelog.outputs.changelog }}
draft: false
prerelease: ${{ (startsWith(steps.tag_name.outputs.version, 'v0')) || (endsWith(steps.tag_name.outputs.version, '-pre')) || (endsWith(steps.tag_name.outputs.version, '-dev')) }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "flake518"
version = "1.0.0"
version = "1.1.0"
description = "A small wrapper around flake8 to support PEP518 pyproject.toml as configuration file."
authors = [
{name = "Carsten Igel", email = "[email protected]"},
Expand Down
4 changes: 1 addition & 3 deletions src/flake518/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@
from .adapter import run as run_flake518


__all__ = [
'run_flake518'
]
__all__ = ["run_flake518"]
33 changes: 29 additions & 4 deletions src/flake518/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,35 @@ def read_pyproject_toml(py_project_toml: Path) -> dict:

# Captions have been lost after merging. Add generic flake8 section
if len(result) > 0:
result = {'flake8': result}
result = {"flake8": result}

return result


def update_configuration(config: dict) -> None:
"""Update configuration to match a correct ini file format.
Args:
config (dict): The configuration to modify
"""
for _, scoped_config in config.items():
if not isinstance(scoped_config, dict):
raise ValueError(
"Second level configuration element must be a dictionary"
)

for key, value in scoped_config.items():
if isinstance(value, dict):
raise ValueError("Cannot nest dictionary in ini-file")
if isinstance(value, list):
logger.debug(
"Changing a configuration value from list to str: %s",
value,
)
value = ", ".join(value)
scoped_config[key] = value


def write_config_to_ini(config: dict, ini: TextIO) -> None:
"""Write the configuration dictionary to the specified file.
Expand Down Expand Up @@ -197,8 +221,9 @@ def run(argv: Optional[_List[str]] = None) -> None:
"Found entries in %s. Adding additional configuration...",
py_project,
)
update_configuration(config)
with NamedTemporaryFile(
"w+t", prefix="flake518_", suffix=".cfg", delete=True
"w+t", prefix="flake518_", suffix=".cfg", delete=True
) as handle:
write_config_to_ini(config, handle)
logger.debug(
Expand All @@ -207,8 +232,8 @@ def run(argv: Optional[_List[str]] = None) -> None:
handle.name,
)
handle.flush()
args.append('--config')
args.append('{}'.format(handle.name))
args.append("--config")
args.append("{}".format(handle.name))
logger.debug("The following arguments are applied now: %s", args)
run_flake8(args)

Expand Down

0 comments on commit 4f23e83

Please sign in to comment.