Skip to content

Commit

Permalink
Merge pull request #4 from dnv-opensource/3-add-basic-code-quality-se…
Browse files Browse the repository at this point in the history
…ttings-black-ruff-pyright

3 add basic code quality settings black ruff pyright
  • Loading branch information
tomarnepedersen authored Nov 23, 2023
2 parents 7fa336b + 0901a2c commit 5571a4d
Show file tree
Hide file tree
Showing 15 changed files with 1,115 additions and 627 deletions.
70 changes: 70 additions & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 🪄 This is your project's Sourcery configuration file.

# You can use it to get Sourcery working in the way you want, such as
# ignoring specific refactorings, skipping directories in your project,
# or writing custom rules.

# 📚 For a complete reference to this file, see the documentation at
# https://docs.sourcery.ai/Configuration/Project-Settings/

# This file was auto-generated by Sourcery on 2023-02-22 at 11:42.

version: '1' # The schema version of this config file

ignore: # A list of paths or files which Sourcery will ignore.
- .git
- .venv
- .tox
- build
- dist
- __pycache__


rule_settings:
enable:
- default
disable: # A list of rule IDs Sourcery will never suggest.
- inline-immediately-returned-variable
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.9' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version.

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
# description: Do not use print statements in the test directory.
# pattern: print(...)
# language: python
# replacement:
# condition:
# explanation:
# paths:
# include:
# - test
# exclude:
# - conftest.py
# tests: []
# tags: []

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0

# github:
# labels: []
# ignore_labels:
# - sourcery-ignore
# request_review: author
# sourcery_branch: sourcery/{base_branch}

# clone_detection:
# min_lines: 3
# min_duplicates: 2
# identical_clones_only: false

# proxy:
# url:
# ssl_certs_file:
# no_ssl_verify: false
63 changes: 28 additions & 35 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
import os
import sys

try:
import tomli as tomli
except ImportError:
Expand All @@ -29,7 +30,7 @@
toml = tomli.load(f)
pyproject = toml["tool"]["poetry"]

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

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

Expand All @@ -39,30 +40,28 @@

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

autoapi_type = 'python'
autoapi_dirs = ['../src/trafficgen', ]
autoapi_root = 'api'
autoapi_type = "python"
autoapi_dirs = [
"../src/trafficgen",
]
autoapi_root = "api"

# 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"

# General information about the project.
project = 'Traffic Generator'
project = "Traffic Generator"
copyright = "2023, DNV, Tom Arne Pedersen"
author = "Tom Arne Pedersen"

Expand All @@ -79,15 +78,15 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to 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 = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -99,7 +98,7 @@
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# 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 @@ -116,7 +115,7 @@
# -- Options for HTMLHelp output ---------------------------------------

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


# -- Options for LaTeX output ------------------------------------------
Expand All @@ -125,15 +124,12 @@
# 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 @@ -143,21 +139,15 @@
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(master_doc, 'trafficgen.tex',
'Traffic Generator Documentation',
'Tom Arne Pedersen', 'manual'),
(master_doc, "trafficgen.tex", "Traffic Generator Documentation", "Tom Arne Pedersen", "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, 'trafficgen',
'Traffic Generator Documentation',
[author], 1)
]
man_pages = [(master_doc, "trafficgen", "Traffic Generator Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------
Expand All @@ -166,10 +156,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'trafficgen',
'Traffic Generator Documentation',
author,
'trafficgen',
'One line description of project.',
'Miscellaneous'),
(
master_doc,
"trafficgen",
"Traffic Generator Documentation",
author,
"trafficgen",
"One line description of project.",
"Miscellaneous",
),
]
123 changes: 122 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ folium = "^0.14.0"
optional = true

[tool.poetry.group.dev.dependencies]
ruff = "^0.0.287" # linter
black[jupyter] = "^23.11"
ruff = "^0.1.6" # linter
pyright = "^1.1.336"
tox = "^4.11.1"
pytest = "^7.4.1"
pytest-cov = "^4.1"
pytest-randomly = "^3.15"
sourcery = "^1.14"

[tool.poetry.group.docs]
optional = true
Expand All @@ -40,3 +45,119 @@ trafficgen = "trafficgen.cli:main"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
testpaths = "tests"
addopts = "--strict-markers"
xfail_strict = true
pythonpath = ["src"]

[tool.black]
line-length = 105
target-version = ["py39", "py310"]

[tool.ruff]
exclude = [
".git",
".venv",
".tox",
"build",
"dist",
"__pycache__",
"./docs/conf.py",
]
src = ["src"]
ignore = [
"E501", # Line length too long
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D205", # 1 blank line required between summary line and description
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
# "N802", # Function name should be lowercase (uncomment if you want to allow Uppercase function names)
# "N803", # Argument name should be lowercase (uncomment if you want to allow Uppercase argument names)
"N806", # Variable in function should be lowercase (uncomment if you want to allow Uppercase variable names in functions)
# "N815", # Variable in class scope should not be mixedCase (uncomment if you want to allow mixedCase variable names in class scope)
# "N816", # Variable in global scope should not be mixedCase (uncomment if you want to allow mixedCase variable names in global scope)
]
line-length = 105
# Activate the following rules step by step to (step by step..) improve code quality
select = [
"E",
# "D",
# "F",
# "N",
# "W",
# "I",
# "B",
]
target-version = "py39"

[tool.ruff.pep8-naming]
ignore-names = [
"test_*",
"setUp",
"tearDown",
]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
"__init__.py" = ["I001"]
"./tests/*" = ["D"]

[tool.pyright]
exclude = [
".git",
".venv",
".tox",
"build",
"dist",
"**/__pycache__",
"./docs/conf.py",
"./venv",
]
extraPaths = ["./src"]
typeCheckingMode = "basic"
useLibraryCodeForTypes = true
# Activate the following rules step by step to (step by step..) improve code quality
# reportMissingParameterType = "error"
# reportUnknownParameterType = "warning"
# reportUnknownMemberType = "warning"
# reportMissingTypeArgument = "error"
# reportPropertyTypeMismatch = "error"
# reportFunctionMemberAccess = "warning"
# reportPrivateUsage = "warning"
# reportTypeCommentUsage = "warning"
# reportIncompatibleMethodOverride = "warning"
# reportIncompatibleVariableOverride = "error"
# reportInconsistentConstructor = "error"
# reportOverlappingOverload = "warning"
# reportUninitializedInstanceVariable = "warning"
# reportCallInDefaultInitializer = "warning"
# reportUnnecessaryIsInstance = "information"
# reportUnnecessaryCast = "warning"
# reportUnnecessaryComparison = "warning"
# reportUnnecessaryContains = "warning"
# reportUnusedCallResult = "warning"
# reportUnusedExpression = "warning"
# reportMatchNotExhaustive = "warning"
# reportShadowedImports = "warning"
# reportUntypedFunctionDecorator = "warning"
# reportUntypedBaseClass = "error"
# reportUntypedNamedTuple = "warning"

# Activate the following rules only locally and temporary, i.e. for a QA session.
# (For server side CI they are considered too strict.)
# reportConstantRedefinition = "warning"
# reportUnnecessaryTypeIgnoreComment = "information"
# reportImportCycles = "warning"
# reportImplicitStringConcatenation = "warning"
Loading

0 comments on commit 5571a4d

Please sign in to comment.