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

"AttributeError: 'Project' object has no attribute '_confirmed_root'" when running nitpick init in an empty directory #644

Open
valberg opened this issue Jan 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@valberg
Copy link

valberg commented Jan 25, 2024

Expected behavior

I was going to play around with nitpick, and thought the best course of action was to try to apply a custom style to an empty directory. But it is maybe not a supported behaviour? I would expect nitpick to give me an error message telling me what is wrong.

Current behavior

When nitpick init I get (this is expected I guess since there is no configuration yet):

Nothing to do. 😴 Either pass at least one style URL or use --suggest to add styles based on the files in the project root (you can do both at the same time).

I then try nitpick init --suggest which results in the following stacktrace:

$ nitpick init --suggest
Traceback (most recent call last):
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 248, in root
    root = self._confirmed_root
           ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Project' object has no attribute '_confirmed_root'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/valberg/.local/bin/nitpick", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/__main__.py", line 14, in main
    nitpick_cli(auto_envvar_prefix=PROJECT_NAME)
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/cli.py", line 197, in init
    config = nit.project.read_configuration()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 295, in read_configuration
    config_file = self.config_file_or_default()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 266, in config_file_or_default
    config_file = self.config_file()
                  ^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 275, in config_file
    existing: Path = self.root / possible
                     ^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 250, in root
    root = self._confirmed_root = confirm_project_root(self._chosen_root)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valberg/.local/pipx/venvs/nitpick/lib/python3.11/site-packages/nitpick/core.py", line 179, in confirm_project_root
    raise QuitComplainingError(Reporter().make_fuss(ProjectViolations.NO_ROOT_DIR))
nitpick.exceptions.QuitComplainingError

Steps to reproduce

  1. Run nitpick init --suggest in an empty directory.

Possible Solution

Give a more informative error about nitpick not working on an empty directory. Or implement a way for nitpick to be able to apply styles to an empty directory (create files with desired content etc.)

Context

I'm trying to apply a style to an empty directory to "kickstart a project".

@valberg valberg added the bug Something isn't working label Jan 25, 2024
@andreoliwa
Copy link
Owner

Thanks for the bug report. 👍🏻
Yeah, it should definitely output an informative error...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Upvoted / Requests
Development

No branches or pull requests

2 participants