Skip to content

Commit 234b31d

Browse files
github-actions[bot]Takishima
authored andcommitted
Fix GitHub workflows (#66)
* Fix GitHub workflows * Switch to only use ruff and ruff-format + update pre-commit hooks * Update CHANGELOG * Fix linter/formatter warnings
1 parent 250e447 commit 234b31d

22 files changed

+215
-150
lines changed

.github/workflows/publish_release.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name: "Publish new release"
44

5-
on:
5+
on: # yamllint disable-line rule:truthy
66
push:
77
tags:
88
- v[0-9]+.*
@@ -42,20 +42,25 @@ jobs:
4242
run: |
4343
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
4444
VERSION=${BRANCH_NAME#release/}
45+
VERSION=${VERSION#v}
4546
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
4647
4748
- name: Extract version from branch name (for hotfix branches)
4849
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/')
4950
run: |
5051
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
5152
VERSION=${BRANCH_NAME#hotfix/}
53+
VERSION=${VERSION#v}
5254
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
5355
56+
- name: Show short log (debug)
57+
run: git --no-pager log --oneline -n40
58+
5459
- name: Build wheel
5560
run: |
5661
if ! git rev-parse v${RELEASE_VERSION} > /dev/null 2>&1; then
5762
_added_tag=1
58-
git tag v${RELEASE_VERSION} main
63+
git tag v${RELEASE_VERSION}
5964
fi
6065
6166
python -m pip install build wheel
@@ -94,12 +99,12 @@ jobs:
9499
prerelease="--prerelease"
95100
fi
96101
gh release create "v${RELEASE_VERSION}" ${prerelease:-} \
97-
--title pylint-secure-coding-standard v${RELEASE_VERSION}" \
102+
--title "pylint-secure-coding-standard v${RELEASE_VERSION}" \
98103
--notes "${notes:-}" \
99104
dist/*
100105
101106
- name: Setup Python for Pypi upload
102-
uses: actions/setup-python@v3
107+
uses: actions/setup-python@v4
103108

104109
- name: Publish standard package
105110
uses: pypa/gh-action-pypi-publish@release/v1

.pre-commit-config.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ repos:
4848
hooks:
4949
- id: yamllint
5050

51-
- repo: https://github.com/psf/black
52-
rev: 23.11.0
53-
hooks:
54-
- id: black
55-
language_version: python3
56-
5751
- repo: https://github.com/asottile/blacken-docs
5852
rev: 1.16.0
5953
hooks:
@@ -62,7 +56,18 @@ repos:
6256
additional_dependencies: [black==23.3.0]
6357

6458
- repo: https://github.com/astral-sh/ruff-pre-commit
65-
rev: v0.1.7
59+
rev: v0.1.8
6660
hooks:
61+
- id: ruff-format
62+
name: ruff (format)
63+
args: [--preview]
64+
6765
- id: ruff
68-
args: [--fix, --exit-non-zero-on-fix, --show-source, --show-fixes]
66+
name: ruff (fix)
67+
alias: ruff-fix
68+
args:
69+
- --fix
70+
- --exit-non-zero-on-fix
71+
- --show-source
72+
- --show-fixes
73+
- --preview

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Configuration options retrieval on Pylint 3
13+
- GitHub workflows
1314

1415
### Repository
1516

16-
- Update `astral-sh/ruff-pre-commit` hook to v0.1.7
17+
- Update `adrienverge/yamllint` hook to v1.33.0
18+
- Update `astral-sh/ruff-pre-commit` hook to v0.1.8
1719

1820
## [v1.5.0] - 2023-11-19
1921

@@ -152,7 +154,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
152154

153155
Initial release
154156

155-
[unreleased]: https://github.com/Takishima/pylint-secure-coding-standard/compare/v1.5.0...HEAD
157+
[1.5.1]: https://github.com/Takishima/pylint-secure-coding-standard/compare/v1.5.0...1.5.1
158+
[unreleased]: https://github.com/Takishima/pylint-secure-coding-standard/compare/1.5.1...HEAD
156159
[v1.0.0]: https://github.com/Takishima/pylint-secure-coding-standard/compare/375145a3dec096ff4e33901ef749a1a9a6f4edc6...v1.0.0
157160
[v1.1.0]: https://github.com/Takishima/pylint-secure-coding-standard/compare/v1.0.0...v1.1.0
158161
[v1.2.0]: https://github.com/Takishima/pylint-secure-coding-standard/compare/v1.1.0...v1.2.0

pylint_secure_coding_standard.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ def _is_posix():
3232
"""Return True if the current system is POSIX-compatible."""
3333
# NB: we could simply use `os.name` instead of `platform.system()`. However, that solution would be difficult to
3434
# test using `mock` as a few modules (like `pytest`) actually use it internally...
35-
return platform.system() in ('Linux', 'Darwin')
35+
return platform.system() in {'Linux', 'Darwin'}
3636

3737

3838
_is_unix = _is_posix
3939

4040
# ==============================================================================
4141

4242

43-
def _read_octal_mode_option(name, value, default):
43+
def _read_octal_mode_option(name, value, default): # noqa: C901
4444
"""
4545
Read an integer or list of integer configuration option.
4646
@@ -78,23 +78,27 @@ def _str_to_int(arg):
7878
try:
7979
allowed_modes = [_str_to_int(mode) for mode in modes if mode]
8080
except ValueError as error:
81-
raise ValueError(f'Unable to convert {modes} elements to integers!') from error
81+
msg = f'Unable to convert {modes} elements to integers!'
82+
raise ValueError(msg) from error
8283
else:
8384
if not allowed_modes:
84-
raise ValueError(f'Calculated empty value for `{name}`!')
85+
msg = f'Calculated empty value for `{name}`!'
86+
raise ValueError(msg)
8587
return allowed_modes
8688
elif modes and modes[0]:
8789
# Single values (ie. max allowed value for mode)
8890
try:
8991
return _str_to_int(value)
9092
except ValueError as error:
91-
if value in ('y', 'yes', 'true'):
93+
if value in {'y', 'yes', 'true'}:
9294
return default
93-
if value in ('n', 'no', 'false'):
95+
if value in {'n', 'no', 'false'}:
9496
return None
95-
raise ValueError(f'Invalid value for `{name}`: {value}!') from error
97+
msg = f'Invalid value for `{name}`: {value}!'
98+
raise ValueError(msg) from error
9699
else:
97-
raise ValueError(f'Invalid value for `{name}`: {value}!')
100+
msg = f'Invalid value for `{name}`: {value}!'
101+
raise ValueError(msg)
98102

99103

100104
# ==============================================================================
@@ -126,7 +130,7 @@ def _is_os_path_call(node):
126130
and node.func.expr.expr.name == 'os'
127131
)
128132
)
129-
and node.func.attrname in ('abspath', 'relpath')
133+
and node.func.attrname in {'abspath', 'relpath'}
130134
)
131135

132136

@@ -183,8 +187,8 @@ def _is_shell_true_call(node):
183187
return False
184188

185189
# subprocess module
186-
if node.func.expr.name in ('subprocess', 'sp'):
187-
if node.func.attrname in ('call', 'check_call', 'check_output', 'Popen', 'run'):
190+
if node.func.expr.name in {'subprocess', 'sp'}:
191+
if node.func.attrname in {'call', 'check_call', 'check_output', 'Popen', 'run'}:
188192
if node.keywords:
189193
for keyword in node.keywords:
190194
if (
@@ -201,7 +205,7 @@ def _is_shell_true_call(node):
201205
):
202206
return True
203207

204-
if node.func.attrname in ('getoutput', 'getstatusoutput'):
208+
if node.func.attrname in {'getoutput', 'getstatusoutput'}:
205209
return True
206210

207211
# asyncio module
@@ -249,7 +253,7 @@ def _is_yaml_unsafe_call(node):
249253
and isinstance(node.func.expr, astroid.Name)
250254
and node.func.expr.name == 'yaml'
251255
):
252-
if node.func.attrname in ('unsafe_load', 'full_load'):
256+
if node.func.attrname in {'unsafe_load', 'full_load'}:
253257
# Cover:
254258
# * yaml.full_load().
255259
# * yaml.unsafe_load().
@@ -279,7 +283,7 @@ def _is_yaml_unsafe_call(node):
279283
# * yaml.load(x, FullLoader).
280284
return True
281285

282-
if isinstance(node.func, astroid.Name) and node.func.name in ('unsafe_load', 'full_load'):
286+
if isinstance(node.func, astroid.Name) and node.func.name in {'unsafe_load', 'full_load'}:
283287
# Cover:
284288
# * unsafe_load(...).
285289
# * full_load(...).
@@ -348,7 +352,8 @@ def _chmod_get_mode(node):
348352
if isinstance(node, astroid.BinOp):
349353
return _binop[node.op](_chmod_get_mode(node.left), _chmod_get_mode(node.right))
350354

351-
raise ValueError(f'Do not know how to process node: {node.repr_tree()}')
355+
msg = f'Do not know how to process node: {node.repr_tree()}'
356+
raise ValueError(msg)
352357

353358

354359
def _chmod_has_wx_for_go(node):
@@ -370,7 +375,8 @@ def _chmod_has_wx_for_go(node):
370375
else:
371376
if modes is None:
372377
# NB: this would be from invalid code such as `os.chmod("file.txt")`
373-
raise RuntimeError('Unable to extract `mode` argument from function call!')
378+
msg = 'Unable to extract `mode` argument from function call!'
379+
raise RuntimeError(msg)
374380
# pylint: disable=no-member
375381
return bool(modes & (stat.S_IWGRP | stat.S_IXGRP | stat.S_IWOTH | stat.S_IXOTH))
376382

@@ -440,11 +446,9 @@ class SecureCodingStandardChecker(BaseChecker): # pylint: disable=too-many-inst
440446
'E8003': (
441447
'Avoid using `shell=True` when calling `subprocess` functions and avoid functions that internally call it',
442448
'avoid-shell-true',
443-
' '.join(
444-
[
445-
'Use of `shell=True` in subprocess functions or use of functions that internally set it should be'
446-
'should be avoided',
447-
]
449+
(
450+
'Use of `shell=True` in subprocess functions or use of functions that internally set it should be '
451+
'should be avoided'
448452
),
449453
),
450454
'R8004': (
@@ -542,7 +546,7 @@ def __init__(self, linter):
542546
self._os_mknod_msg_arg = ''
543547
self._os_mknod_modes_allowed = []
544548

545-
def visit_call(self, node): # pylint: disable=too-many-branches # noqa: PLR0912
549+
def visit_call(self, node): # pylint: disable=too-many-branches # noqa: PLR0912, C901
546550
"""Visitor method called for astroid.Call nodes."""
547551
if _is_pdb_call(node):
548552
self.add_message('avoid-debug-stmt', node=node)
@@ -562,7 +566,7 @@ def visit_call(self, node): # pylint: disable=too-many-branches # noqa: PLR0912
562566
self.add_message('avoid-os-popen', node=node)
563567
elif _is_builtin_open_for_writing(node) and self._os_open_modes_allowed:
564568
self.add_message('replace-builtin-open', node=node)
565-
elif isinstance(node.func, astroid.Name) and (node.func.name in ('eval', 'exec')):
569+
elif isinstance(node.func, astroid.Name) and (node.func.name in {'eval', 'exec'}):
566570
self.add_message('avoid-eval-exec', node=node)
567571
elif not _is_posix() and _is_function_call(node, module='shlex', function='quote'):
568572
self.add_message('avoid-shlex-quote-on-non-posix', node=node)
@@ -609,17 +613,17 @@ def visit_import(self, node):
609613
# * import pdb as xxx.
610614
self.add_message('avoid-debug-stmt', node=node)
611615

612-
def visit_importfrom(self, node):
616+
def visit_importfrom(self, node): # noqa: C901
613617
"""Visitor method called for astroid.ImportFrom nodes."""
614618
if node.modname == 'pdb':
615619
self.add_message('avoid-debug-stmt', node=node)
616620
elif node.modname == 'tempfile' and [name for (name, _) in node.names if name == 'mktemp']:
617621
self.add_message('replace-mktemp', node=node)
618-
elif node.modname in ('os.path', 'op') and [name for (name, _) in node.names if name in ('relpath', 'abspath')]:
622+
elif node.modname in {'os.path', 'op'} and [name for (name, _) in node.names if name in {'relpath', 'abspath'}]:
619623
self.add_message('replace-os-relpath-abspath', node=node)
620624
elif (
621625
node.modname == 'subprocess'
622-
and [name for (name, _) in node.names if name in ('getoutput', 'getstatusoutput')]
626+
and [name for (name, _) in node.names if name in {'getoutput', 'getstatusoutput'}]
623627
) or (node.modname == 'asyncio' and [name for (name, _) in node.names if name == 'create_subprocess_shell']):
624628
self.add_message('avoid-shell-true', node=node)
625629
elif node.modname == 'os' and [name for (name, _) in node.names if name == 'system']:
@@ -628,9 +632,9 @@ def visit_importfrom(self, node):
628632
self.add_message('avoid-os-popen', node=node)
629633
elif not _is_posix() and node.modname == 'shlex' and [name for (name, _) in node.names if name == 'quote']:
630634
self.add_message('avoid-shlex-quote-on-non-posix', node=node)
631-
elif node.modname == 'pickle' and [name for (name, _) in node.names if name in ('load', 'loads')]:
635+
elif node.modname == 'pickle' and [name for (name, _) in node.names if name in {'load', 'loads'}]:
632636
self.add_message('avoid-pickle-load', node=node)
633-
elif node.modname == 'marshal' and [name for (name, _) in node.names if name in ('load', 'loads')]:
637+
elif node.modname == 'marshal' and [name for (name, _) in node.names if name in {'load', 'loads'}]:
634638
self.add_message('avoid-marshal-load', node=node)
635639
elif node.modname == 'shelve' and [name for (name, _) in node.names if name == 'open']:
636640
self.add_message('avoid-shelve-open', node=node)

0 commit comments

Comments
 (0)