Skip to content

Commit 8723ea7

Browse files
Merge pull request #10 from railnova/python3.12
add support to python3.12+
2 parents 0b08213 + 031f58d commit 8723ea7

7 files changed

Lines changed: 182 additions & 55 deletions

File tree

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Contributors
33
============
44

55
* Charles-Henri Mousset <chm@railnova.eu>
6+
* Abdellah Azaanoun <abdellah.azaanoun@railnova.eu>

CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
Changelog
33
=========
44

5+
Version 1.0.0
6+
=============
7+
8+
- Added Python 3.12+ support (up to 3.14)
9+
- Replaced deprecated pkg_resources with importlib.metadata
10+
- Modernized setup.py (removed pyscaffold dependency)
11+
- Added explicit Python version classifiers (3.8-3.14)
12+
- Set minimum Python version to 3.8
13+
- Fixed typo in pytest configuration
14+
515
Version 0.1
616
===========
717

README.rst

Lines changed: 118 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,72 @@
22
netlist
33
=============
44

5+
A Python library for parsing and analyzing electronic circuit netlists, with focus on Altium Designer format.
56

6-
Parse Altium designer (and probably other) netlist.
7-
7+
.. image:: https://img.shields.io/pypi/pyversions/netlist.svg
8+
:alt: Python Version Support
89

910
Description
1011
===========
1112

12-
A netlist describes all the electrical connection between then components of a Printed Circuit Board. A typical Altium Designer generated Netlist looks like this::
13+
A netlist describes all the electrical connections between components on a Printed Circuit Board (PCB). This library parses netlists and provides utilities for analyzing connectivity, finding pins, and performing automated checks.
14+
15+
**Supported formats:**
16+
- Altium Designer netlists
17+
- Other similar netlist formats
18+
19+
20+
Installation
21+
============
22+
23+
Install using pip::
24+
25+
pip install netlist
26+
27+
Or for development::
28+
29+
pip install -e .
30+
31+
**Requirements:** Python 3.8 or higher (tested up to Python 3.16)
32+
33+
34+
Quick Start
35+
===========
36+
37+
Basic usage::
38+
39+
from python_netlist import Netlist
40+
41+
# Parse a netlist file
42+
nl = Netlist('my_board.net')
43+
44+
# Check for orphaned nets (nets with <2 connections)
45+
orphans = nl.check_orphans()
46+
47+
# Find pins on a specific net
48+
pins = nl.find_pins('VCC', connector_map)
49+
50+
51+
Features
52+
========
53+
54+
**Net Parsing**
55+
Parse netlist files to extract component connections and signal information.
56+
57+
**Pin Finding**
58+
Map net names to physical connector pins using connector definitions.
59+
60+
**Automated Checks**
61+
Detect common schematic errors like unconnected pins and orphaned nets.
62+
63+
**Command-line Interface**
64+
Analyze netlists directly from the terminal.
65+
66+
67+
Netlist Format
68+
==============
69+
70+
A typical Altium Designer generated netlist looks like this::
1371

1472
Wire List
1573
@@ -31,58 +89,85 @@ A netlist describes all the electrical connection between then components of a P
3189
3290
3391

34-
It contains
35-
1. a very crude BOM (value, designator, package)
36-
2. A list of all signal names and their connection.
92+
The netlist contains:
3793

38-
In this example, 2 components are defined, and 2 nets are defined.
94+
1. A basic BOM (value, designator, package)
95+
2. A list of all signal names and their connections
3996

40-
This module ignores the BOM, and concentrates only on nets.
97+
**Note:** This module focuses on net connectivity and ignores the BOM section.
4198

4299

43-
SOM connection helper
100+
SOM Connection Helper
44101
=====================
45102

46-
On large System On Module, it can be very tedious and error-prone to define the different signal connection in device trees, or in an Hardware Design (for FPGA designs)
103+
For large System On Module (SOM) designs, it can be tedious and error-prone to manually define signal connections in device trees or FPGA hardware designs.
104+
105+
Using the ``find_pins`` function, you can retrieve pin names based on net names.
106+
107+
**Connector Definition Example**
47108

48-
Using to the `find_pins` function, it is possible to retreive pin names from on a net name.
49-
You first have to define your module connectors and pins this way::
109+
Define your module connectors and pins::
50110

