-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Fix the custom file header #1346
Conversation
datamodel_code_generator/__init__.py
Outdated
if path is None: | ||
file = None | ||
else: | ||
if not path.parent.exists(): | ||
path.parent.mkdir(parents=True) | ||
file = path.open('wt', encoding=encoding) | ||
|
||
if custom_file_header and os.path.exists(custom_file_header): | ||
with open(custom_file_header) as header_file: | ||
custom_file_header = ''.join(header_file.readlines()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koxudaxi I took the liberty and added the option to read the header from file as well. We need to add the ASF header to each of the file in Iceberg: https://github.com/apache/iceberg/pull/7751/files Passing in a multi line string as an argument is a bit of a pain, so I figured this would be a nice addition.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1346 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 11 26 +15
Lines 1020 3341 +2321
Branches 201 794 +593
===========================================
+ Hits 1020 3341 +2321
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
@@ -500,15 +500,18 @@ def get_header_and_first_line(csv_file: IO[str]) -> Dict[str, Any]: | |||
header += f'\n# version: {get_version()}' | |||
|
|||
file: Optional[IO[Any]] | |||
for path, body_and_filename in modules.items(): | |||
body, filename = body_and_filename | |||
for path, (body, filename) in modules.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't realize the way to unpack the tuple in the for
statement.
Thank you!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that was a nice addition, any time! 👍🏻
arg_parser.add_argument( | ||
'--custom-file-header-path', | ||
help='Custom file header file path', | ||
default=None, | ||
type=str, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fokko
I add a new option to avoid confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me as well :) I was considering that as well
@Fokko |
Looks like the argument is missing :)