Skip to content

Commit

Permalink
Merge pull request #621 from RocketPy-Team/mnt/update-pylint-rules
Browse files Browse the repository at this point in the history
MNT: Refactors the code to adopt pylint
  • Loading branch information
Gui-FernandesBR authored Jul 5, 2024
2 parents 23fa110 + 6908414 commit 257d16a
Show file tree
Hide file tree
Showing 83 changed files with 1,253 additions and 1,774 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/lint_black.yaml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Linters

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "**.py"
- "**.ipynb"
- ".github/**"
- "pyproject.toml"
- "requirements*"
- ".pylintrc"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[all]
pip install .[tests]
pip install pylint isort
- name: Run isort
run: isort --check-only rocketpy/ tests/ docs/ --profile black
- name: Run black
uses: psf/black@stable
with:
options: "--check rocketpy/ tests/ docs/"
jupyter: true
- name: Run pylint
run: |
pylint rocketpy/
4 changes: 3 additions & 1 deletion .github/workflows/test_pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ jobs:
run: python -c "import sys, rocketpy; print(f'{rocketpy.__name__} running on Python {sys.version}')"

- name: Install test dependencies
run: pip install -r requirements-tests.txt
run: |
pip install -r requirements-tests.txt
pip install .[all]
- name: Run Unit Tests
run: pytest tests/unit --cov=rocketpy
Expand Down
61 changes: 49 additions & 12 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fail-under=10
#from-stdin=

# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS, docs
ignore=CVS, docs, data,

# Add files or directories matching the regular expressions patterns to the
# ignore-list. The regex matches against paths and can be in Posix or Windows
Expand Down Expand Up @@ -212,7 +212,24 @@ good-names=FlightPhases,
fin_set_NACA,
fin_set_E473,
HIRESW_dictionary,

prop_I_11,
Kt, # transformation matrix transposed
clalpha2D,
clalpha2D_incompresible,
r_NOZ, # Nozzle position vector
rocket_dry_I_33,
rocket_dry_I_11,
motor_I_33_at_t,
motor_I_11_at_t,
motor_I_33_derivative_at_t,
motor_I_11_derivative_at_t,
M3_forcing,
M3_damping,
CM_to_CDM,
CM_to_CPM,
center_of_mass_without_motor_to_CDM,
motor_center_of_dry_mass_to_CDM,
generic_motor_cesaroni_M1520,

# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
Expand All @@ -222,6 +239,8 @@ good-names-rgxs= ^[a-z][0-9]?$, # Single lowercase characters, possibly followe
^(dry_|propellant_)[A-Z]+_\d+$, # Variables starting with 'dry_' or 'propellant_', followed by uppercase characters, underscore, and digits
^[a-z]+_ISA$, # Lowercase words ending with '_ISA'
^plot(1D|2D)$, # Variables starting with 'plot' followed by '1D' or '2D'
S_noz*, # nozzle gyration tensor
r_CM*, # center of mass position and its variations

# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
Expand Down Expand Up @@ -312,16 +331,16 @@ exclude-too-few-public-methods=
ignored-parents=

# Maximum number of arguments for function / method.
max-args=10
max-args=15

# Maximum number of attributes for a class (see R0902).
max-attributes=30
max-attributes=50

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5

# Maximum number of branch for function / method body.
max-branches=12
max-branches=25

# Maximum number of locals for function / method body.
max-locals=30
Expand All @@ -330,16 +349,16 @@ max-locals=30
max-parents=7

# Maximum number of public methods for a class (see R0904).
max-public-methods=40
max-public-methods=25

# Maximum number of return / yield for function / method body.
max-returns=6
max-returns=25

# Maximum number of statements in function / method body.
max-statements=50
max-statements=25

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
min-public-methods=0


[EXCEPTIONS]
Expand Down Expand Up @@ -454,14 +473,32 @@ disable=raw-checker-failed,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
deprecated-pragma, # because we have some peniding deprecations in the code.
use-symbolic-message-instead,
use-implicit-booleaness-not-comparison-to-string,
use-implicit-booleaness-not-comparison-to-zero,
no-else-return,
no-else-return, # this is a style preference, we don't need to follow it
inconsistent-return-statements,
unspecified-encoding,
unspecified-encoding, # this is not a relevant issue.
no-member, # because we use funcify_method decorator
invalid-overridden-method, # because we use funcify_method decorator
too-many-function-args, # because we use funcify_method decorator
fixme, # because we use TODO in the code
missing-module-docstring, # not useful for most of the modules.
attribute-defined-outside-init, # to avoid more than 200 errors (code works fine)
not-an-iterable, # rocketpy Functions are iterable, false positive
too-many-function-args, # gives false positives for Function calls
method-hidden, # avoids some errors in tank_geometry and flight classes
missing-timeout, # not a problem to use requests without timeout
protected-access, # we use private attriubutes out of the class (maybe we should fix this)
duplicate-code, # repeating code is a bad thing, but should we really care about it?
line-too-long, # black already takes care of this
missing-function-docstring, # this is too verbose.
redefined-outer-name, # too verbose, and doesn't add much value
method-cache-max-size-none,
no-else-raise, # pointless



# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ black:
black rocketpy/ tests/ docs/

pylint:
-pylint rocketpy tests --output=.pylint-report.txt
-pylint rocketpy --output=.pylint-report.txt

build-docs:
cd docs && $(PYTHON) -m pip install -r requirements.txt && make html
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Consider the following integration test:
# give it at least 5 times to try to download the file
example_plain_env.set_atmospheric_model(type="wyoming_sounding", file=URL)
assert example_plain_env.all_info() == None
assert example_plain_env.all_info() is None
assert abs(example_plain_env.pressure(0) - 93600.0) < 1e-8
assert (
abs(example_plain_env.barometric_height(example_plain_env.pressure(0)) - 722.0)
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ line-length = 88
include = '\.py$|\.ipynb$'
skip-string-normalization = true

[tool.isort]
profile = "black"

[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_also = [
Expand All @@ -71,7 +74,13 @@ exclude_also = [
[tool.flake8]
max-line-length = 88
max-module-lines = 3000
ignore = ['E203', 'W503']
ignore = [
'W503', # conflicts with black
'E203', # conflicts with black
'E501', # line too long, already checked by black and pylint
'E266', # too many leading '#' for block comment, this is pointless
'F401', # imported but unused, already checked by pylint
]
exclude = [
'.git,__pycache__',
]
Loading

0 comments on commit 257d16a

Please sign in to comment.