You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: handle union type and add pre-commit lint hooks (#51)
* ci: add pre-commit hooks and automated tests
* build: remove obsolete init.sh file
* ci: define a cache for the virtual environment based on the dependencies lock file
* build(yapf): upgraded version
* feat(inspect): handle unions in type annotations
* build: improve code coverage (added tests, removed irrelevant code)
* ci: run test without installing the lint dependencies
* docs(readme): fix copy-pasted reference to pydoctrace
* docs(contributing): add how to activate the pre-commit hooks
* ci(ruff): update version to 0.0.285
* ci(jobs): add concurrency to cancel a running job when a new one is triggered
* refactor(tests): split union-types tests in different unit tests for readability sake
* style(tests): post-review fixes about test code (type annotations, code comments, doc styling, default values)
* docs(readme): add a section about the Python versions required by py2puml and pyenv
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+13-79
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,19 @@ version = "major.minor.patch"
64
64
It takes time to write comprehensive guidelines.
65
65
To save time (my writing time and your reading time), I tried to make it short so my best advice is _go have a look at the production and test codes and try to follow the conventions you draw from what you see_ 🙂
66
66
67
+
To homogenize code style consistency and enforce code quality, this project uses:
68
+
69
+
- the `yapf` formatter and the `ruff` linter
70
+
-`pre-commit` hooks that are triggered on the Github CI (in pull-requests) and should be activated locally when contributing to the project:
71
+
72
+
```sh
73
+
# installs the dependencies, including pre-commit as a lint dependency
74
+
poetry install
75
+
76
+
# activates the pre-commit hooks
77
+
poetry run pre-commit install --hook-type pre-commit --hook-type commit-msg
78
+
```
79
+
67
80
## Unit tests
68
81
69
82
Pull requests must come with unit tests, either new ones (for feature addtitions), changed ones (for feature changes) or non-regression ones (for bug fixes).
@@ -91,82 +104,3 @@ When manipulating **literal strings**:
91
104
python_version ='3.8+'
92
105
f'use f-strings to format strings, py2puml use Python {python_version}'
93
106
```
94
-
95
-
### Code formatting
96
-
97
-
#### Imports
98
-
99
-
The following guidelines regarding imports are designed to help people understand what a Python module does or deals with:
100
-
101
-
* place import statements at the top of the file
102
-
* explicit the functionalities you import with the `from ... import ...` syntax instead of importing a whole module (it does not tell how this module is being used)
103
-
* order the imports by family of modules:
104
-
1. the native modules (the types imported from the typing module are often placed first)
105
-
1. the dependency modules defined in the [pyproject.toml file](pyproject.toml) (`py2puml` only use development dependencies)
106
-
1. the modules of the `py2puml` package
107
-
* when they are so many items imported from a module that they do not fit on a single line, wrap them with a pair of parentheses instead of using a backslash
108
-
109
-
```python
110
-
from typing import Dict, List, Tuple
111
-
112
-
from ast import (
113
-
NodeVisitor, arg, expr,
114
-
FunctionDef, Assign, AnnAssign,
115
-
Attribute, Name, Tuple as AstTuple,
116
-
Subscript, get_source_segment
117
-
)
118
-
from collections import namedtuple
119
-
120
-
from py2puml.domain.umlclass import UmlAttribute
121
-
from py2puml.domain.umlrelation import UmlRelation, RelType
122
-
```
123
-
124
-
#### Code indentation
125
-
126
-
Most settings in Python-code editors replace tabulation by 4 space characters.
127
-
That is what is used for this library as well.
128
-
129
-
This library follows an opiniated way for formatting the code between **parentheses, brackets or braces**.
130
-
Whenever a block of python expressions is surrounded by a pair of parentheses, brackets or braces:
131
-
132
-
* start the inner content in an indented block (one tabulation is enough) in a new line following the opening parenthesis, bracket or brace
133
-
* type the closing parenthesis, bracket or brace in a new line, de-indent so that the inner content is visually enclosed between the opening and closing symbol
`py2puml` uses [pre-commit hooks](https://pre-commit.com/) and [pre-commit.ci Continuous Integration](https://pre-commit.ci/) to enforce commit messages, code formatting and linting for quality and consistency sake.
18
+
See the [code conventions](#code-conventions) section if you would like to contribute to the project.
19
+
20
+
14
21
# How it works
15
22
16
23
`py2puml` produces a class diagram [PlantUML script](https://plantuml.com/en/class-diagram) representing classes properties (static and instance attributes) and their relations (composition and inheritance relationships).
17
24
18
25
`py2puml` internally uses code [inspection](https://docs.python.org/3/library/inspect.html) (also called *reflexion* in other programming languages) and [abstract tree parsing](https://docs.python.org/3/library/ast.html) to retrieve relevant information.
19
-
Some parsing features are available only since Python 3.8 (like [ast.get_source_segment](https://docs.python.org/3/library/ast.html#ast.get_source_segment)).
26
+
27
+
## Minimum Python versions to run py2puml
28
+
29
+
`p2puml` uses some code-parsing features that are available only since **Python 3.8** (like [ast.get_source_segment](https://docs.python.org/3/library/ast.html#ast.get_source_segment)).
30
+
If your codebase uses the `int | float` syntax to define optional types, then you should use Python 3.10 to run `py2puml`.
31
+
32
+
To sum it up, use at least Python 3.8 to run py2puml, or a higher version if you use syntax features available only in higher versions.
33
+
34
+
The [.python-version](.python-version) file indicates the Python version used to develop the library.
35
+
It is a file used by [pyenv](https://github.com/pyenv/pyenv/) to define the binary used by the project.
20
36
21
37
## Features
22
38
@@ -129,7 +145,7 @@ footer Generated by //py2puml//
129
145
@enduml
130
146
```
131
147
132
-
Using PlantUML, this content is rendered as this diagram:
148
+
Using PlantUML, this content is rendered as in this diagram:
poetry run pytest -v --cov=py2puml --cov-branch --cov-report term-missing --cov-fail-under 92
211
+
poetry run pytest -v --cov=py2puml --cov-branch --cov-report term-missing --cov-fail-under 93
196
212
```
197
213
198
214
# Changelog
199
215
216
+
*`0.8.0`: added support for union types, and github actions (pre-commit hooks + automated tests)
200
217
*`0.7.2`: added the current working directory to the import path to make py2puml work in any directory or in native virtual environment (not handled by poetry)
201
218
*`0.7.1`: removed obsolete part of documentation: deeply compound types are now well handled (by version `0.7.0`)
202
219
*`0.7.0`: improved the generated PlantUML documentation (added the namespace structure of the code base, homogenized type between inspection and parsing), improved relationships management (handle forward references, deduplicate relationships)
@@ -224,8 +241,55 @@ Unless stated otherwise all works are licensed under the [MIT license](http://sp
224
241
*[Julien Jerphanion](https://github.com/jjerphan)
225
242
*[Luis Fernando Villanueva Pérez](https://github.com/jonykalavera)
226
243
244
+
## Pull requests
245
+
227
246
Pull-requests are welcome and will be processed on a best-effort basis.
228
-
Follow the [contributing guide](CONTRIBUTING.md).
247
+
248
+
Pull requests must follow the guidelines enforced by the `pre-commit` hooks:
249
+
250
+
- commit messages must follow the Angular conventions enforced by the `commitlint` hook
251
+
- code formatting must follow the conventions enforced by the `isort` and `yapf` hooks
252
+
- code linting should not detect code smells in your contributions, this is checked by the `ruff` hook
253
+
254
+
Please also follow the [contributing guide](CONTRIBUTING.md) to ease your contribution.
255
+
256
+
## Code conventions
257
+
258
+
The code conventions are described and enforced by [pre-commit hooks](https://pre-commit.com/hooks.html) to maintain consistency across the code base.
259
+
The hooks are declared in the [.pre-commit-config.yaml](.pre-commit-config.yaml) file.
260
+
261
+
Set the git hooks (pre-commit and commit-msg types):
262
+
263
+
```sh
264
+
poetry run pre-commit install --hook-type pre-commit --hook-type commit-msg
265
+
```
266
+
267
+
Before committing, you can check your changes with:
268
+
269
+
```sh
270
+
# put all your changes in the git staging area
271
+
git add -A
272
+
273
+
# all hooks
274
+
poetry run pre-commit run --all-files
275
+
276
+
# a specific hook
277
+
poetry run pre-commit run ruff --all-files
278
+
```
279
+
280
+
### Commit messages
281
+
282
+
Please, follow the [conventions of the Angular team](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format) for commit messages.
283
+
When merging your pull-request, the new version of the project will be derived from the messages.
284
+
285
+
### Code formatting
286
+
287
+
This project uses `isort` and `yapf` to format the code.
288
+
The guidelines are expressed in their respective sections in the [pyproject.toml](pyproject.toml) file.
289
+
290
+
### Best practices
291
+
292
+
This project uses the `ruff` linter, which is configured in its section in the [pyproject.toml](pyproject.toml) file.
0 commit comments