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
This worklog enforces the coding style guide described in PEP 7 and
PEP 8.
Besides the code refactoring, it adds tooling configuration to aid the
writing of new code.
All files can be formatted using the black auto-formatter and isort.
These tools can be run automatically by pre-commit if it's configured.
Copy file name to clipboardExpand all lines: CONTRIBUTING.rst
+68-8Lines changed: 68 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -30,31 +30,91 @@ Contributing to this project is easy. You just need to follow these steps.
30
30
31
31
Thanks again for your wish to contribute to MySQL. We truly believe in the principles of open source development and appreciate any contributions to our projects.
32
32
33
-
Running Tests
34
-
-------------
33
+
Setting Up a Development Environment
34
+
------------------------------------
35
35
36
-
Any code you contribute needs to pass our test suite. Please follow these steps to run our tests and validate your contributed code.
36
+
The following tips provide all the technical directions you should follow when writing code and before actually submitting your contribution.
37
37
38
-
1) Make sure you have the necessary `prerequisites <https://dev.mysql.com/doc/dev/connector-python/8.0/installation.html#prerequisites>`_ for building the project and `Pylint <https://www.pylint.org/>`_ for code analysis and style
38
+
1) Make sure you have the necessary `prerequisites <https://dev.mysql.com/doc/dev/connector-python/8.0/installation.html#prerequisites>`_ for building the project and `Pylint <https://www.pylint.org/>`_ for static code analysis
Please follow the MySQL Connector/Python coding standards when contributing with code.
50
+
51
+
All files should be formatted using the `black <https://github.com/psf/black>`_ auto-formatter and `isort <https://pycqa.github.io/isort/>`_. This will be run by `pre-commit <https://pre-commit.com>`_ if it's configured.
52
+
53
+
For C files, the `PEP 7 <https://peps.python.org/pep-0007/>`_ should be followed. A ``.clang-format`` configuration is included in the source, so you can manually format the code using the `clang-format <https://clang.llvm.org/docs/ClangFormat.html>`_ tool.
54
+
55
+
Pre-commit Checks
56
+
~~~~~~~~~~~~~~~~~
57
+
58
+
MySQL Connector/Python comes with a pre-commit config file, which manages Git pre-commit hooks. These hooks are useful for identifing issues before committing code.
59
+
60
+
To use the pre-commit hooks, you first need to install the `pre-commit <https://pre-commit.com>`_ package and then the git hooks:
61
+
62
+
.. code-block:: bash
63
+
64
+
shell> python -m pip install pre-commit
65
+
shell> pre-commit install
66
+
67
+
The first time pre-commit runs, it will automatically download, install, and run the hooks. Running the hooks for the first time may be slow, but subsequent checks will be significantly faster.
68
+
69
+
Now, pre-commit will run on every commit.
70
+
71
+
Running Tests
72
+
-------------
73
+
74
+
Any code you contribute needs to pass our test suite. Please follow these steps to run our tests and validate your contributed code.
When submitting a patch that introduces changes to the source code, you need to make sure that those changes are be accompanied by a proper set of tests that cover 100% of the affected code paths. This is easily auditable by generating proper test coverage HTML and stdout reports using the following commands:
92
+
93
+
1) Install the `coverage.py <https://github.com/nedbat/coveragepy>`_ package
94
+
95
+
.. code-block:: bash
96
+
97
+
shell> python -m pip install coverage
98
+
99
+
2) Use coverage run to run your test suite and gather data
100
+
101
+
.. code-block:: bash
102
+
103
+
shell> coverage run unittests.py --with-mysql=<mysql-dir> --with-mysql-capi=<mysql-capi-dir> --with-protobuf-include-dir=<protobuf-include-dir> --with-protobuf-lib-dir=<protobuf-lib-dir> --with-protoc=<protoc-binary>
104
+
105
+
3) Use ``coverage report`` to report on the results
106
+
107
+
.. code-block:: bash
108
+
109
+
shell> coverage report -m
110
+
111
+
4) For a nicer presentation, use ``coverage html`` to get annotated HTML listings
112
+
113
+
.. code-block:: bash
114
+
115
+
shell> coverage html
57
116
117
+
The HTML will be generated in ``build/coverage_html``.
0 commit comments