Skip to content

Commit

Permalink
refactor: Removed defines.py and distributed its contents into approp…
Browse files Browse the repository at this point in the history
…riate files.
  • Loading branch information
devbisme committed Oct 17, 2021
1 parent 90f3368 commit 8b09aa3
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 129 deletions.
1 change: 0 additions & 1 deletion skidl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from .bus import *
from .circuit import *
from .common import *
from .defines import *
from .erc import *
from .interface import *
from .logger import *
Expand Down
11 changes: 6 additions & 5 deletions skidl/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@

from .alias import Alias
from .common import *
from .defines import *
from .logger import logger
from .net import Net
from .net import Net, NET_PREFIX
from .netpinlist import NetPinList
from .pin import Pin
from .skidlbaseobj import SkidlBaseObject
from .utilities import *

# Prefix for implicit buses.
BUS_PREFIX = "B$"


standard_library.install_aliases()


Expand Down Expand Up @@ -183,7 +186,7 @@ def insert(self, index, *objects):

# Assign names to all the unnamed nets in the bus.
# Separate index from bus name if name ends with number.
sep = '_' if self.name[-1].isdigit() else ''
sep = "_" if self.name[-1].isdigit() else ""
for i, net in enumerate(self.nets):
if net.is_implicit():
# Net names are the bus name with the index appended.
Expand Down Expand Up @@ -375,8 +378,6 @@ def is_movable(self):
def is_implicit(self):
"""Return true if the bus name is implicit."""

from .defines import NET_PREFIX, BUS_PREFIX

prefix_re = "({}|{})+".format(re.escape(NET_PREFIX), re.escape(BUS_PREFIX))
return re.match(prefix_re, self.name)

Expand Down
6 changes: 3 additions & 3 deletions skidl/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

from .arrange import Arranger
from .bus import Bus
from .common import *
from .defines import *
from .common import builtins
from .erc import dflt_circuit_erc
from .interface import Interface
from .logger import erc_logger, logger
Expand Down Expand Up @@ -132,7 +131,7 @@ def mini_reset(self, init=False):

def __enter__(self):
"""Create a context for making this circuit the default_circuit."""
self.circuit_stack.append(builtins.default_circuit)
self.circuit_stack.append(default_circuit)
builtins.default_circuit = self
return self

Expand Down Expand Up @@ -1167,6 +1166,7 @@ def backup_parts(self, file_=None):
"""

from . import skidl
from .tools import SKIDL

if self.no_files:
return
Expand Down
8 changes: 3 additions & 5 deletions skidl/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
Stuff everyone needs.
"""

import sys

try:
import __builtin__ as builtins
except ModuleNotFoundError:
import builtins

import sys

USING_PYTHON2 = sys.version_info.major == 2
USING_PYTHON3 = not USING_PYTHON2

if USING_PYTHON2:
# Python 2 doesn't have this exception, so spoof it.
builtins.FileNotFoundError = OSError

if USING_PYTHON3:
else:
# Python 3 doesn't have basestring,
# Python 2 doesn't work with type(''),
# so....
Expand Down
51 changes: 0 additions & 51 deletions skidl/defines.py

This file was deleted.

1 change: 0 additions & 1 deletion skidl/erc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

from future import standard_library

from .defines import *
from .logger import erc_logger

standard_library.install_aliases()
Expand Down
1 change: 1 addition & 0 deletions skidl/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from future import standard_library

from .scriptinfo import get_script_name
from .skidlbaseobj import WARNING

standard_library.install_aliases()

Expand Down
16 changes: 7 additions & 9 deletions skidl/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@

from future import standard_library

from .common import *
from .defines import *
from .erc import dflt_net_erc
from .logger import logger
from .skidlbaseobj import SkidlBaseObject
from .utilities import *

standard_library.install_aliases()

# Prefix for implicit nets.
NET_PREFIX = "N$"

Traversal = collections.namedtuple("Traversal", ["nets", "pins"])

Expand Down Expand Up @@ -72,7 +72,7 @@ def get(cls, name, circuit=None):
from .alias import Alias

if not circuit:
circuit = builtins.default_circuit
circuit = default_circuit

search_params = (("name", name, True), ("aliases", name, True))

Expand All @@ -92,7 +92,7 @@ def get(cls, name, circuit=None):
def fetch(cls, name, *args, **attribs):
"""Get the net with the given name from a circuit, or create it if not found."""

circuit = attribs.get("circuit", builtins.default_circuit)
circuit = attribs.get("circuit", default_circuit)
return cls.get(name, circuit=circuit) or cls(name, *args, **attribs)

def __init__(self, name=None, circuit=None, *pins_nets_buses, **attribs):
Expand All @@ -113,7 +113,7 @@ def __init__(self, name=None, circuit=None, *pins_nets_buses, **attribs):
self._name = name

# Add the net to the passed-in circuit or to the default circuit.
circuit = circuit or builtins.default_circuit
circuit = circuit or default_circuit
circuit += self

# Attach whatever pins were given.
Expand Down Expand Up @@ -262,7 +262,7 @@ def copy(self, num_copies=None, circuit=None, **attribs):

# If circuit is not specified, then create the copies within circuit of the
# original, or in the default circuit.
circuit = circuit or self.circuit or builtins.default_circuit
circuit = circuit or self.circuit or default_circuit

# Can't make a distinct copy of a net which already has pins on it
# because what happens if a pin is connected to the copy? Then we have
Expand Down Expand Up @@ -385,7 +385,7 @@ def __iter__(self):
def is_implicit(self):
"""Return true if the net name is implicit."""

from .defines import NET_PREFIX, BUS_PREFIX
from .bus import BUS_PREFIX

self.test_validity()
prefix_re = "({}|{})+".format(re.escape(NET_PREFIX), re.escape(BUS_PREFIX))
Expand Down Expand Up @@ -751,8 +751,6 @@ def name(self):
@name.setter
def name(self, name):

from .defines import NET_PREFIX

self.test_validity()
# Remove the existing name so it doesn't cause a collision if the
# object is renamed with its existing name.
Expand Down
3 changes: 1 addition & 2 deletions skidl/netclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from future import standard_library

from .common import *
from .logger import logger
from .utilities import *

Expand All @@ -42,7 +41,7 @@ def __init__(self, name, **attribs):

# This object will belong to the default Circuit object or the one
# that's passed as a parameter.
circuit = attribs.pop("circuit", builtins.default_circuit)
circuit = attribs.pop("circuit", default_circuit)

# Assign net class name.
self.name = name
Expand Down
2 changes: 2 additions & 0 deletions skidl/netlist_to_skidl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from future import standard_library
from kinparse import parse_netlist

from .part import TEMPLATE

standard_library.install_aliases()


Expand Down
3 changes: 1 addition & 2 deletions skidl/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@

from .bus import Bus
from .circuit import subcircuit
from .common import *
from .defines import *
from .interface import Interface
from .net import Net
from .part import NETLIST
from .protonet import ProtoNet

standard_library.install_aliases()
Expand Down
Loading

0 comments on commit 8b09aa3

Please sign in to comment.