Skip to content

Commit

Permalink
Style and formatting rules (#51)
Browse files Browse the repository at this point in the history
* docs: clarify formatting guidelines

* fix: configuration for formatting tools

* fix: absolute import

* style: reformatted with black and flake8

* style: order imports

* fix: added config for pylint

* style: typo

* fix: prevent Iterator to loop forever

* style: sorting imports

* pre-commit

* fix: removed

* fix: function name

* style: formatting

* fix: list groups test

* style: sort import

* added links

Co-authored-by: Jacob Gårder <Jacob.Garder@hm.com>
  • Loading branch information
jacobgarder and Jacob Gårder committed Nov 3, 2021
1 parent 071ffa5 commit 8158ff8
Show file tree
Hide file tree
Showing 30 changed files with 180 additions and 248 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 127
max-doc-length = 127
extend_ignore = E203, W503, W605, F841
exclude = build,dist,.git,docs,docsrc,examples,.venv,venv
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
exclude: ^(docsrc/|docs/|examples/)
repos:
- repo: local
hooks:
- id: black
name: black
language: system
entry: black
minimum_pre_commit_version: 2.9.2
require_serial: true
types: [python]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort
args: [--profile, black, --skip, docsrc, --skip, examples, --filter-files]
types: [python]
17 changes: 10 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ Pull requests are the best way to propose changes to the codebase. Pull requests
Once your change has been merged into `develop`, it will be bundled with the next batch of changes into the next release,
which is merged into main.

## Keep Pull Requests Short and Specific!
## Keep Pull Requests Short and Specific

It takes a lot of work to review a PR that covers multiple issues or features. Breaking
your PR up into smaller requests is greatly appreciated. Doing this ensures quick review
and PRs that require additional work won't hold up other work.

If there is one thing you do, please do this.

## I recommend Conventional Commits

No system is perfect, but I've found [Conventional Commits](https://www.conventionalcommits.org/) to work pretty well for myself. At the very
least check it out and see if it works for you too.

Expand All @@ -45,16 +47,16 @@ maintainers if that's a concern.

## Report bugs using Github's [issues](https://github.com/mitchos/pyZscaler/issues)

I use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!
I use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/mitchos/pyzscaler/issues/new); it's that easy!

## Write bug reports with detail, background, and sample code

**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can.
- Be specific!
- Give sample code if you can.
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
Expand All @@ -63,8 +65,9 @@ People *love* thorough bug reports.

## Use a Consistent Coding Style

* Tabs over spaces :)
* I use [Black](https://github.com/psf/black) for formatting in this project.
- [Black](https://github.com/psf/black) is used for formatting in this project with line-length 127.

- [Flake8](https://flake8.pycqa.org) is used for linting.

## License

Expand All @@ -73,4 +76,4 @@ By contributing, you agree that your contributions will be licensed under the MI
## References

This document was adapted from the open-source contribution guidelines
for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)
for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)
67 changes: 33 additions & 34 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
import os
import sys

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

# -- Project information -----------------------------------------------------

project = 'pyZscaler'
copyright = '2021, Mitch Kelly'
author = 'Mitch Kelly'
html_title = ''
project = "pyZscaler"
copyright = "2021, Mitch Kelly"
author = "Mitch Kelly"
html_title = ""

# The short X.Y version
version = '0.10'
version = "0.10"
# The full version, including alpha/beta/rc tags
release = '0.10.0'
release = "0.10.0"

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

Expand All @@ -39,27 +39,27 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.githubpages',
'sphinx.ext.napoleon'
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.githubpages",
"sphinx.ext.napoleon",
]
autodoc_typehints = "none"
add_module_names = False
autodoc_class_signature = "separated"

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

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

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

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -71,7 +71,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
Expand All @@ -81,8 +81,8 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_logo = 'logo.svg'
html_theme = "furo"
html_logo = "logo.svg"

