Skip to content

Commit 4ff361a

Browse files
authored
Merge pull request #4 from lestex/redo-imports
redo package imports and documentation
2 parents 716803d + 469d900 commit 4ff361a

File tree

13 files changed

+78
-63
lines changed

13 files changed

+78
-63
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
pip install --upgrade pip setuptools wheel
27-
pip install flake8==4.0.1
28-
pip install --upgrade isort blue mypy types-PyYAML bandit safety
27+
pip install --upgrade isort blue mypy ruff bandit safety
2928
3029
- name: Run lint
3130
run: isort .
3231

3332
- name: Run blue formatter
3433
run: make format
3534

36-
- name: Run flake8
37-
run: |
38-
flake8 . --count --show-source --statistics
39-
flake8 . --count --exit-zero --max-complexity=4
35+
- name: Run ruff
36+
run: ruff .
4037

4138
- name: Run mypy / static types
4239
run: make static-check

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/hooks.html for more hooks
32
repos:
43
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.3.0
4+
rev: v4.4.0
65
hooks:
76
- id: check-added-large-files
87
- id: check-toml
@@ -21,3 +20,8 @@ repos:
2120
hooks:
2221
- id: blue
2322
name: blue
23+
- repo: https://github.com/charliermarsh/ruff-pre-commit
24+
rev: v0.0.219
25+
hooks:
26+
- id: ruff
27+
args: ["--force-exclude"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ format: isort ## formats python
7272
@blue .
7373

7474
lint: format ## run python flake8 linter tool
75-
@flake8 --exclude .git,.venv pygithubactions
75+
@ruff .
7676

7777
static-check: ## runs static checks with mypy
7878
@mypy pygithubactions

README.md

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
### Import the package
88

99
```python
10-
import pygithubaction.core
10+
from pygithubactions import core
1111
```
1212

1313
### Inputs/Outputs
@@ -17,89 +17,86 @@ Action inputs can be read with `get_input` which returns a `str` or `get_boolean
1717
Outputs can be set with `set_output` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
1818

1919
```python
20-
from pygithubaction.core import get_input
21-
from pygithubaction.core import set_output
20+
from pygithubactions import core
2221

23-
my_input = get_input('inputName', required=True);
24-
boolean_input = get_boolean_input('booleanInputName', required=True);
25-
multiline_input = get_multiline_input('multilineInputName', required=True)
22+
my_input = core.get_input('inputName', required=True)
23+
boolean_input = core.get_boolean_input('booleanInputName', required=True)
24+
multiline_input = core.get_multiline_input('multilineInputName', required=True)
2625

27-
set_output('outputkey', 'outputval')
26+
core.set_output('outputkey', 'outputval')
2827
```
2928

3029
### Exporting variables
3130

3231
Since each step runs in a separate process, you can use `export_variable` to add it to this step and future steps environment blocks.
3332

3433
```python
35-
from pygithubaction.core import export_variable
34+
from pygithubactions import core
3635

37-
export_variable('envvar', 'val')
36+
core.export_variable('envvar', 'val')
3837
```
3938

4039
### Setting a secret
4140

4241
Setting a secret registers the secret with the runner to ensure it is masked in logs.
4342

4443
```python
45-
from pygithubaction.core import set_secret
44+
from pygithubactions import core
4645

47-
set_secret('mypassword')
46+
core.set_secret('mypassword')
4847
```
4948

5049
### PATH Manipulation
5150

5251
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `add_path`. The runner will prepend the path given to the jobs PATH.
5352

5453
```python
55-
from pygithubaction.core import add_path
54+
from pygithubactions import core
5655

57-
add_path('/path/to/mytool')
56+
core.add_path('/path/to/mytool')
5857
```
5958

6059
### Exit codes
6160

6261
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
6362

6463
```python
65-
from pygithubaction.core import set_failed
64+
from pygithubactions import core
6665

6766
try:
6867
# Do stuff
6968
# ...
7069

7170
except Exception as e:
7271
# set_failed logs the message and sets a failing exit code
73-
set_failed(f'Action failed with error {e}')
72+
core.set_failed(f'Action failed with error {e}')
7473
```
7574

7675
### Logging
7776

7877
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
7978

8079
```python
81-
from pygithubaction.core import (
82-
get_input, debug, info, notice, is_debug, error
83-
)
80+
from pygithubactions import core
8481

8582

86-
my_input = get_input('input');
83+
my_input = core.get_input('input')
8784

8885
try:
89-
debug('Inside try block')
90-
86+
core.debug('Inside try block')
87+
9188
if not my_input:
92-
warning('my_input was not set')
93-
94-
if is_debug():
95-
# curl -v https://github.com
89+
core.warning('my_input was not set')
90+
91+
if core.is_debug():
92+
# do something
9693
else:
97-
# curl https://github.com
94+
# do something
9895

9996
# Do stuff
100-
info('Output to the actions build log')
101-
notice('This is a message that will also emit an annotation')
97+
core.info('Output to the actions build log')
98+
core.notice('This is a message that will also emit an annotation')
10299

103100
except Exception as e:
104-
error(f'Error: {e}, action may still succeed though')
101+
core.error(f'Error: {e}, action may still succeed though')
105102
```

pygithubactions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from pygithubactions.core import core

pygithubactions/core/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_input(
6464
6565
Returns:
6666
value (str): - Input value.
67-
""" # noqa
67+
"""
6868
norm_name = name.replace(' ', '_').upper()
6969
value = os.environ.get(f'INPUT_{norm_name}', '')
7070

@@ -91,7 +91,7 @@ def get_boolean_input(
9191
9292
Returns:
9393
bool
94-
""" # noqa
94+
"""
9595
true_values = ['true', 'True', 'TRUE']
9696
false_values = ['false', 'False', 'FALSE']
9797
value = get_input(name, required, trim_whitespace)
@@ -122,14 +122,14 @@ def get_multiline_input(
122122
123123
Returns:
124124
list[str]: List of inputs.
125-
""" # noqa
125+
"""
126126
inputs = get_input(name, required, trim_whitespace)
127127
inputs_list = [i for i in inputs.split('\n') if i != '']
128128

129129
if not trim_whitespace:
130130
return inputs_list
131131

132-
return list(map(lambda i: i.strip(), inputs_list))
132+
return [i.strip() for i in inputs_list]
133133

134134

135135
def set_output(name: str, value: Any) -> None:

pygithubactions/core/file_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def prepare_key_value_message(key: str, value: Any) -> str:
4040
f'the delimiter: {delimiter}'
4141
)
4242

43-
return f'{key}<<{delimiter}{os.linesep}{converted_value}{os.linesep}{delimiter}' # noqa
43+
return f'{key}<<{delimiter}{os.linesep}{converted_value}{os.linesep}{delimiter}'

pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22

33
name = "pygithubactions"
4-
version = "0.1.0"
4+
version = "0.1.0"
55
description = "Github actions core library implemented in python"
66
readme = "README.md"
77
requires-python = ">=3.10"
@@ -46,3 +46,19 @@ multi_line_output = 3
4646

4747
[tool.mypy]
4848
ignore_missing_imports = true
49+
50+
[tool.ruff]
51+
select = [
52+
"E", # pycodestyle errors
53+
"W", # pycodestyle warnings
54+
"F", # pyflakes
55+
"C", # flake8-comprehensions
56+
"B", # flake8-bugbear
57+
]
58+
59+
[tool.ruff.per-file-ignores]
60+
"__init__.py" = ["F401"]
61+
"tests/*.py" = ["E501"]
62+
63+
[tool.ruff.mccabe]
64+
max-complexity = 3

tests/test_command.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_command_escape_message(capsys):
1616
captured = capsys.readouterr()
1717
assert (
1818
captured.out
19-
== f'::some-command::percent %25 percent %25 cr %0D cr %0D lf %0A lf %0A{os.linesep}' # noqa: E501
19+
== f'::some-command::percent %25 percent %25 cr %0D cr %0D lf %0A lf %0A{os.linesep}'
2020
)
2121

2222
# verify literal escape sequences
@@ -32,14 +32,14 @@ def test_command_escape_property(capsys):
3232
issue_command(
3333
'some-command',
3434
{
35-
'name': 'percent % percent % cr \r cr \r lf \n lf \n colon : colon : comma , comma ,' # noqa: E501
35+
'name': 'percent % percent % cr \r cr \r lf \n lf \n colon : colon : comma , comma ,'
3636
},
3737
'',
3838
)
3939
captured = capsys.readouterr()
4040
assert (
4141
captured.out
42-
== f'::some-command name=percent %25 percent %25 cr %0D cr %0D lf %0A lf %0A colon %3A colon %3A comma %2C comma %2C::{os.linesep}' # noqa: E501
42+
== f'::some-command name=percent %25 percent %25 cr %0D cr %0D lf %0A lf %0A colon %3A colon %3A comma %2C comma %2C::{os.linesep}'
4343
)
4444

4545
# Verify literal escape sequences
@@ -51,7 +51,7 @@ def test_command_escape_property(capsys):
5151
captured = capsys.readouterr()
5252
assert (
5353
captured.out
54-
== f'::some-command::%2525 %2525 %250D %250D %250A %250A %253A %253A %252C %252C{os.linesep}' # noqa: E501
54+
== f'::some-command::%2525 %2525 %250D %250D %250A %250A %253A %253A %252C %252C{os.linesep}'
5555
)
5656

5757

@@ -70,7 +70,7 @@ def test_command_with_message_properties(capsys):
7070
captured = capsys.readouterr()
7171
assert (
7272
captured.out
73-
== f'::some-command prop1=value 1,prop2=value 2::some message{os.linesep}' # noqa: E501
73+
== f'::some-command prop1=value 1,prop2=value 2::some message{os.linesep}'
7474
)
7575

7676

@@ -102,7 +102,7 @@ def test_command_with_three_properties(capsys):
102102
captured = capsys.readouterr()
103103
assert (
104104
captured.out
105-
== f'::some-command prop1=value 1,prop2=value 2,prop3=value 3::{os.linesep}' # noqa: E501
105+
== f'::some-command prop1=value 1,prop2=value 2,prop3=value 3::{os.linesep}'
106106
)
107107

108108

@@ -118,5 +118,5 @@ def test_command_with_non_string_props(capsys):
118118
)
119119

120120
captured = capsys.readouterr()
121-
part_out = '::some-command prop1={"test"%3A "object"},prop2=123,prop3=true::{"test": "object"}' # noqa: E501
121+
part_out = '::some-command prop1={"test"%3A "object"},prop2=123,prop3=true::{"test": "object"}'
122122
assert captured.out == f'{part_out}{os.linesep}'

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_is_debug():
2626

2727
def test_set_failed_sets_correct_exit_code_failure_message(capsys):
2828
failure_message = 'Failure message'
29-
with pytest.raises(SystemExit) as e: # noqa
29+
with pytest.raises(SystemExit) as e:
3030
set_failed(failure_message)
3131

3232
captured = capsys.readouterr()

0 commit comments

Comments
 (0)