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

Added command line option to keep trailing newlines #135

Closed
wants to merge 2 commits into from
Closed

Added command line option to keep trailing newlines #135

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 7, 2013

This adds the command line options '--keep-trailing-newline' (or '-n').

I'm not sure whether 'n' is the right letter to shorten it to and might require some thought.

I added a newline to one of the test samples. I'm not sure whether that would be okay, or whether it would be better to add a new file to check this with.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.62%) when pulling 9b85b1300615c05e165c730f569c071de2759fdf on luked:master into 9b04c23 on audreyr:master.

@ghost ghost mentioned this pull request Dec 7, 2013
@@ -181,7 +181,8 @@ def generate_files(repo_dir, context=None, output_dir="."):
run_hook('pre_gen_project', project_dir)

with work_in(template_dir):
env = Environment()
if environment_kwargs is None: environment_kwargs = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like this construction, there's nothing wrong with another newline.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) when pulling cf4f058c5651804848910fc21404920532c82937 on luked:master into 9b04c23 on audreyr:master.

@ghost
Copy link
Author

ghost commented Dec 7, 2013

Yes, sorry about that. I had missed adding a docstring for the argument also.

@michaeljoseph
Copy link
Contributor

🍰

@ghost
Copy link
Author

ghost commented Dec 8, 2013

Maybe jinja_kwargs would be a more descriptive name?

That made me think about whether the kwargs part was necessary. Perhaps jinja_environment or jinja_env?

Could ending it with kwargs also be misleading as an argument name?

@michaeljoseph
Copy link
Contributor

jinja_options?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 92ef05d on luked:master into 9b04c23 on audreyr:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.89%) when pulling 5a2def4b05f48894a593e3bd60cf86868b9317b7 on luked:master into 9b04c23 on audreyr:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 4bdc02b on luked:master into 9b04c23 on audreyr:master.

@ghost
Copy link
Author

ghost commented Dec 10, 2013

jinja_options?

Much better 😄

With the second patch that changes that changes the default, travis failed the first time. I think it was just network issue though. 😕

@michaeljoseph
Copy link
Contributor

Cool 🍕 🍔 👍

@coderanger
Copy link
Contributor

@audreyr Any chance this can get merged? Otherwise it either has to be corrected in a hook or git will complain on any generated file.

@coderanger
Copy link
Contributor

Example of a hook script to work around this issue https://github.com/poise/cookiecutter-cookbook/blob/master/hooks/post_gen_project.py

@dhellmann
Copy link

We're running into some issues with source files that have trailing newlines being output without those trailing newlines. It would be nice to have this merged! :-)

@treyhunner
Copy link
Contributor

👍 this is a big problem for Python projects especially which very rarely lack trailing newlines at the ends of files.

I actually think #79 may be a better short-term solution to this problem. I think a global switch is not granular enough. A default of adding trailing newlines is almost certainly the most sane.

There are legitimate reasons to keep trailing newlines out of specific files (or add them only to specific files).

It might be nice to eventually allow a flag to keep trailing newlines out of specific files. I have no specific use for such a feature, but it is conceivable that some files may disallow trailing newlines while others allow/require them.

@audreyfeldroy audreyfeldroy added this to the 0.8.0 milestone May 29, 2014
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 98ac2d2 on luked:master into 3b84343 on audreyr:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) when pulling 98ac2d2 on luked:master into 3b84343 on audreyr:master.

@ghost
Copy link
Author

ghost commented May 29, 2014

@treyhunner Yeah, I don't know why a command line argument is needed, but @michaeljoseph had asked for it.

I had thought that perhaps allowing the cookiecutter.json file of the individual cookiecutters to specify jinja2 options might be a better solution, as the author of a cookiecutter is probably more likely to care about this stuff than the end user. I thought I might work on a patch that would do this, but I thought I would wait and see if this problem would get resolved first :)

@michaeljoseph
Copy link
Contributor

I think we would prefer a cli switch and the current default to stay the same, so that we can preserve existing functionality / backwards compatibility?

@treyhunner
Copy link
Contributor

@michaeljoseph I agree with @LukeD that allowing cookiecutter authors to tweak the behavior is most desirable. As a user I don't want to remember to add a command line option to every cookiecutter I use. As a maintainer of a cookiecutter I am okay with tweaking my configuration to add trailing newlines to my files as appropriate.

@michaeljoseph
Copy link
Contributor

@treyhunner 👍 to that.
So we have to wait for @audreyr to make a call either way, but @LukeD if you wanna work on that patch of yours in the meantime, I have time to review / help out.

@treyhunner
Copy link
Contributor

I realized that the keep_trailing_newline behavior only causes newline absence/presence to be maintained. I believe this is the expected behavior, so I created a simple pull request which I believe solves this problem in the most appropriate way: #183. Please chime in there.

@pydanny pydanny modified the milestones: 0.9.0, 0.8.0 - Extra Context Jul 9, 2014
@michaeljoseph
Copy link
Contributor

Closing in favour of #183

@michaeljoseph michaeljoseph removed this from the 0.9.0 milestone Jul 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants