Skip to content

Commit

Permalink
Delete legacy config files (#887)
Browse files Browse the repository at this point in the history
* Delete legacy config files

We don't need it anymore.

* Extract package name
  • Loading branch information
therve authored Mar 16, 2022
1 parent e3193cd commit 8d9228b
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 41 deletions.
6 changes: 0 additions & 6 deletions .generator/config/v1.json

This file was deleted.

6 changes: 0 additions & 6 deletions .generator/config/v2.json

This file was deleted.

15 changes: 8 additions & 7 deletions .generator/src/generator/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import pathlib

import click
Expand All @@ -7,6 +6,8 @@
from . import openapi
from . import formatter

PACKAGE_NAME = "datadog_api_client"


@click.command()
@click.option(
Expand All @@ -26,8 +27,6 @@ def cli(input, output):
spec = openapi.load(input)

version = input.parent.name
with (input.parent.parent.parent / "config" / f"{version}.json").open() as fp:
config = json.load(fp)

env = Environment(loader=FileSystemLoader(str(pathlib.Path(__file__).parent / "templates")))

Expand All @@ -41,9 +40,9 @@ def cli(input, output):
env.filters["return_type"] = openapi.return_type
env.filters["snake_case"] = formatter.snake_case

env.globals["config"] = config
env.globals["enumerate"] = enumerate
env.globals["version"] = version
env.globals["package"] = PACKAGE_NAME
env.globals["openapi"] = spec
env.globals["get_name"] = formatter.get_name
env.globals["get_type_for_attribute"] = openapi.get_type_for_attribute
Expand Down Expand Up @@ -77,15 +76,17 @@ def cli(input, output):
apis = openapi.apis(spec)
models = openapi.models(spec)

package = output / config["packageName"].replace(".", "/")
package.mkdir(parents=True, exist_ok=True)
top_package = output / PACKAGE_NAME
top_package.mkdir(parents=True, exist_ok=True)

top_package = package.parent
for name, template in extra_files.items():
filename = top_package / name
with filename.open("w") as fp:
fp.write(template.render())

package = top_package / version
package.mkdir(exist_ok=True)

for name, model in models.items():
filename = formatter.snake_case(name) + ".py"
model_path = package / "model" / filename
Expand Down
6 changes: 3 additions & 3 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% include "api_info.j2" %}


from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
from datadog_api_client.model_utils import (
from {{ package }}.api_client import ApiClient, Endpoint as _Endpoint
from {{ package }}.model_utils import (
date,
datetime,
file_type,
none_type,
)
{%- for model in get_api_models(operations) %}
from {{ config["packageName"] }}.model.{{ model|snake_case }} import {{ model }}
from {{ package }}.{{ version }}.model.{{ model|snake_case }} import {{ model }}
{%- endfor %}

{% set classname = name.replace(" ", "") + "Api" %}
Expand Down
8 changes: 4 additions & 4 deletions .generator/src/generator/templates/api_client.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ from urllib.parse import quote
from urllib3.fields import RequestField # type: ignore


from datadog_api_client import rest
from datadog_api_client.exceptions import ApiTypeError, ApiValueError
from datadog_api_client.model_utils import (
from {{ package }} import rest
from {{ package }}.exceptions import ApiTypeError, ApiValueError
from {{ package }}.model_utils import (
ModelNormal,
ModelSimple,
ModelComposed,
Expand Down Expand Up @@ -788,7 +788,7 @@ class Endpoint(object):
def user_agent():
"""Generate default User-Agent header."""
import platform
from datadog_api_client.version import __version__
from {{ package }}.version import __version__

return "datadog-api-client-python/{version} (python {py}; os {os}; arch {arch})".format(
version=__version__,
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/apis.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- for api in apis %}
{%- set classname = api.replace(" ", "") + "Api" %}
from {{ config["packageName"] }}.api.{{ classname|snake_case }} import {{ classname }}
from {{ package }}.{{ version }}.api.{{ classname|snake_case }} import {{ classname }}
{%- endfor %}

4 changes: 2 additions & 2 deletions .generator/src/generator/templates/base_configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import multiprocessing
import urllib3 # type: ignore

from http import client as http_client
from datadog_api_client.exceptions import ApiValueError
from {{ package }}.exceptions import ApiValueError


JSON_SCHEMA_VALIDATION_KEYWORDS = {
Expand Down Expand Up @@ -118,7 +118,7 @@ class BaseConfiguration:
self.discard_unknown_keys = discard_unknown_keys
self.disabled_client_side_validations = disabled_client_side_validations
self.logger = {}
self.logger["package_logger"] = logging.getLogger("{{ config["packageName"] }}")
self.logger["package_logger"] = logging.getLogger("{{ package }}")
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
self.logger_format = "%(asctime)s %(levelname)s %(message)s"
self.logger_stream_handler = None
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/configuration.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% include "api_info.j2" %}

from datadog_api_client.configuration import BaseConfiguration
from {{ package }}.configuration import BaseConfiguration


class Configuration(BaseConfiguration):
Expand Down
6 changes: 3 additions & 3 deletions .generator/src/generator/templates/init.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% include "api_info.j2" %}

from datadog_api_client.api_client import ApiClient, AsyncApiClient
from datadog_api_client.exceptions import (
from {{ package }}.api_client import ApiClient, AsyncApiClient
from {{ package }}.exceptions import (
OpenApiException, ApiAttributeError, ApiTypeError, ApiValueError, ApiKeyError, ApiException)

from {{ config["packageName"] }}.configuration import Configuration
from {{ package }}.{{ version }}.configuration import Configuration
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/model.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% include "api_info.j2" %}


from datadog_api_client.model_utils import (
from {{ package }}.model_utils import (
ApiTypeError,
ModelComposed,
ModelNormal,
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/model_generic.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- if refs %}
def lazy_import():
{%- for ref in refs %}
from {{ config["packageName"] }}.model.{{ ref|snake_case }} import {{ ref }}
from {{ package }}.{{ version }}.model.{{ ref|snake_case }} import {{ ref }}
{%- endfor %}
{# keep new line #}
{%- for ref in refs %}
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/model_oneof.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- if refs %}
def lazy_import():
{%- for ref in refs %}
from {{ config["packageName"] }}.model.{{ ref|snake_case }} import {{ ref }}
from {{ package }}.{{ version }}.model.{{ ref|snake_case }} import {{ ref }}
{%- endfor %}
{%- for ref in refs %}
globals()["{{ ref }}"] = {{ ref }}
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/model_simple.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- set ref = get_type_for_items(model) %}
{%- if ref %}
def lazy_import():
from {{ config["packageName"] }}.model.{{ ref|snake_case }} import {{ ref }}
from {{ package }}.{{ version }}.model.{{ ref|snake_case }} import {{ ref }}

globals()["{{ ref }}"] = {{ ref }}
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/model_utils.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from typing import Collection, Mapping, Union

from dateutil.parser import parse

from datadog_api_client.exceptions import (
from {{ package }}.exceptions import (
ApiKeyError,
ApiAttributeError,
ApiTypeError,
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/models.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- for model in models %}
from {{ config["packageName"] }}.model.{{ model|snake_case }} import {{ model }}
from {{ package }}.{{ version }}.model.{{ model|snake_case }} import {{ model }}
{%- endfor %}

2 changes: 1 addition & 1 deletion .generator/src/generator/templates/rest.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zlib

import urllib3 # type: ignore

from datadog_api_client.exceptions import (
from {{ package }}.exceptions import (
ApiException,
UnauthorizedException,
ForbiddenException,
Expand Down
2 changes: 1 addition & 1 deletion src/datadog_api_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
self.discard_unknown_keys = discard_unknown_keys
self.disabled_client_side_validations = disabled_client_side_validations
self.logger = {}
self.logger["package_logger"] = logging.getLogger("datadog_api_client.v2")
self.logger["package_logger"] = logging.getLogger("datadog_api_client")
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
self.logger_format = "%(asctime)s %(levelname)s %(message)s"
self.logger_stream_handler = None
Expand Down

0 comments on commit 8d9228b

Please sign in to comment.