51111
pz_pins = {
52-
"JX1" : {
53-
"9" : "R19",
54-
"10" : "T19",
55-
"11" : "T11",
56-
"12" : "T12",
57-
"13" : "T10",
58-
"14" : "U12",
112+
"JX1": {
113+
"9": "R19",
114+
"10": "T19",
115+
"11": "T11",
116+
"12": "T12",
117+
"13": "T10",
118+
"14": "U12",
59119
},
60-
"JX2" : {
61-
"13" : "G14",
62-
"14" : "J15",
63-
"17" : "C20",
64-
"18" : "B19",
120+
"JX2": {
121+
"13": "G14",
122+
"14": "J15",
123+
"17": "C20",
124+
"18": "B19",
65125
},
66126
}
67127

68-
in this example, the SOM has 2 connectors which are seperate parts on the PCB, called "JX1" and "JX2". Pin 9 of connector JX1 is named pin "R19" internally in the SOM.
128+
In this example:
129+
- The SOM has 2 connector parts: ``JX1`` and ``JX2``
130+
- Pin 9 of connector ``JX1`` maps to internal pin ``R19``
69131

70-
This also works on components which have a single part (in this example only the first 2 pins are described)::
132+
**Single-Part Component Example**
71133

72-
stmf32F407_64_pins = {
73-
"1" : "VBAT",
74-
"2" : "PC13",
134+
Works for components with a single part (showing first 2 pins)::
135+
136+
stm32f407_64_pins = {
137+
"1": "VBAT",
138+
"2": "PC13",
75139
}
76140

77141

78142
Automatic Checks
79143
================
80144

81-
Common Schematic capture mistakes can be caught analyzing the Netlist. The most common is probably unconnected pins due to a bad net label.
145+
Catch common schematic capture mistakes by analyzing the netlist.
146+
147+
**Orphan Detection**
82148

83-
`check_orphans` lists all nets that have (by default) less than 2 connections.
149+
The ``check_orphans`` function lists all nets with fewer than 2 connections (configurable), which often indicates connection errors::
84150

85-
Command-line tool
151+
orphans = netlist.check_orphans(min_connections=2)
152+
153+
154+
Command-Line Tool
86155
=================
87156

88-
You can call `python -m netlist` to invoque the command-line tool. Use the built-in help to lear to use it.
157+
Invoke the command-line tool::
158+
159+
python -m netlist --help
160+
161+
Use the built-in help to learn about available commands and options.
162+
163+
164+
License
165+
=======
166+
167+
MIT License - see LICENSE.txt for details
168+
169+
170+
Links
171+
=====
172+
173+
* Repository: https://github.com/chmousset/python-netlist

setup.cfg

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,44 @@
44

55
[metadata]
66
name = netlist
7+
version = 1.0.0
78
description = Netlist parser
89
author = Charles-Henri Mousset
910
author_email = chm@railnova.eu
10-
license = mit
11+
license = MIT
1112
long_description = file: README.rst
1213
long_description_content_type = text/x-rst; charset=UTF-8
1314
url = https://github.com/chmousset/python-netlist
1415
project_urls =
15-
Documentation =
16+
Documentation = # TBD
1617
# Change if running only on Windows, Mac or Linux (comma-separated)
1718
platforms = any
1819
# Add here all kinds of additional classifiers as defined under
1920
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
2021
classifiers =
2122
Development Status :: 4 - Beta
2223
Programming Language :: Python
24+
Programming Language :: Python :: 3
25+
Programming Language :: Python :: 3.8
26+
Programming Language :: Python :: 3.9
27+
Programming Language :: Python :: 3.10
28+
Programming Language :: Python :: 3.11
29+
Programming Language :: Python :: 3.12
30+
Programming Language :: Python :: 3.13
31+
Programming Language :: Python :: 3.14
2332

2433
[options]
2534
zip_safe = False
2635
packages = find:
2736
include_package_data = True
2837
package_dir =
2938
=src
30-
# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
31-
setup_requires = pyscaffold>=3.2a0,<3.3a0
3239
# Add here dependencies of your project (semicolon/line-separated), e.g.
3340
# install_requires = numpy; scipy
3441
# The usage of test_requires is discouraged, see `Dependency Management` docs
3542
# tests_require = pytest; pytest-cov
3643
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
37-
# python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*
44+
python_requires = >=3.8
3845

3946
[options.packages.find]
4047
where = src
@@ -72,7 +79,7 @@ extras = True
7279
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
7380
# in order to write a coverage file that can be read by Jenkins.
7481
addopts =
75-
--cov pyton_netlist --cov-report term-missing
82+
--cov python_netlist --cov-report term-missing
7683
--verbose
7784
norecursedirs =
7885
dist
@@ -85,7 +92,7 @@ dists = bdist_wheel
8592

8693
[bdist_wheel]
8794
# Use this option if your package is pure-python
88-
universal = 1
95+
universal = 0
8996

9097
[build_sphinx]
9198
source_dir = docs

setup.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@
77
PyScaffold helps you to put up the scaffold of your new Python project.
88
Learn more under: https://pyscaffold.org/
99
"""
10-
import sys
11-
12-
from pkg_resources import VersionConflict, require
1310
from setuptools import setup
1411

15-
try:
16-
require('setuptools>=38.3')
17-
except VersionConflict:
18-
print("Error: version of setuptools is too old (<38.3)!")
19-
sys.exit(1)
20-
2112

2213
if __name__ == "__main__":
23-
setup(use_pyscaffold=True)
14+
setup()

src/python_netlist/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# -*- coding: utf-8 -*-
2-
from pkg_resources import get_distribution, DistributionNotFound
2+
try:
3+
from importlib.metadata import version, PackageNotFoundError
4+
except ImportError:
5+
# Python < 3.8
6+
from importlib_metadata import version, PackageNotFoundError
37

48
try:
59
# Change here if project is renamed and does not equal the package name
610
dist_name = 'netlist'
7-
__version__ = get_distribution(dist_name).version
8-
except DistributionNotFound:
11+
__version__ = version(dist_name)
12+
except PackageNotFoundError:
913
__version__ = 'unknown'
10-
finally:
11-
del get_distribution, DistributionNotFound

src/python_netlist/__main__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Allow running the module with: python -m python_netlist
5+
"""
6+
import argparse
7+
from pprint import pprint
8+
from .netlist import Netlist
9+
10+
11+
def main():
12+
parser = argparse.ArgumentParser(description='Netlist tool')
13+
parser.add_argument('--out', type=str, help='JSON output file')
14+
parser.add_argument('--no-checks', default=False, action='store_true',
15+
help="Don't perform checks")
16+
parser.add_argument('file', help="Netlist")
17+
args = parser.parse_args()
18+
19+
print("...Parsing " + args.file + "...")
20+
netlist = Netlist(args.file)
21+
if not args.no_checks:
22+
print("###### Check Orphans ######")
23+
orphans = netlist.check_orphans()
24+
if len(orphans):
25+
print("## Possible orphans:")
26+
pprint(orphans)
27+
exit(1)
28+
29+
30+
if __name__ == '__main__':
31+
main()

0 commit comments

Comments
 (0)