Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when readme option is not set #6

Open
thomasgilgenast opened this issue Feb 15, 2021 · 0 comments
Open

TypeError when readme option is not set #6

thomasgilgenast opened this issue Feb 15, 2021 · 0 comments

Comments

@thomasgilgenast
Copy link
Member

As mentioned in #5, if the readme option in the [target] section of the config file is not set, treeshaker crashes with:

Traceback (most recent call last):
  File ".../venv/bin/treeshaker", line 8, in <module>
    sys.exit(main())
  File ".../venv/lib/python3.8/site-packages/treeshaker/treeshaker.py", line 293, in main
    fire.Fire(run_from_config)
  File ".../venv/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File ".../venv/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File ".../venv/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File ".../venv/lib/python3.8/site-packages/treeshaker/treeshaker.py", line 284, in run_from_config
    readme=os.path.join(config_path, section['readme']),
  File ".../lib/python3.8/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)
  File ".../lib/python3.8/genericpath.py", line 152, in _check_arg_types
    raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType'

This happens because there is no logic in place on this line to check if section['readme'] is None:

readme=os.path.join(config_path, section['readme']),

But in process_module() itself we do have logic to check if readme is None:

# load readme content
readme_content = None
if readme and os.path.exists(readme):
with open(readme, 'r') as handle:
readme_content = handle.read()
# write README
if readme_content or fire_components or functions:
new_name = old_name_to_new_name[target_module_name]
with open(os.path.join(dest_dir, 'README.md'), 'w') as handle:
handle.write('%s\n' % dest_dir)
handle.write(('=' * len(dest_dir)) + '\n\n')
if readme_content:
handle.write(readme_content + '\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant