Skip to content

Commit

Permalink
python 3.8 support for importlib files api (#189)
Browse files Browse the repository at this point in the history
* python 3.8 support for importlib files api

* deleted unneeded line

* added the same change to gowin_unpack.py
  • Loading branch information
david65536 committed Aug 3, 2023
1 parent 8e31050 commit d6ada5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions apycula/gowin_bba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import gzip
import argparse
import re
from contextlib import contextmanager
from contextlib import contextmanager, closing
from collections import Counter
from apycula import chipdb

Expand Down Expand Up @@ -255,8 +255,11 @@ def main():

args = parser.parse_args()
read_constids(args.constids)
with gzip.open(importlib.resources.files("apycula").joinpath(f"{args.device}.pickle"), 'rb') as f:

with importlib.resources.path('apycula', f'{args.device}.pickle') as path:
with closing(gzip.open(path, 'rb')) as f:
db = pickle.load(f)

write_chipdb(db, args.output, args.device)

if __name__ == "__main__":
Expand Down
8 changes: 6 additions & 2 deletions apycula/gowin_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import importlib.resources
from collections import namedtuple
from contextlib import closing
from apycula import codegen
from apycula import chipdb
from apycula.chipdb import add_attr_val, get_shortval_fuses, get_longval_fuses, get_bank_fuses
Expand Down Expand Up @@ -981,8 +982,11 @@ def main():
mods = m.group(1) or ""
luts = m.group(3)
device = f"GW1N{mods}-{luts}"
with gzip.open(importlib.resources.files("apycula").joinpath(f"{device}.pickle"), 'rb') as f:
db = pickle.load(f)

with importlib.resources.path('apycula', f'{args.device}.pickle') as path:
with closing(gzip.open(path, 'rb')) as f:
db = pickle.load(f)

with open(args.netlist) as f:
pnr = json.load(f)

Expand Down
6 changes: 4 additions & 2 deletions apycula/gowin_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import gzip
import argparse
import importlib.resources
from contextlib import closing
from apycula import codegen
from apycula import chipdb
from apycula import attrids
Expand Down Expand Up @@ -1048,8 +1049,9 @@ def main():
luts = m.group(3)
_device = f"GW1N{mods}-{luts}"

with gzip.open(importlib.resources.files("apycula").joinpath(f"{_device}.pickle"), 'rb') as f:
db = pickle.load(f)
with importlib.resources.path('apycula', f'{args.device}.pickle') as path:
with closing(gzip.open(path, 'rb')) as f:
db = pickle.load(f)

global _pinout
_pinout = db.pinout[_device][_packages[_device]]
Expand Down

0 comments on commit d6ada5b

Please sign in to comment.