Closed jgoeders closed 1 year ago
I believe that I was able to recreate the same error. Including .name at the end of the command (e.g. pathlib.Path('...').name) should fix the issue. Is this something that you want added into the parser in cases where the user does not include .name?
Yes, .name works because it returns a string; however, the parse API should also accept a pathlib.Path
object as that is the standard way of providing file paths in Python.
I added on the next release branch a flag to pass to the parser if pathlib.Path is being used. The flag is path_used Does this fix the issue for you?
Instead of having to pass a parameter to the parser, can we just check what the passed object is? If it's a string then don't do anything, and if it's a pathlib.Path object then get the filename string from it and continue on.
I agree with @jacobdbrown4. It's odd to have a flag. It's expected that python libraries that accept a file path will just work with pathlib.Path objects.
if it's a pathlib.Path object then get the filename string from it and continue on
Yes, you could add something like this to the start of the function:
filename = str(filename)
However, you should really be keeping the path as a pathlib.Path object internally, and more correctly, if passed a string, convert it to pathlib.Path object right away.
Right now it looks like the code is using os.path everywhere. This is the old way of doing paths in Python. The code should be using pathlib for all path handling and manipulations. It's much more readable and the modern Python way of dealing with paths.
Thanks for the info. We should probably update SpyDrNet to use pathlib like you were saying.
@jgoeders
@jacobdbrown4 and I have added the following functionality to the parser that is on the most recent release.
if it's a pathlib.Path object then get the filename string from it and continue on
Does this fix the issue for you?
Also, I have started looking into updating the code from os.path to pathlib. I have noticed different types of paths e.g. PosixPath, PurePosixPath, PurePath, and Path as well as path for windows. Is there a standard type of path that should be used?
[x] spydrnet/compare/tests/test_compare_netlists.py Line 17 Line 18
[x] spydrnet/init.py Line 121 Line 127 Line 133
[x] spydrnet/util/architecture.py Line 8 Line 10 Line 11 Line 12
[x] setup.py Line 29 Line 30
[x] spydrnet/composers/verilog/tests/test_composer.py Line 15 Line 80 Line 98
[x] docs/source/conf.py Line 20 Line 211
[x] spydrnet/parsers/edif/tests/test_edif_parser.py Line 56
[x] spydrnet/tests/test_example_netlist_functionality.py Line 10
[x] spydrnet/parsers/verliog/tests/test_tokenizer.py Line 13
[x] spydrnet/parsers/edif/tests/test_tokenizer.py Line 29
I have gone through and updated everything that uses os.path to use pathlib. I believe it is all working okay. My work is on the next_release branch.
I might create some tests that use pathlib paths to make sure parsing and composing works okay with that.
This is in next release branch and waiting to be released.
spydernet.parse
throws aAttributeError: 'PosixPath' object has no attribute 'readable'
if you provide a PosixPath pathlib.Path object.