Skip to content

Enhance Code Quality with Ruff, Black, and Pre-commit #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5f6d3bd
add: linter, formatter for github actions
soulee-dev Aug 28, 2023
4670d31
add: CONTRIBUTING.md
soulee-dev Aug 28, 2023
76e0ed9
add: pre-commit config and pre-commit rule
soulee-dev Aug 28, 2023
f78e436
fix: auto-fix with ruff
soulee-dev Aug 28, 2023
c913f6d
fix: E401 Multiple imports on one line
soulee-dev Aug 28, 2023
b561eff
fix: E999 SyntaxError: Unexpected token 'json'
soulee-dev Aug 28, 2023
76551e3
fix: F821 Undefined name `unicode` by removing python2 compatibility
soulee-dev Aug 28, 2023
0ddeb2c
fix: F811 Redefinition of unused `gtid` from line 3
soulee-dev Aug 28, 2023
6ba4908
fix: E721 Do not compare types, use `isinstance()`
soulee-dev Aug 28, 2023
42b6e99
fix: E721 Do not compare types, use `isinstance()`
soulee-dev Aug 28, 2023
f516bf1
fix: F811 Redefinition of unused `TestMariadbBinlogStreamReader` from…
soulee-dev Aug 28, 2023
a10a9ce
fix: import json
soulee-dev Aug 28, 2023
b4069b1
fix: fromtimestamp into utcfromtimestamp
soulee-dev Aug 28, 2023
dfe1358
fix: apply black formatter
soulee-dev Aug 28, 2023
4a59307
fix: test that doesn't work
soulee-dev Aug 28, 2023
2148ae7
fix: remove actions dependencies
soulee-dev Sep 2, 2023
e7dcf33
Merge branch 'main' into enhancement/linter-and-formatter
soulee-dev Sep 4, 2023
7a5cfc2
fix: E712
soulee-dev Sep 4, 2023
ed94c76
fix: apply black
soulee-dev Sep 4, 2023
fb9bf88
Merge branch 'main' into enhancement/linter-and-formatter
soulee-dev Sep 12, 2023
e6bcd51
fix: apply black
soulee-dev Sep 12, 2023
e4500d6
fix: remove duplicated if-statement
soulee-dev Sep 12, 2023
fd52bbe
fix: indent for if-statement
soulee-dev Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Lint
on: [ push, pull_request ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
- uses: psf/black@stable
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.286
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributing to python-mysql-replication

Firstly, thank you for considering to contribute to `python-mysql-replication`. We appreciate your effort, and to ensure that your contributions align with the project's coding standards, we employ the use of `pre-commit` hooks. This guide will walk you through setting them up.

## Setting up pre-commit

1. **Install pre-commit**

Before you can use `pre-commit`, you need to install it. You can do so using `pip`:

```bash
pip install pre-commit
```

2. **Install the pre-commit hooks**

Navigate to the root directory of your cloned `python-mysql-replication` repository and run:

```bash
pre-commit install
```

This will install the `pre-commit` hooks to your local repository.

3. **Make sure to stage your changes**

`pre-commit` will only check the files that are staged in git. So make sure to `git add` any new changes you made before running `pre-commit`.

4. **Run pre-commit manually (Optional)**

Before committing, you can manually run:

```bash
pre-commit run --all-files
```

This will run the hooks on all the files. If there's any issue, the hooks will let you know.

## If you encounter issues

If you run into any problems with the hooks, you can always skip them using:

```bash
git commit -m "Your commit message" --no-verify
```

However, please note that skipping hooks might lead to CI failures if we use these checks in our CI pipeline. It's always recommended to adhere to the checks to ensure a smooth contribution process.

---

That's it! With these steps, you should be well on your way to contributing to `python-mysql-replication`. We look forward to your contributions!
151 changes: 83 additions & 68 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,214 +11,223 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys
import os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'Python MySQL Replication'
copyright = u'2012-2023, Julien Duponchelle'
project = "Python MySQL Replication"
copyright = "2012-2023, Julien Duponchelle"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.43'
version = "0.43"
# The full version, including alpha/beta/rc tags.
release = '0.43'
release = "0.43"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}

# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True

# If false, no index is generated.
#html_use_index = True
# html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'PythonMySQLReplicationdoc'
htmlhelp_basename = "PythonMySQLReplicationdoc"


# -- Options for LaTeX output --------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PythonMySQLReplication.tex', u'Python MySQL Replication Documentation',
u'Julien Duponchelle', 'manual'),
(
"index",
"PythonMySQLReplication.tex",
"Python MySQL Replication Documentation",
"Julien Duponchelle",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False

# If true, show page references after internal links.
#latex_show_pagerefs = False
# latex_show_pagerefs = False

# If true, show URL addresses after external links.
#latex_show_urls = False
# latex_show_urls = False

# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []

# If false, no module index is generated.
#latex_domain_indices = True
# latex_domain_indices = True


# -- Options for manual page output --------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pythonmysqlreplication', u'Python MySQL Replication Documentation',
[u'Julien Duponchelle'], 1)
(
"index",
"pythonmysqlreplication",
"Python MySQL Replication Documentation",
["Julien Duponchelle"],
1,
)
]

# If true, show URL addresses after external links.
#man_show_urls = False
# man_show_urls = False


# -- Options for Texinfo output ------------------------------------------------
Expand All @@ -227,16 +236,22 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'PythonMySQLReplication', u'Python MySQL Replication Documentation',
u'Julien Duponchelle', 'PythonMySQLReplication', 'One line description of project.',
'Miscellaneous'),
(
"index",
"PythonMySQLReplication",
"Python MySQL Replication Documentation",
"Julien Duponchelle",
"PythonMySQLReplication",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# texinfo_appendices = []

# If false, no module index is generated.
#texinfo_domain_indices = True
# texinfo_domain_indices = True

# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# texinfo_show_urls = 'footnote'
Loading