-
Notifications
You must be signed in to change notification settings - Fork 418
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
Update csv_generator.py #2231
base: main
Are you sure you want to change the base?
Update csv_generator.py #2231
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,10 @@ | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import _csv | ||
import csv | ||
import sys | ||
from typing import ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like with the header, I suspect this changes were done automatically by your editor. If not, can you explain your reasoning for the edits? |
||
Dict, | ||
List, | ||
) | ||
|
||
from typing import Dict, List | ||
from os.path import join | ||
from _types import Field | ||
from generator import ecs_helpers | ||
from _types import ( | ||
Field, | ||
) | ||
|
||
|
||
def generate(ecs_flat: Dict[str, Field], version: str, out_dir: str) -> None: | ||
|
@@ -39,35 +16,29 @@ def generate(ecs_flat: Dict[str, Field], version: str, out_dir: str) -> None: | |
def base_first(ecs_flat: Dict[str, Field]) -> List[Field]: | ||
base_list: List[Field] = [] | ||
sorted_list: List[Field] = [] | ||
|
||
for field_name in sorted(ecs_flat): | ||
if '.' in field_name: | ||
sorted_list.append(ecs_flat[field_name]) | ||
else: | ||
base_list.append(ecs_flat[field_name]) | ||
|
||
return base_list + sorted_list | ||
|
||
|
||
def save_csv(file: str, sorted_fields: List[Field], version: str) -> None: | ||
open_mode: str = "wb" | ||
if sys.version_info >= (3, 0): | ||
open_mode: str = "w" | ||
open_mode = "w" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest simplifying even more:
If we do make this change in this generator, I think it'd make sense to do the same across the repo (e.g. here). |
||
|
||
with open(file, open_mode) as csvfile: | ||
schema_writer: _csv._writer = csv.writer(csvfile, | ||
delimiter=',', | ||
quoting=csv.QUOTE_MINIMAL, | ||
lineterminator='\n') | ||
|
||
schema_writer = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL, lineterminator='\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the type hint, |
||
schema_writer.writerow(["ECS_Version", "Indexed", "Field_Set", "Field", | ||
"Type", "Level", "Normalization", "Example", "Description"]) | ||
|
||
for field in sorted_fields: | ||
key_parts: List[str] = field['flat_name'].split('.') | ||
if len(key_parts) == 1: | ||
field_set: str = 'base' | ||
else: | ||
field_set: str = key_parts[0] | ||
key_parts = field['flat_name'].split('.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, why remove the type hints? |
||
field_set = 'base' if len(key_parts) == 1 else key_parts[0] | ||
indexed = str(field.get('index', True)).lower() | ||
|
||
indexed: str = str(field.get('index', True)).lower() | ||
schema_writer.writerow([ | ||
version, | ||
indexed, | ||
|
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 suspect this header was removed by your editor, but it would need to remain with any changes.