Conversation
|
I want to walk through the code with a file to review further. |
|
Check the indentation on lines 27-39 for an extra leading space. |
|
When testing from linux command line (in conda environment with all dependencies included): (nxexamples) prjemian@zap:~/.../NeXus/exampledata$ ./nxdl/nxdl_to_hdf5.py -h
./nxdl/nxdl_to_hdf5.py: line 1: import: command not found
./nxdl/nxdl_to_hdf5.py: line 2: import: command not found
./nxdl/nxdl_to_hdf5.py: line 3: import: command not found
./nxdl/nxdl_to_hdf5.py: line 4: import: command not found
./nxdl/nxdl_to_hdf5.py: line 5: import: command not found
./nxdl/nxdl_to_hdf5.py: line 6: import: command not found
./nxdl/nxdl_to_hdf5.py: line 7: import: command not found
from: can't read /var/mail/lxml
./nxdl/nxdl_to_hdf5.py: line 9: import: command not found
from: can't read /var/mail/tinydb
./nxdl/nxdl_to_hdf5.py: line 11: $'\r': command not found
./nxdl/nxdl_to_hdf5.py: line 12: $'\r': command not found
./nxdl/nxdl_to_hdf5.py: line 13: readme_string: command not found
./nxdl/nxdl_to_hdf5.py: line 40: h5py_script_lst: command not found
./nxdl/nxdl_to_hdf5.py: line 41: nxsfrmt_script_lst: command not found
./nxdl/nxdl_to_hdf5.py: line 42: db: command not found
./nxdl/nxdl_to_hdf5.py: line 43: query: command not found
./nxdl/nxdl_to_hdf5.py: line 44: tables_dct: command not found
./nxdl/nxdl_to_hdf5.py: line 45: $'\r': command not found
./nxdl/nxdl_to_hdf5.py: line 46: syntax error near unexpected token `('
'/nxdl/nxdl_to_hdf5.py: line 46: `def init_database():Since debugging in VSCode with that environment passes these Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: '/home/prjemian/Documents/projects/NeXus/exampledata/../../definitions/applications'
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1651, in <module>
files = sorted(os.listdir(pathlib.PurePath(def_dir, def_subdir)))Here's my directory structure: (nxexamples) prjemian@zap:~/.../NeXus/exampledata$ ll /home/prjemian/Documents/projects/NeXus/
total 12K
drwxrwxr-x 15 prjemian prjemian 4.0K Dec 8 11:11 _definitions/
drwxrwxr-x 16 prjemian prjemian 4.0K Dec 13 09:53 definitions/
drwxrwxr-x 16 prjemian prjemian 4.0K Dec 14 11:37 exampledata/Muyst be off by one |
|
Should test that this directory exists earlier. Might be best if I propose some changes in a sub-branch? |
|
Getting further now. First exception location moved forward: Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: '/home/prjemian/Documents/projects/NeXus/exampledata/../autogenerated_examples/nxdl/python_scripts/h5py/ex_h5py_/home/prjemian/Documents/projects/NeXus/definitions/applications/NXarchive.py'
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1521, in write_script
f = open(pathlib.PurePath(path, 'ex_%s_%s.py' % (mod_name,class_nm)), 'w')
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1503, in write_script_files
write_script(mod_name,
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1472, in make_class_as_nf_file
write_script_files(class_nm)
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1573, in process_nxdl
make_class_as_nf_file(class_nm, dest_dir, symbol_dct=sym_args_dct)
File "/home/prjemian/Documents/projects/NeXus/exampledata/nxdl/nxdl_to_hdf5.py", line 1661, in <module>
process_nxdl(str(class_path), def_subdir)Is that a consequence of this code block? exampledata/nxdl/nxdl_to_hdf5.py Lines 872 to 875 in a92773b |
|
This block of code will become much stronger with the use of a context. exampledata/nxdl/nxdl_to_hdf5.py Lines 1377 to 1467 in 5ead471 Change 1377 to: with h5py.File(fpath, 'w') as nf:indent the remaining lines in the block, and remove the two lines that read: Read here for more details on context managers. |
|
Also, if you are writing for Python 3.7 and above, you should consider using Python f strings. Replace a line such as this: exampledata/nxdl/nxdl_to_hdf5.py Line 419 in 4298d62 with print(f'Error: invalid definition category [{category}]')Another example: exampledata/nxdl/nxdl_to_hdf5.py Line 86 in 4298d62 would be changed (including a swap of single to double outer quotes) to h5py_script_lst.append(f"root['{nxgrp.name}'].attrs[{name}'] = '{s_data.split('/')[-1]}'") |
prjemian
left a comment
There was a problem hiding this comment.
Since I can't run the code locally on Linux, some changes are needed as noted. Additional changes may also be needed.
MNT changes to use contexts and pathlib ops
|
The #!/usr/bin/env pythonwhich informs the OS to inspect the current environment and start this code with the first I was able to start this module directly as: python ./nxdl/nxdl_to_hdf5.pywith no such errors about |
move starting code into a main() function
|
#30 (comment)
|
Made changes to process the contributed_definitions directory also extended README.md.