From a897b77f5e3e544868b0af5fd985705d89d3715e Mon Sep 17 00:00:00 2001 From: Simon-Olivier Morneau Date: Tue, 14 Jun 2022 16:52:31 +0200 Subject: [PATCH 1/2] Rename pyton_netlist directory, add error exit codes --- docs/conf.py | 4 ++-- setup.cfg | 4 ++-- setup.py | 2 +- src/{pyton_netlist => python_netlist}/__init__.py | 0 src/{pyton_netlist => python_netlist}/netlist.py | 12 ++++++++++-- tests/conftest.py | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) rename src/{pyton_netlist => python_netlist}/__init__.py (100%) rename src/{pyton_netlist => python_netlist}/netlist.py (92%) mode change 100644 => 100755 diff --git a/docs/conf.py b/docs/conf.py index fb6d121..e4e30d4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,7 +35,7 @@ from sphinx import apidoc output_dir = os.path.join(__location__, "api") -module_dir = os.path.join(__location__, "../src/pyton_netlist") +module_dir = os.path.join(__location__, "../src/python_netlist") try: shutil.rmtree(output_dir) except FileNotFoundError: @@ -216,7 +216,7 @@ # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'pyton_netlist-doc' +htmlhelp_basename = 'python_netlist-doc' # -- Options for LaTeX output -------------------------------------------------- diff --git a/setup.cfg b/setup.cfg index 4748d30..a976330 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,10 +53,10 @@ testing = [options.entry_points] # Add here console scripts like: # console_scripts = -# script_name = pyton_netlist.module:function +# script_name = python_netlist.module:function # For example: # console_scripts = -# fibonacci = pyton_netlist.skeleton:run +# fibonacci = python_netlist.skeleton:run # And any other entry points, for example: # pyscaffold.cli = # awesome = pyscaffoldext.awesome.extension:AwesomeExtension diff --git a/setup.py b/setup.py index ace7c92..d864eb3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ - Setup file for pyton_netlist. + Setup file for python_netlist. Use setup.cfg to configure your project. This file was generated with PyScaffold 3.2.3. diff --git a/src/pyton_netlist/__init__.py b/src/python_netlist/__init__.py similarity index 100% rename from src/pyton_netlist/__init__.py rename to src/python_netlist/__init__.py diff --git a/src/pyton_netlist/netlist.py b/src/python_netlist/netlist.py old mode 100644 new mode 100755 similarity index 92% rename from src/pyton_netlist/netlist.py rename to src/python_netlist/netlist.py index b688c73..295b0ff --- a/src/pyton_netlist/netlist.py +++ b/src/python_netlist/netlist.py @@ -1,12 +1,15 @@ +#!/usr/bin/env python3 # Copyright 2020 Railnova SA # Author: Charles-Henri Mousset # # Netlist parsing for filling platform ios from pprint import pprint + class Netlist: """A netlist is a dict of all the nets (signals) on a PCB, and of all its connections to the different components of that board.""" + def __init__(self, path): self.path = path netlist = {} @@ -27,7 +30,7 @@ def __init__(self, path): while len(txt[i]) > 4: l = txt[i].strip() tok = l.split() - net_conns.update({tok[0] : tok[1]}) + net_conns.update({tok[0]: tok[1]}) i += 1 netlist.update({net_name: net_conns}) i += 1 @@ -62,10 +65,13 @@ def find_pins(self, nets, con_to_pin, ignore_missing=False): def check_orphands(self, min_pins=2): """return a list of nets that have less than min_pins connections""" netlist = self.netlist - return {n: netlist[n] for n in netlist if len(netlist[n]) < min_pins and not (n.startswith('NC_') or ('.NC_' in n))} + return {n: netlist[n] for n in netlist if + len(netlist[n]) < min_pins and not (n.startswith('NC_') or ('.NC_' in n))} + if __name__ == '__main__': import argparse + parser = argparse.ArgumentParser(description='Netlist tool') parser.add_argument('--out', type=str, help='JSON output file') parser.add_argument('--no-checks', default=False, action='store_true', @@ -81,10 +87,12 @@ def check_orphands(self, min_pins=2): if len(orphands): print("## Possible orphands:") pprint(orphands) + exit(1) else: print("No orphands: OK") if args.out: import json + with open(args.out, 'w') as f: json.dump(netlist.netlist, f) diff --git a/tests/conftest.py b/tests/conftest.py index 5a9e8e0..a5a50d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ - Dummy conftest.py for pyton_netlist. + Dummy conftest.py for python_netlist. If you don't know what this is for, just leave it empty. Read more about conftest.py under: From 64efa6f776ddeaf682ff713959a87c29454a2723 Mon Sep 17 00:00:00 2001 From: Simon-Olivier Morneau Date: Wed, 15 Jun 2022 12:59:42 +0200 Subject: [PATCH 2/2] Fix typo s%/orphand/orphan/g --- README.rst | 2 +- src/python_netlist/netlist.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index f3c98e1..ae86780 100644 --- a/README.rst +++ b/README.rst @@ -80,7 +80,7 @@ Automatic Checks Common Schematic capture mistakes can be caught analyzing the Netlist. The most common is probably unconnected pins due to a bad net label. -`check_orphands` lists all nets that have (by default) less than 2 connections. +`check_orphans` lists all nets that have (by default) less than 2 connections. Command-line tool ================= diff --git a/src/python_netlist/netlist.py b/src/python_netlist/netlist.py index 295b0ff..8a8fcd8 100755 --- a/src/python_netlist/netlist.py +++ b/src/python_netlist/netlist.py @@ -62,7 +62,7 @@ def find_pins(self, nets, con_to_pin, ignore_missing=False): raise Exception("net {} has no associated pin!".format(n)) return " ".join(balls) - def check_orphands(self, min_pins=2): + def check_orphans(self, min_pins=2): """return a list of nets that have less than min_pins connections""" netlist = self.netlist return {n: netlist[n] for n in netlist if @@ -82,14 +82,14 @@ def check_orphands(self, min_pins=2): print("...Parsing " + args.file + "...") netlist = Netlist(args.file) if not args.no_checks: - print("###### Check Orphands ######") - orphands = netlist.check_orphands() - if len(orphands): - print("## Possible orphands:") - pprint(orphands) + print("###### Check Orphans ######") + orphans = netlist.check_orphans() + if len(orphans): + print("## Possible orphans:") + pprint(orphans) exit(1) else: - print("No orphands: OK") + print("No orphans: OK") if args.out: import json