Skip to content

Commit fbb26b5

Browse files
authoredMay 31, 2024
Python: further improvements to checks and docs in dev_setup (microsoft#6445)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Added a section on documentation to the DEV_SETUP Added a check for the copyright row to pre-commit Closes microsoft#5629 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent 377287f commit fbb26b5

File tree

190 files changed

+1886
-1930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1886
-1930
lines changed
 

‎python/DEV_SETUP.md

+51
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,57 @@ It's important to note that most of this library is written with asynchronous in
155155
developer should always assume everything is asynchronous. One can use the function signature
156156
with either `async def` or `def` to understand if something is asynchronous or not.
157157

158+
### Documentation
159+
160+
Each file should have a single first line containing: # Copyright (c) Microsoft. All rights reserved.
161+
162+
We follow the [Google Docstring](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#383-functions-and-methods) style guide for functions and methods.
163+
They are currently not checked for private functions (functions starting with '_').
164+
165+
They should contain:
166+
- Single line explaining what the function does, ending with a period.
167+
- If necessary to further explain the logic a newline follows the first line and then the explanation is given.
168+
- The following three sections are optional, and if used should be separated by a single empty line.
169+
- Arguments are then specified after a header called `Args:`, with each argument being specified in the following format:
170+
- `arg_name` (`arg_type`): Explanation of the argument, arg_type is optional, as long as you are consistent.
171+
- if a longer explanation is needed for a argument, it should be placed on the next line, indented by 4 spaces.
172+
- Default values do not have to be specified, they will be pulled from the definition.
173+
- Returns are specified after a header called `Returns:` or `Yields:`, with the return type and explanation of the return value.
174+
- Finally, a header for exceptions can be added, called `Raises:`, with each exception being specified in the following format:
175+
- `ExceptionType`: Explanation of the exception.
176+
- if a longer explanation is needed for a exception, it should be placed on the next line, indented by 4 spaces.
177+
178+
Putting them all together, gives you at minimum this:
179+
180+
```python
181+
def equal(arg1: str, arg2: str) -> bool:
182+
"""Compares two strings and returns True if they are the same."""
183+
...
184+
```
185+
Or a complete version of this:
186+
187+
```python
188+
def equal(arg1: str, arg2: str) -> bool:
189+
"""Compares two strings and returns True if they are the same.
190+
191+
Here is extra explanation of the logic involved.
192+
193+
Args:
194+
arg1 (str): The first string to compare.
195+
arg2 (str): The second string to compare.
196+
This string requires extra explanation.
197+
198+
Returns:
199+
bool: True if the strings are the same, False otherwise.
200+
201+
Raises:
202+
ValueError: If one of the strings is empty.
203+
"""
204+
...
205+
```
206+
207+
If in doubt, use the link above to read much more considerations of what to do and when, or use common sense.
208+
158209
## Pydantic and Serialization
159210

160211
[Pydantic Documentation](https://docs.pydantic.dev/1.10/)

‎python/pyproject.toml

+11-5
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,24 @@ target-version = "py310"
127127
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
128128

129129
[tool.ruff.lint]
130-
select = ["D", "E", "F", "I"]
131-
ignore = ["D100", "D101", "D104"]
130+
preview = true
131+
select = ["D", "E", "F", "I", "CPY", "ISC", "INP", "RSE102", "RET", "SIM", "TD", "FIX", "ERA001", "RUF"]
132+
ignore = ["D100", "D101", "D104", "TD003", "FIX002"]
132133

133134
[tool.ruff.lint.pydocstyle]
134135
convention = "google"
135136

136137
[tool.ruff.lint.per-file-ignores]
137-
# Ignore all directories named `tests`.
138-
"tests/**" = ["D"]
139-
"samples/**" = ["D"]
138+
# Ignore all directories named `tests` and `samples`.
139+
"tests/**" = ["D", "INP", "TD", "ERA001", "RUF"]
140+
"samples/**" = ["D", "INP", "ERA001", "RUF"]
140141
# Ignore all files that end in `_test.py`.
141142
"*_test.py" = ["D"]
143+
"*.ipynb" = ["CPY", "E501"]
144+
145+
[tool.ruff.lint.flake8-copyright]
146+
notice-rgx = "^# Copyright \\(c\\) Microsoft\\. All rights reserved\\."
147+
min-file-size = 1
142148

143149
[tool.bandit]
144150
targets = ["python/semantic_kernel"]

0 commit comments

Comments
 (0)