Skip to content

Commit 9ec718f

Browse files
committed
Switch from relative imports to absolute imports. Absolute imports appears to be best practice, and relative imports seem to interfere with doctest.
1 parent af2eee4 commit 9ec718f

16 files changed

Lines changed: 110 additions & 122 deletions

pyrtl/analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import sys
1313
import collections
1414

15-
from .core import working_block
16-
from .wire import Input, Output, Const, Register, WireVector
17-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
18-
from .importexport import output_to_verilog
19-
from .memory import RomBlock
20-
from .helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
15+
from pyrtl.core import working_block
16+
from pyrtl.wire import Input, Output, Const, Register, WireVector
17+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
18+
from pyrtl.importexport import output_to_verilog
19+
from pyrtl.memory import RomBlock
20+
from pyrtl.helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
2121

2222

2323
# --------------------------------------------------------------------

pyrtl/compilesim.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import _ctypes
1111
from collections.abc import Mapping
1212

13-
from .core import working_block, Block
14-
from .wire import Input, Output, Const, WireVector, Register
15-
from .memory import MemBlock, RomBlock
16-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
17-
from .simulation import SimulationTrace, _trace_sort_key
18-
from .helperfuncs import infer_val_and_bitwidth
13+
from pyrtl.core import working_block, Block
14+
from pyrtl.wire import Input, Output, Const, WireVector, Register
15+
from pyrtl.memory import MemBlock, RomBlock
16+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
17+
from pyrtl.simulation import SimulationTrace, _trace_sort_key
18+
from pyrtl.helperfuncs import infer_val_and_bitwidth
1919

2020

2121
__all__ = ['CompiledSimulation']

pyrtl/conditional.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def make_adder(x: pyrtl.WireVector) -> pyrtl.WireVector:
162162
# Use the objects "conditional_assignment" and "otherwise" as described above. The
163163
# classes below are internal implementation details.
164164

165-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
166-
from .wire import WireVector, Const, Register
165+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
166+
from pyrtl.wire import WireVector, Const, Register
167167

168168

169169
# -----------------------------------------------------------------------
@@ -320,7 +320,7 @@ def _pred_sets_are_in_conflict(pred_set_a, pred_set_b):
320320

321321
def _finalize(defaults):
322322
"""Build the required muxes and call back to WireVector to finalize the wirevector build."""
323-
from .memory import MemBlock
323+
from pyrtl.memory import MemBlock
324324
from pyrtl.corecircuits import select
325325
for lhs in _predicate_map:
326326
# handle memory write ports

pyrtl/core.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@
1010
"""
1111
from __future__ import annotations
1212

13-
from typing import TYPE_CHECKING
14-
15-
if TYPE_CHECKING:
16-
from .wire import WireVector, Register
17-
from .memory import MemBlock
18-
1913
import collections
2014
import re
2115
import keyword
22-
from typing import NamedTuple
16+
from typing import NamedTuple, TYPE_CHECKING
2317

24-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
18+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
19+
20+
if TYPE_CHECKING:
21+
from pyrtl.wire import WireVector, Register
22+
from pyrtl.memory import MemBlock
2523

2624

2725
# -----------------------------------------------------------------
2826
# __ __ __
2927
# |__) | / \ / ` |__/
3028
# |__) |___ \__/ \__, | \
3129
#
32-
3330
class LogicNet(NamedTuple):
3431
"""The basic immutable datatype for storing a "net" in a netlist.
3532
@@ -147,7 +144,7 @@ def __str__(self):
147144
lhs = ', '.join(str(x) for x in self.dests)
148145
options = '' if self.op_param is None else '(' + str(self.op_param) + ')'
149146

150-
from .helperfuncs import _currently_in_jupyter_notebook
147+
from pyrtl.helperfuncs import _currently_in_jupyter_notebook
151148

152149
if _currently_in_jupyter_notebook():
153150
# Output the working block as a Latex table
@@ -349,7 +346,7 @@ def __init__(self):
349346

350347
def __str__(self):
351348
"""String form has one LogicNet per line."""
352-
from .helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
349+
from pyrtl.helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
353350

354351
if _currently_in_jupyter_notebook():
355352
_print_netlist_latex(list(self))
@@ -517,7 +514,7 @@ class _NetConnectionsDict(dict):
517514
nice error message when _MemIndexed is used as a lookup key.
518515
"""
519516
def __missing__(self, key):
520-
from .memory import _MemIndexed
517+
from pyrtl.memory import _MemIndexed
521518

522519
if isinstance(key, _MemIndexed):
523520
raise PyrtlError(
@@ -572,7 +569,7 @@ def add_wire_dst(edge, node):
572569
dst_list[edge] = [node]
573570

574571
if include_virtual_nodes:
575-
from .wire import Input, Output, Const
572+
from pyrtl.wire import Input, Output, Const
576573
for wire in self.wirevector_subset((Input, Const)):
577574
add_wire_src(wire, wire)
578575

@@ -589,7 +586,7 @@ def add_wire_dst(edge, node):
589586

590587
def _repr_svg_(self):
591588
""" IPython display support for Block. """
592-
from .visualization import block_to_svg
589+
from pyrtl.visualization import block_to_svg
593590
return block_to_svg(self)
594591

595592
def __iter__(self):
@@ -602,7 +599,7 @@ def __iter__(self):
602599
Also, the order of the nets is not guaranteed to be the same
603600
over multiple iterations.
604601
"""
605-
from .wire import Input, Const, Register
602+
from pyrtl.wire import Input, Const, Register
606603
src_dict, dest_dict = self.net_connections()
607604
to_clear = self.wirevector_subset((Input, Const, Register))
608605
cleared = set()
@@ -634,9 +631,8 @@ def sanity_check(self):
634631
635632
:raise PyrtlError: If the ``Block`` is malformed.
636633
"""
637-
638-
from .wire import Input, Const, Output
639-
from .helperfuncs import get_stack, get_stacks
634+
from pyrtl.wire import Input, Const, Output
635+
from pyrtl.helperfuncs import get_stack, get_stacks
640636

641637
# check for valid LogicNets (and wires)
642638
for net in self.logic:
@@ -734,7 +730,7 @@ def sanity_check_memory_sync(self, wire_src_dict=None):
734730
if wire_src_dict is None:
735731
wire_src_dict, wdd = self.net_connections()
736732

737-
from .wire import Input, Const
733+
from pyrtl.wire import Input, Const
738734
sync_src = 'r'
739735
sync_prop = 'wcs'
740736
for net in sync_mems:
@@ -756,24 +752,24 @@ def sanity_check_memory_sync(self, wire_src_dict=None):
756752

757753
def sanity_check_wirevector(self, w):
758754
""" Check that w is a valid WireVector type. """
759-
from .wire import WireVector
755+
from pyrtl.wire import WireVector
760756
if not isinstance(w, WireVector):
761757
raise PyrtlError(
762758
'error attempting to pass an input of type "%s" '
763759
'instead of WireVector' % type(w))
764760

765761
def sanity_check_memblock(self, m):
766762
""" Check that m is a valid memblock type. """
767-
from .memory import MemBlock
763+
from pyrtl.memory import MemBlock
768764
if not isinstance(m, MemBlock):
769765
raise PyrtlError(
770766
'error attempting to pass an input of type "%s" '
771767
'instead of MemBlock' % type(m))
772768

773769
def sanity_check_net(self, net):
774770
""" Check that net is a valid LogicNet. """
775-
from .wire import Input, Output, Const, Register
776-
from .memory import MemBlock
771+
from pyrtl.wire import Input, Output, Const, Register
772+
from pyrtl.memory import MemBlock
777773

778774
# general sanity checks that apply to all operations
779775
if not isinstance(net, LogicNet):

pyrtl/corecircuits.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import math
55
from typing import Union
66

7-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
8-
from .core import Block, LogicNet, working_block
9-
from .wire import Const, WireVector, WireVectorLike, WrappedWireVector
10-
from pyrtl.rtllib import barrel
11-
from pyrtl.rtllib import muxes
12-
from .conditional import otherwise
7+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
8+
from pyrtl.core import Block, LogicNet, working_block
9+
from pyrtl.wire import Const, WireVector, WireVectorLike, WrappedWireVector
10+
from pyrtl.rtllib import barrel, muxes
11+
from pyrtl.conditional import otherwise
1312

1413

1514
def mux(index: WireVectorLike, *mux_ins: WireVector,
@@ -476,7 +475,7 @@ def myhardware(input_a, input_b):
476475
be dropped).
477476
:param block: ``Block`` to use for the returned ``WireVector``.
478477
"""
479-
from .memory import _MemIndexed
478+
from pyrtl.memory import _MemIndexed
480479
block = working_block(block)
481480

482481
if isinstance(val, (int, str)):
@@ -542,7 +541,7 @@ def bitfield_update(w: WireVectorLike, range_start: int, range_end: int, newvalu
542541
543542
:return: ``w`` with some of the bits overwritten by ``newvalue``.
544543
"""
545-
from .corecircuits import concat_list
544+
from pyrtl.corecircuits import concat_list
546545

547546
w = as_wires(w)
548547
idxs = list(range(len(w))) # we make a list of integers and slice those up to use as indexes

pyrtl/helperfuncs.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@
1010
from functools import reduce
1111
from typing import Union, NamedTuple
1212

13-
from .core import working_block, _NameIndexer, _get_debug_mode, Block
14-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
15-
from .wire import WireVector, Input, Output, Const, Register, WrappedWireVector
16-
from .corecircuits import (
17-
as_wires,
18-
rtl_all,
19-
rtl_any,
20-
concat,
21-
concat_list,
22-
select,
23-
shift_left_logical
24-
)
13+
from pyrtl.core import working_block, _NameIndexer, _get_debug_mode, Block
14+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
15+
from pyrtl.wire import WireVector, Input, Output, Const, Register, WrappedWireVector
16+
from pyrtl.corecircuits import (
17+
as_wires, rtl_all, rtl_any, concat, concat_list, select, shift_left_logical)
2518

2619
# -----------------------------------------------------------------
2720
# ___ __ ___ __ __
@@ -187,12 +180,12 @@ class MatchedFields(NamedTuple):
187180
"""``NamedTuple`` containing the matched fields, if any."""
188181

189182
def __enter__(self):
190-
from .conditional import _push_condition
183+
from pyrtl.conditional import _push_condition
191184
_push_condition(self.matched)
192185
return self.fields
193186

194187
def __exit__(self, *execinfo):
195-
from .conditional import _pop_condition
188+
from pyrtl.conditional import _pop_condition
196189
_pop_condition()
197190

198191

pyrtl/importexport.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import operator
1919
import typing
2020

21-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
22-
from .core import working_block, _NameSanitizer, Block
23-
from .wire import WireVector, Input, Output, Const, Register, next_tempvar_name
24-
from .corecircuits import concat_list, rtl_all, rtl_any, select
25-
from .memory import RomBlock
26-
from .passes import two_way_concat, one_bit_selects
21+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
22+
from pyrtl.core import working_block, _NameSanitizer, Block
23+
from pyrtl.wire import WireVector, Input, Output, Const, Register, next_tempvar_name
24+
from pyrtl.corecircuits import concat_list, rtl_all, rtl_any, select
25+
from pyrtl.memory import RomBlock
26+
from pyrtl.passes import two_way_concat, one_bit_selects
2727

2828

2929
def _natural_sort_key(key):

pyrtl/memory.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import collections
1616

17-
from .pyrtlexceptions import PyrtlError
18-
from .core import working_block, LogicNet, _NameIndexer, Block
19-
from .wire import WireVector, Const, next_tempvar_name
20-
from .corecircuits import as_wires
21-
from .helperfuncs import infer_val_and_bitwidth
17+
from pyrtl.pyrtlexceptions import PyrtlError
18+
from pyrtl.core import working_block, LogicNet, _NameIndexer, Block
19+
from pyrtl.wire import WireVector, Const, next_tempvar_name
20+
from pyrtl.corecircuits import as_wires
21+
from pyrtl.helperfuncs import infer_val_and_bitwidth
2222
# ------------------------------------------------------------------------
2323
#
2424
# ___ __ __ __ __ __
@@ -257,7 +257,7 @@ def _build_read_port(self, addr):
257257
return data
258258

259259
def _assignment(self, item, val, is_conditional):
260-
from .conditional import _build
260+
from pyrtl.conditional import _build
261261

262262
# Even though as_wires is already called on item already in the __getitem__ method,
263263
# we need to call it again here because __setitem__ passes the original item

pyrtl/passes.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
import collections
88

9-
from .core import working_block, set_working_block, _get_debug_mode, LogicNet, PostSynthBlock
10-
from .helperfuncs import _NetCount
11-
from .corecircuits import (_basic_mult, _basic_add, _basic_sub, _basic_eq,
12-
_basic_lt, _basic_gt, _basic_select, concat_list,
13-
as_wires, concat)
14-
from .memory import MemBlock
15-
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
16-
from .wire import WireVector, Input, Output, Const, Register
17-
from .transform import net_transform, _get_new_block_mem_instance, copy_block, replace_wires
18-
from . import transform
19-
from pyrtl import wire # transform.all_nets looks better than all_nets
9+
from pyrtl.core import (
10+
working_block, set_working_block, _get_debug_mode, LogicNet, PostSynthBlock)
11+
from pyrtl.helperfuncs import _NetCount
12+
from pyrtl.corecircuits import (
13+
_basic_mult, _basic_add, _basic_sub, _basic_eq, _basic_lt, _basic_gt, _basic_select,
14+
concat_list, as_wires, concat)
15+
from pyrtl.memory import MemBlock
16+
from pyrtl.pyrtlexceptions import PyrtlError, PyrtlInternalError
17+
from pyrtl.wire import WireVector, Input, Output, Const, Register
18+
from pyrtl.transform import (
19+
net_transform, _get_new_block_mem_instance, copy_block, replace_wires)
20+
from pyrtl import transform # transform.all_nets looks better than all_nets
2021

2122

2223
# --------------------------------------------------------------------
@@ -1017,7 +1018,7 @@ def two_way_fanout(block=None):
10171018
10181019
:param block: block to update (defaults to working block)
10191020
"""
1020-
from .analysis import fanout
1021+
from pyrtl.analysis import fanout
10211022
block = working_block(block)
10221023

10231024
_, dst_map = block.net_connections()

pyrtl/rtllib/adders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22

33
import pyrtl
4-
from . import libutils
4+
from pyrtl.rtllib import libutils
55

66

77
def kogge_stone(a, b, cin=0):

0 commit comments

Comments
 (0)