Skip to content

Commit

Permalink
merge with next release
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdbrown4 committed Aug 21, 2023
2 parents 9b49fc0 + 2c0cdc0 commit 5d93d96
Show file tree
Hide file tree
Showing 216 changed files with 250 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
env:
EXAMPLE_NETLISTS_PATH: ${{ github.workspace }}/example_netlists/
steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -23,4 +25,4 @@ jobs:
- name: Run Pytest for SpyDrNet
uses: cclauss/GitHub-Action-for-pytest@master
with:
args: python -m pytest -v
args: python3 -m pytest -v
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SpyDrNet can be used to create netlists from scratch. Because it is a low-level

**Loading Example Netlists**

Several example netlists are included with the package to introduce the framework, its features, and functionality. To list and load these netlists, modify the following example:
Several example netlists are included in the repository to introduce the framework, its features, and functionality. To list and load these netlists, see the :ref:`using_example_netlists` page and then run the following:

.. code:: python
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ SpyDrNet 1.12.2
----------------
April 18, 2023

Bug fix for Verilog parser for partially connected ports being misaligned and fixed primitive name with a space at the end.
Changed some of the os.path to pathlib to conform to updated coding standards
* Bug fix for Verilog parser for partially connected ports being misaligned and fixed primitive name with a space at the end.
* Changed some of the os.path to pathlib to conform to updated coding standards

SpyDrNet 1.12.1
----------------
Expand Down
12 changes: 5 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys

sys.path.insert(0, os.path.abspath("../.."))
import pathlib
sys.path.insert(0,os.path.abspath('../..'))
import spydrnet as sdn

# import sphinxgallery
Expand Down Expand Up @@ -217,11 +217,9 @@
# -- Options for Sphinx-Gallery ----------------------------------------------

sphinx_gallery_conf = {
"examples_dirs": os.path.join(
"..", "..", "examples"
), # path to your example scripts
"gallery_dirs": "auto_examples", # path to where to save gallery generated output
"remove_config_comments": True,
'examples_dirs': pathlib.Path('..').joinpath('..', 'examples'), # path to your example scripts
'gallery_dirs': 'auto_examples', # path to where to save gallery generated output
'remove_config_comments': True
}