# 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
Expand All @@ -95,7 +95,7 @@
# 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"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -111,23 +111,20 @@
# -- Options for HTMLHelp output ---------------------------------------------

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

# -- 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': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -137,28 +134,30 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyZscaler.tex', 'pyZscaler Documentation',
'Mitch Kelly', 'manual'),
(master_doc, "pyZscaler.tex", "pyZscaler Documentation", "Mitch Kelly", "manual"),
]

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

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pyzscaler', 'pyZscaler Documentation',
[author], 1)
]
man_pages = [(master_doc, "pyzscaler", "pyZscaler Documentation", [author], 1)]

# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyZscaler', 'pyZscaler Documentation',
author, 'pyZscaler', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"pyZscaler",
"pyZscaler Documentation",
author,
"pyZscaler",
"One line description of project.",
"Miscellaneous",
),
]

# -- Options for Epub output -------------------------------------------------
Expand All @@ -176,14 +175,14 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]

# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}

# -- Options for todo extension ----------------------------------------------

Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ requests = "2.26.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 127

[tool.pylint.'MESSAGES CONTROL']
disable=[
"format",
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring",
"too-many-public-methods",
"anomalous-backslash-in-string",
"import-error",
"redefined-outer-name",
]

[tool.pylint.'FORMAT']
max-line-length = 127

[tool.isort]
profile = "black"
5 changes: 3 additions & 2 deletions pyzscaler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
__license__ = "MIT"
__contributors__ = [
"Dax Mickelson",
"Jacob Gårder",
]
__version__ = "0.10.0"

from .zia import ZIA
from .zpa import ZPA
from pyzscaler.zia import ZIA # noqa
from pyzscaler.zpa import ZPA # noqa
3 changes: 2 additions & 1 deletion pyzscaler/zia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from restfly.session import APISession

from pyzscaler import __version__

from .admin_role_management import AdminAndRoleManagementAPI
from .audit_logs import AuditLogsAPI
from .config import ActivationAPI
from .dlp import DLPAPI
Expand All @@ -17,7 +19,6 @@
from .url_filters import URLFilteringAPI
from .users import UserManagementAPI
from .vips import DataCenterVIPSAPI
from .admin_role_management import AdminAndRoleManagementAPI


class ZIA(APISession):
Expand Down
16 changes: 4 additions & 12 deletions pyzscaler/zia/dlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ def add_dict(self, name, match_type, **kwargs):

# Simplify Zscaler's required values for our users.
if match_type == "all":
payload[
"customPhraseMatchType"
] = "MATCH_ALL_CUSTOM_PHRASE_PATTERN_DICTIONARY"
payload["customPhraseMatchType"] = "MATCH_ALL_CUSTOM_PHRASE_PATTERN_DICTIONARY"
elif match_type == "any":
payload[
"customPhraseMatchType"
] = "MATCH_ANY_CUSTOM_PHRASE_PATTERN_DICTIONARY"
payload["customPhraseMatchType"] = "MATCH_ANY_CUSTOM_PHRASE_PATTERN_DICTIONARY"
else:
raise ValueError

Expand Down Expand Up @@ -172,13 +168,9 @@ def update_dict(self, dict_id, **kwargs):
if kwargs.get("match_type"):
match_type = kwargs.pop("match_type")
if match_type == "all":
payload[
"customPhraseMatchType"
] = "MATCH_ALL_CUSTOM_PHRASE_PATTERN_DICTIONARY"
payload["customPhraseMatchType"] = "MATCH_ALL_CUSTOM_PHRASE_PATTERN_DICTIONARY"
elif match_type == "any":
payload[
"customPhraseMatchType"
] = "MATCH_ANY_CUSTOM_PHRASE_PATTERN_DICTIONARY"
payload["customPhraseMatchType"] = "MATCH_ANY_CUSTOM_PHRASE_PATTERN_DICTIONARY"
else:
raise ValueError

Expand Down
Loading

0 comments on commit 8158ff8

Please sign in to comment.