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

Adding --force does not work due to directory already existing #98

Closed
onedr0p opened this issue Jan 16, 2024 · 4 comments
Closed

Adding --force does not work due to directory already existing #98

onedr0p opened this issue Jan 16, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@onedr0p
Copy link

onedr0p commented Jan 16, 2024

Describe the bug

Adding --force does not work due to directory already existing from a previous makejinja --force execution

To Reproduce

command

makejinja --force

config

[makejinja]
inputs = ["./bootstrap/templates"]
output = "./"
data = ["./bootstrap/vars/addons.yaml", "./bootstrap/vars/config.yaml"]
import_paths = ["./bootstrap/scripts"]
loaders = ["loader:Loader"]
jinja_suffix = ".j2"

# Block delimiters are changed to avoid conflicts with Renovate
# https://github.com/renovatebot/renovate/discussions/18470
[makejinja.delimiter]
block_start = "#%"
block_end = "%#"
comment_start = "{#"
comment_end = "#}"
variable_start = "{%"
variable_end = "%}"

error

Load data '/Users/devin/Code/repos/onedr0p/flux-template-cluster/bootstrap/vars/addons.yaml'
Load data '/Users/devin/Code/repos/onedr0p/flux-template-cluster/bootstrap/vars/config.yaml'
Render file '/Users/devin/Code/repos/onedr0p/flux-template-cluster/bootstrap/templates/.sops.yaml.j2' -> '/Users/devin/Code/repos/onedr0p/flux-template-cluster/.sops.yaml'
Create folder '/Users/devin/Code/repos/onedr0p/flux-template-cluster/bootstrap/templates/ansible' -> '/Users/devin/Code/repos/onedr0p/flux-template-cluster/ansible'
Traceback (most recent call last):
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/bin/makejinja", line 8, in <module>
    sys.exit(makejinja_cli())
             ^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/typed_settings/cli_click.py", line 247, in new_func
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/makejinja/cli.py", line 37, in makejinja_cli
    makejinja(config)
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/makejinja/app.py", line 59, in makejinja
    handle_input_folder(
  File "/Users/devin/Code/repos/onedr0p/flux-template-cluster/.venv/lib/python3.11/site-packages/makejinja/app.py", line 155, in handle_input_folder
    output_path.mkdir()
  File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py", line 1116, in mkdir
    os.mkdir(self, mode)
FileExistsError: [Errno 17] File exists: '/Users/devin/Code/repos/onedr0p/flux-template-cluster/ansible'
task: Failed to run task "configure": exit status 1

Expected behavior

That adding --force will not fail if the directory already exists.

@onedr0p onedr0p added the bug Something isn't working label Jan 16, 2024
@onedr0p
Copy link
Author

onedr0p commented Jan 16, 2024

I also wanted to say that I cannot use --clean as the output directory includes files/folders outside what gets rendered by makejinja. In my use-case the directories that would be conflicting are only ever generated by makejinja.

@mirkolenz
Copy link
Owner

Thanks for the report! At the moment, --force is only applied to files and not folders (I mostly use makejinja with the --clean flag myself). I just pushed a commit fixing this bug, as soon as CI is finished (typically a few minutes) a new release will be pushed to PyPI.

@onedr0p
Copy link
Author

onedr0p commented Jan 16, 2024

Beautiful! I would love to help contribute but don't have a ton of free time these days. Is there anyway I can send you some cash to at least have a few beers or meals on me? It's the least I could do for the time you spend developing this tool and being very responsive to issues!

@mirkolenz
Copy link
Owner

Thanks for your kind offer, I'm glad that makejinja is helpful! No need for money though, spreading the word about the project is support enough. Also keep reporting any issues you may find, this can only be beneficial for makejinja. Really appreciate your enthusiasm 😄

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
None yet
Development

No branches or pull requests

2 participants