# -- Extension configuration -------------------------------------------------
6 changes: 3 additions & 3 deletions docs/source/developer/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This section aims to help you do a spydrnet release, meaning you make the latest
4. :ref:`update_documentation` and ensure it can build properly
5. On Github, create a pull request with the updated code in the next_release branch.
6. Accept and merge the pull request when the checks have finished.
7. Move to the master branch using `git checkout master`
7. Move to the master branch using `git checkout master` and run `git pull`
8. :ref:`create_and_update_tag`
9. :ref:`build_package` (this will update the documentation's version number)
10. :ref:`build_documentation`
Expand Down Expand Up @@ -103,9 +103,9 @@ Upgrade pip if needed.

Make sure everything is up to date

>>> python3 -m pip install --user --upgrade setuptools wheel
>>> python3 -m pip install --upgrade setuptools wheel

Make the python archive package:
Make sure you are in the top level directory. Make the python archive package:

>>> python3 setup.py sdist bdist_wheel

Expand Down
2 changes: 1 addition & 1 deletion docs/source/overview/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ write_blackbox

write_eblif_cname

- Flag
- Flag used for eblif (Yosys to F4PGA)

defparam

Expand Down
2 changes: 1 addition & 1 deletion docs/source/overview/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Or the following for a Verilog file
netlist = sdn.parse('<netlist_filename>.v')
SpyDrNet has built in example netlists. For this tutorial, we will use the example 'one_counter'. This is the same as if we parsed a netlist named 'one_counter'.
The SpyDrNet repo has example netlists. For this tutorial, we will use the example 'one_counter'. This is the same as if we parsed a netlist named 'one_counter'. Review the :ref:`using_example_netlists` page for help loading example netlists.

.. code-block::
Expand Down
1 change: 1 addition & 0 deletions docs/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Reference
:maxdepth: 2

classes/index.rst
using_example_netlists
netlist_types
built_in_architecture
functions/index
Expand Down
58 changes: 58 additions & 0 deletions docs/source/reference/using_example_netlists.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. _using_example_netlists:

Using SpyDrNet Example Netlists
----------------------------------

Many EDIF, Verilog, and EBLIF example netlists are found in the SpyDrNet repo under *example_netlists*. In versions of SpyDrNet previous to 1.13, the example netlists were included in the python package. From version 1.13 on, perform the steps below to access the example netlists using *sdn.load_example_netlist_by_name(<name>)*.

Option 1
^^^^^^^^^

1. Download the `example netlists directory <https://github.com/byuccl/spydrnet/tree/move_tests_and_files/example_netlists>`_ from the `SpyDrNet repo <https://github.com/byuccl/spydrnet>`_, or just clone the repo.

2. In the Linux terminal, run

.. code-block::
export EXAMPLE_NETLISTS_PATH=<path to example netlists>
where the <path to example netlists> is the path to the top level example netlists directory in the spydrnet repo.

3. Use the *sdn.load_example_netlist_by_name(<name>)* to access the example netlist. For example:

.. code-block::
import spydrnet as sdn
netlist = sdn.load_example_netlist_by_name("b13")
Option 2
^^^^^^^^^

Run the following code and type 'y' and then hit enter when asked whether or not to download the example netlists.

.. code-block::
import spydrnet as sdn
netlist = sdn.load_example_netlist_by_name(<name>)
Additional Information
^^^^^^^^^^^^^^^^^^^^^^^

It is possible to see the names of the example netlists for each netlist format

.. code-block::
print(sdn.example_netlist_names) # lists the names of the EDIF example netlists
print(sdn.verilog_example_netlist_names) # lists the names of the Verilog example netlists
print(sdn.eblif_example_netlist_names) # lists the names of the EBLIF example netlists
By default, sdn.load_example_netlist_by_name() assumes the netlists is EDIF format. To load a Verilog or EBLIF example netlist, do the following:

.. code-block::
import spydrnet as sdn
from spydrnet.util.netlist_type import VERILOG, EBLIF
verilog_example_netlist = sdn.load_example_netlist_by_name(name, VERILOG)
eblif_example_netlist = sdn.load_example_netlist_by_name(name, EBLIF)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import setuptools
import glob
import os
from pathlib import Path

if sys.argv[-1] == "setup.py":
print("To install, run 'python setup.py install'")
Expand All @@ -25,11 +24,11 @@
long_description = fh.read().replace(':ref:','')

support_files = list()
folder_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "spydrnet", "support_files"))
for filename in glob.glob(os.path.join(folder_path, "**", "*"), recursive=True):
if os.path.isfile(filename) and \
(os.path.getsize(filename) < 1024 * 10 or "architecture_libraries" in filename):
support_files.append("support_files/" + str(filename)[len(folder_path) + 1:].replace('\\', '/'))
folder_path = Path(Path(__file__).parent).joinpath("spydrnet", "support_files")
for filename in Path.glob(folder_path, "**/*"):
if filename.is_file() and \
(filename.stat().st_size < 1024 * 10 or "architecture_libraries" in str(filename)):
support_files.append("support_files/" + str(filename)[len(str(folder_path)) + 1:].replace('\\', '/'))

