Skip to content

Commit

Permalink
Move rule descriptions to rule class docstrings
Browse files Browse the repository at this point in the history
As I wrote in KiCad#220, the rule class docstrings seem like a more sensible
place for rule descriptions.  I offered to make this change a couple of
months ago, and have seen no objections, so here it is.

While moving the descriptions, I changed them all to match the one-line
rule names in KLC 3.0.11, the current revision.

In moving the descriptions out of the constructor, many rule classes no
longer need to define their own constructors at all, so overall this
reduces how much code we have to maintain.
  • Loading branch information
Ratfink committed May 24, 2018
1 parent 9460010 commit ce445f1
Show file tree
Hide file tree
Showing 38 changed files with 67 additions and 183 deletions.
4 changes: 2 additions & 2 deletions common/rulebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def name(self):
path = "".join(path.split(".")[:-1])
return path.replace('_', '.')

def __init__(self, description):
self.description = description
def __init__(self):
self.description = self.__doc__.strip().splitlines()[0].strip()
self.messageBuffer=[]
self.resetErrorCount()
self.resetWarningCount()
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import cmath

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Silkscreen layer requirements")
"""Silkscreen layer requirements"""

def checkReference(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Fabrication layer requirements")
"""Fabrication layer requirements"""

# Check for presence of component value
def checkMissingValue(self):
Expand Down
8 changes: 2 additions & 6 deletions pcb/rules/F5_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
from boundingbox import BoundingBox

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Courtyard layer requirements")
"""Courtyard layer requirements"""

# Get the superposed boundary of pads and fab layer
def getFootprintBounds(self):
Expand Down Expand Up @@ -214,4 +210,4 @@ def fix(self):
self.module.addRectangle(
[cy['x'], cy['y']],
[cy['x'] + cy['width'], cy['y'] + cy['height']],
'F.CrtYd', KLC_CRTYD_WIDTH)
'F.CrtYd', KLC_CRTYD_WIDTH)
6 changes: 1 addition & 5 deletions pcb/rules/F6_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For surface-mount devices, placement type must be set to "Surface Mount"')
"""Footprint placement type must be set to surface mount"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F6_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args,'For surface-mount devices, footprint anchor is placed in the middle of the footprint (IPC-7351).')
"""Footprint anchor should be placed in the middle of the component body"""

def check(self):
"""
Expand Down
7 changes: 3 additions & 4 deletions pcb/rules/F6_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
"""Pad requirements for SMD footprints"""

def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad requirements for SMD footprints')
super(Rule, self).__init__(module, args)

self.required_layers = ["Cu", "Paste", "Mask"]
self.sides = ["F.", "B."]
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For through-hole devices, placement type must be set to "Through Hole"')
"""Footprint placement type must be set to Through Hole"""

def check(self):
"""
Expand Down
7 changes: 3 additions & 4 deletions pcb/rules/F7_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
"""Footprint anchor should placed at the location of Pin-1"""

def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For through-hole components, footprint anchor is set on pad 1')
super(Rule, self).__init__(module, args)

self.pin1_position = []
self.pin1_count = 0
Expand Down
7 changes: 3 additions & 4 deletions pcb/rules/F7_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
"""Pin 1 should be rectangular, and other pads circular or oval"""

def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad 1 should be denoted by rectangular pad')
super(Rule, self).__init__(module, args)

self.names = ['1', 'A', 'A1', 'P1', 'PAD1']

Expand Down
7 changes: 3 additions & 4 deletions pcb/rules/F7_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
"""Pad requirements for THT footprints"""

def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad requirements for THT footprints')
super(Rule, self).__init__(module, args)

self.required_layers = ["*.Cu","*.Mask"]

Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Annular ring must be at least 0.15mm')
"""Minimum annular ring width"""

def checkPad(self, pad):
if not 'size' in pad['drill']:
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Minimum hole drill size')
"""Minimum hole diameter"""

def checkPad(self, pad):

Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F9_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import os

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Footprint metadata must be filled as appropriate')
"""Footprint meta-data is filled in as appropriate"""

def checkDocs(self):
mod = self.module
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F9_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Footprint properties should be left to default values.')
"""Footprint properties are as default values unless otherwise required in datasheet"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F9_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
SYSMOD_PREFIX = "${KISYS3DMOD}/"

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, '3D model settings')
"""Footprint 3D model requirements"""

def checkModel(self, model):

Expand Down
7 changes: 3 additions & 4 deletions pcb/rules/G1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import re

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
"""Only standard characters are used for naming libraries and components"""

def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Illegal characters in footprint name')
super(Rule, self).__init__(module, args)
# Set of allowed chars. Some characters need to be escaped.
allowed_chars = "a-zA-Z0-9_\-\.,\+"
self.pattern = re.compile('^['+allowed_chars+']+$')
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/G1_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import platform

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Library files must use Unix-style line endings (LF)')
"""Library files use Unix style line endings"""

def check(self):

Expand Down
11 changes: 6 additions & 5 deletions pcb/rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ def graphItemString(graph, layer=False, width=False):
return shapeText + layerText + widthText

class KLCRule(KLCRuleBase):
"""A base class to represent a KLC rule
Create the methods check and fix to use with the kicad_mod files.
"""
A base class to represent a KLC rule
"""
def __init__(self, module, args, description):
def __init__(self, module, args):

KLCRuleBase.__init__(self, description)
KLCRuleBase.__init__(self)

self.module = module
self.args = args
Expand All @@ -99,4 +100,4 @@ def fix(self):
def fixmore(self):
if self.needsFixMore:
self.info("fixmore not supported")
return
return
6 changes: 1 addition & 5 deletions schlib/rules/EC01.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import re

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'General pin number checking')
"""General pin number checking"""

def checkPinNames(self):
self.wrong_pin_numbers = []
Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/EC02.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Check part reference, name and footprint position and alignment')
"""Check part reference, name and footprint position and alignment"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/G1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import string

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Illegal characters in symbol name')
"""Only standard characters are used for naming libraries and components"""

def check(self):

Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/S3_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import math

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Origin is centered on the middle of the symbol')
"""Origin is centered on the middle of the symbol"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/S3_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Text fields should use common size of 50mils, but labels and numbers may use text size as low as 20mil if required')
"""Text fields should use a common text size of 50mils"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/S3_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Symbol outline and fill requirements')
"""Symbol outline and fill requirements"""

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions schlib/rules/S3_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Pin name position offset')
"""Pin name position offset"""

def check(self):

Expand Down
8 changes: 2 additions & 6 deletions schlib/rules/S4_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Pin requirements')
"""General pin requirements"""

def checkPinOrigin(self, gridspacing=100):
self.violating_pins = []
Expand Down Expand Up @@ -131,4 +127,4 @@ def fix(self):
pass

if self.checkPinLength():
pass
pass
6 changes: 1 addition & 5 deletions schlib/rules/S4_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import re

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Pins should be arranged by function')
"""Pins should be grouped by function"""

def checkGroundPins(self):

Expand Down
Loading

0 comments on commit ce445f1

Please sign in to comment.