extras_require = {
"all": [
Expand Down
84 changes: 61 additions & 23 deletions spydrnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pathlib
import pkgutil
import sys
from pathlib import Path

# ===================
# Setup Logging
Expand Down Expand Up @@ -57,11 +58,11 @@ def enable_file_logging(LOG_LEVEL=None):
def get_active_plugins():
active_plugins = {}
config_file = None
config_file_home = os.path.join(str(pathlib.Path.home()), ".spydrnet")
if os.path.isfile(config_file_home):
config_file_home = Path(str(pathlib.Path.home()), ".spydrnet")
if Path(config_file_home).is_file():
config_file = config_file_home
config_file_local = os.path.join(".", ".spydrnet")
if os.path.isfile(config_file_local):
config_file_local = Path(".", ".spydrnet")
if Path(config_file_local).is_file():
config_file = config_file_local
if config_file:
for plugin in open(config_file, "r").read().split():
Expand Down Expand Up @@ -99,8 +100,6 @@ def get_active_plugins():
INOUT = Port.Direction.INOUT
UNDEFINED = Port.Direction.UNDEFINED

import os

from spydrnet.composers import compose
from spydrnet.parsers import parse
from spydrnet.plugins import namespace_manager
Expand All @@ -112,38 +111,77 @@ def get_active_plugins():
from spydrnet.util.selection import ALL, BOTH, INSIDE, OUTSIDE
from spydrnet.util.netlist_type import EDIF, VERILOG, EBLIF

base_dir = os.path.dirname(os.path.abspath(__file__))

import glob
def determine_example_netlists_path(download_option):
example_netlists_path = pathlib.Path("example_netlists")
temp_dir_loc = pathlib.Path("/tmp/spydrnet_example_netlists/spydrnet-move_tests_and_files/example_netlists/")
if "EXAMPLE_NETLISTS_PATH" in os.environ:
example_netlists_path = pathlib.Path(os.environ["EXAMPLE_NETLISTS_PATH"])
elif temp_dir_loc.exists():
example_netlists_path = temp_dir_loc
else:
None

if not example_netlists_path.exists() and download_option:
print("Could not find example netlists. Download to /tmp/spydrnet_example_netlists? y/n")
response = input()
if response == "y":
print("Downloading example netlists...")

import requests
url = "https://github.com/byuccl/spydrnet/archive/refs/heads/move_tests_and_files.zip"
filename = pathlib.Path('/tmp/spydrnet_temp.zip')
response = requests.get(url)
filename.write_bytes(response.content)

import zipfile
extract_loc = "/tmp/spydrnet_example_netlists"
with zipfile.ZipFile(filename, 'r') as zip_ref:
zip_ref.extractall(extract_loc)
env_variable = extract_loc + "/spydrnet-move_tests_and_files/example_netlists/"
os.environ["EXAMPLE_NETLISTS_PATH"] = env_variable
print("Example netlists located in " + os.environ["EXAMPLE_NETLISTS_PATH"])
example_netlists_path = temp_dir_loc

example_netlists_path = example_netlists_path.resolve()
return example_netlists_path

example_netlists_path = determine_example_netlists_path(False)

base_dir = Path(Path(__file__).absolute()).parent

example_netlist_names = list()
for filename in glob.glob(os.path.join(base_dir, 'support_files', 'EDIF_netlists', "*")):
basename = os.path.basename(filename)
edif_path = Path(example_netlists_path).joinpath('EDIF_netlists')
for filename in Path.glob(edif_path, "*"):
basename = Path(filename).name
example_netlist_names.append(basename[:basename.index('.')])
example_netlist_names.sort()

verilog_example_netlist_names = list()
for filename in glob.glob(os.path.join(base_dir, 'support_files', 'verilog_netlists', "*")):
basename = os.path.basename(filename)
verilog_path = Path(example_netlists_path).joinpath('verilog_netlists')
for filename in Path.glob(verilog_path, "*"):
basename = Path(filename).name
verilog_example_netlist_names.append(basename[:basename.index('.')])
verilog_example_netlist_names.sort()

eblif_example_netlist_names = list()
for filename in glob.glob(os.path.join(base_dir, 'support_files', 'eblif_netlists', "*")):
basename = os.path.basename(filename)
eblif_path = Path(example_netlists_path).joinpath('eblif_netlists')
for filename in Path.glob(eblif_path, "*"):
basename = Path(filename).name
eblif_example_netlist_names.append(basename[:basename.index('.')])
eblif_example_netlist_names.sort()

def load_example_netlist_by_name(name, format=EDIF):
example_netlists_path = determine_example_netlists_path(True)
error_message = "Example netlist not found. Either run 'export EXAMPLE_NETLISTS_PATH=<path>' or allow downloading to /tmp/spydrnet_example_netlists."
if format is EDIF:
assert name in example_netlist_names, "Example netlist not found"
return parse(os.path.join(base_dir, 'support_files', 'EDIF_netlists', name + ".edf.zip"))
assert name in example_netlist_names, error_message
return parse(Path(example_netlists_path, 'EDIF_netlists', name + ".edf.zip"))
elif format is VERILOG:
assert name in verilog_example_netlist_names, "Example netlist not found"
return parse(os.path.join(base_dir, 'support_files', 'verilog_netlists', name + ".v.zip"))
assert name in verilog_example_netlist_names, error_message
return parse(Path(example_netlists_path, 'verilog_netlists', name + ".v.zip"))
elif format is EBLIF:
assert name in eblif_example_netlist_names, "Example netlist not found"
return parse(os.path.join(base_dir, 'support_files', 'eblif_netlists', name + ".eblif.zip"))
assert name in eblif_example_netlist_names, error_message
return parse(Path(example_netlists_path, 'eblif_netlists', name + ".eblif.zip"))
else: # if no version is recognized, default to edif
assert name in example_netlist_names, "Example netlist not found"
return parse(os.path.join(base_dir, 'support_files', 'EDIF_netlists', name + ".edf.zip"))
assert name in example_netlist_names, error_message
return parse(Path(example_netlists_path, 'EDIF_netlists', name + ".edf.zip"))
1 change: 0 additions & 1 deletion spydrnet/composers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path


Expand Down
1 change: 0 additions & 1 deletion spydrnet/parsers/eblif/eblif_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import zipfile
import io
import os
from spydrnet.parsers.eblif.eblif_tokens import BACKSLASH
from pathlib import Path

Expand Down
10 changes: 9 additions & 1 deletion spydrnet/parsers/edif/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ def __init__(self, input_source):
else:
self.input_stream = open(input_source, "r")
elif isinstance(input_source, Path):
self.input_stream = open(input_source,"r")
if zipfile.is_zipfile(input_source):
zip = zipfile.ZipFile(input_source)
filename = Path(input_source).name
filename = filename[:filename.rindex(".")]
stream = zip.open(filename)
stream = io.TextIOWrapper(stream)
self.input_stream = stream
else:
self.input_stream = open(input_source,"r")
else:
if isinstance(input_source, io.TextIOBase) is False:
self.input_stream = io.TextIOWrapper(input_source)
Expand Down
11 changes: 9 additions & 2 deletions spydrnet/parsers/verilog/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import zipfile
import io
import os
import spydrnet.parsers.verilog.verilog_tokens as vt
from spydrnet.parsers.verilog.verilog_token_factory import TokenFactory
from pathlib import Path
Expand Down Expand Up @@ -44,7 +43,15 @@ def __init__(self, input_source):
else:
self.input_stream = open(input_source, 'r')
elif isinstance(input_source, Path):
self.input_stream = open(input_source,"r")
if zipfile.is_zipfile(input_source):
zip = zipfile.ZipFile(input_source)
filename = Path(input_source).name
filename = filename[:filename.rindex(".")]
stream = zip.open(filename)
stream = io.TextIOWrapper(stream)
self.input_stream = stream
else:
self.input_stream = open(input_source,"r")
else:
if isinstance(input_source, io.TextIOBase) is False:
self.input_stream = io.TextIOWrapper(input_source)
Expand Down
13 changes: 6 additions & 7 deletions spydrnet/util/architecture.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import spydrnet as sdn
from pathlib import Path

base_dir = os.path.dirname(os.path.abspath(sdn.__file__))
base_file_path = os.path.join(base_dir, 'support_files', 'architecture_libraries')
base_file_path = Path(sdn.base_dir, 'support_files', 'architecture_libraries')

XILINX_7SERIES = os.path.join(base_file_path, "xilinx_7series.v.zip")
F4PGA_XILINX_7SERIES = os.path.join(base_file_path, "f4pga_xilinx_7series.v.zip")
LATTICE_LIFCL = os.path.join(base_file_path, "lifcl.v.zip")
YOSYS_CELLS = os.path.join(base_file_path, "yosys_internal_cells.v.zip")
XILINX_7SERIES = Path(base_file_path).joinpath("xilinx_7series.v.zip")
F4PGA_XILINX_7SERIES = Path(base_file_path).joinpath("f4pga_xilinx_7series.v.zip")
LATTICE_LIFCL = Path(base_file_path).joinpath("lifcl.v.zip")
YOSYS_CELLS = Path(base_file_path).joinpath("yosys_internal_cells.v.zip")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5d93d96

Please sign in to comment.