Skip to content

Commit

Permalink
Revert "Resolve Circular Imports (#3912)" (#3960)
Browse files Browse the repository at this point in the history
This reverts commit c73d3d1.
  • Loading branch information
MichaelYochpaz committed Jan 18, 2024
1 parent c73d3d1 commit f215e64
Show file tree
Hide file tree
Showing 41 changed files with 281 additions and 614 deletions.
4 changes: 0 additions & 4 deletions .changelog/3912.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ jobs:
source $(poetry env info --path)/bin/activate
export ARTIFACTS_FOLDER="/home/circleci/project/artifacts"
mkdir -p $ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER/demisto_sdk_debug.log
cd content
demisto-sdk -v
echo $(echo '{"node_version": "'$(node --version)'","npm_list":'$(npm list --json)'}')
Expand All @@ -335,7 +335,7 @@ jobs:
source $(poetry env info --path)/bin/activate
export ARTIFACTS_FOLDER="/home/circleci/project/artifacts"
mkdir -p $ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER/demisto_sdk_debug.log
cd content
demisto-sdk -v
echo $(echo '{"node_version": "'$(node --version)'","npm_list":'$(npm list --json)'}')
Expand Down Expand Up @@ -436,7 +436,7 @@ jobs:
source $(poetry env info --path)/bin/activate
export ARTIFACTS_FOLDER="/home/circleci/project/artifacts"
mkdir -p $ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER
export DEMISTO_SDK_LOG_FILE_PATH=$ARTIFACTS_FOLDER/demisto_sdk_debug.log
cd content
demisto-sdk -v
mkdir ./tmp
Expand Down
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ repos:
rev: v4.4.0
hooks:
- id: trailing-whitespace
args:
- --markdown-linebreak-ext=md
- id: end-of-file-fixer
- id: check-docstring-first
exclude: demisto_sdk/commands/init/templates/.*
Expand Down
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,8 @@ Supported commands:
20. [generate-yml-from-python](https://xsoar.pan.dev/docs/integrations/yml-from-python-code-gen)
21. [generate-unit-tests](https://github.com/demisto/demisto-sdk/blob/master/demisto_sdk/commands/generate_unit_tests/README.md)
22. [pre-commit (experimental)](https://github.com/demisto/demisto-sdk/blob/master/demisto_sdk/commands/pre_commit/README.md)
23. [setup-env](https://github.com/demisto/demisto-sdk/blob/master/demisto_sdk/commands/setup_env/README.md)

---

### Logs

Log files are generated and stored automatically by default in the user's home directory:
**Linux / macOS**: `$HOME/.demisto-sdk/logs`
**Windows**: `%USERPROFILE%\.demisto-sdk\logs`

The default directory can be overriden using the `--log-file-path` flag, or the `DEMISTO_SDK_LOG_FILE_PATH` environment variable.

---
23. [setup-env](https://github.com/demisto/demisto-sdk/blob/master/demisto_sdk/commands/setup_env/README.md)

### Customizable command configuration

Expand Down Expand Up @@ -178,7 +167,7 @@ MIT - See [LICENSE](LICENSE) for more information.

---

## How to setup a development environment?
## How to setup development environment?

Follow the guide found [here](CONTRIBUTION.md#2-install-demisto-sdk-dev-environment) to setup your `demisto-sdk` dev environment.
The development environment is connected to the branch you are currently using in the SDK repository.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import argparse
import logging
import sys

from demisto_sdk.commands.common.logger import logger
from demisto_sdk.scripts.changelog.changelog import Changelog

logger = logging.getLogger("demisto-sdk")


def validate_changelog_and_logs(pr_num: str, pr_name: str) -> bool:
try:
Expand Down
53 changes: 21 additions & 32 deletions demisto_sdk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
from demisto_sdk.commands.common.cpu_count import cpu_count
from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json
from demisto_sdk.commands.common.hook_validations.readme import ReadMeValidator
from demisto_sdk.commands.common.logger import (
handle_deprecated_args,
logger,
logging_setup,
)
from demisto_sdk.commands.common.logger import handle_deprecated_args, logging_setup
from demisto_sdk.commands.common.tools import (
find_type,
get_last_remote_release_version,
Expand Down Expand Up @@ -74,6 +70,8 @@
"internet, un-set the DEMISTO_SDK_OFFLINE_ENV environment variable.[/red]"
)

logger = logging.getLogger("demisto-sdk")


# Third party packages

Expand Down Expand Up @@ -160,13 +158,16 @@ def get_context_arg(args):
help="Minimum logging threshold for the file logger."
" Possible values: DEBUG, INFO, WARNING, ERROR.",
)
@click.option("--log-file-path", help="Path to save log files onto.")
@click.option(
"--log-file-path",
help="Path to the log file. Default: Content root path.",
)
@functools.wraps(func)
def wrapper(*args, **kwargs):
logging_setup(
console_log_threshold=kwargs.get("console_log_threshold") or logging.INFO,
file_log_threshold=kwargs.get("file_log_threshold") or logging.DEBUG,
log_file_path=kwargs.get("log_file_path"),
log_file_path=kwargs.get("log_file_path") or None,
)

handle_deprecated_args(get_context_arg(args).args)
Expand Down Expand Up @@ -204,8 +205,9 @@ def main(ctx, config, version, release_notes, **kwargs):
console_log_threshold=kwargs.get("console_log_threshold", logging.INFO),
file_log_threshold=kwargs.get("file_log_threshold", logging.DEBUG),
log_file_path=kwargs.get("log_file_path"),
skip_log_file_creation=True, # Log file creation is handled in the logger setup of the sub-command
)
global logger
logger = logging.getLogger("demisto-sdk")
handle_deprecated_args(ctx.args)

config.configuration = Configuration()
Expand Down Expand Up @@ -1270,8 +1272,12 @@ def lint(ctx, **kwargs):
type=str,
)
@click.pass_context
@logging_setup_decorator
def coverage_analyze(ctx, **kwargs):
logger = logging_setup(
console_log_threshold=kwargs.get("console_log_threshold") or logging.INFO,
file_log_threshold=kwargs.get("file_log_threshold") or logging.DEBUG,
log_file_path=kwargs.get("log_file_path") or None,
)
from demisto_sdk.commands.coverage_analyze.coverage_report import CoverageReport

try:
Expand Down Expand Up @@ -2678,7 +2684,6 @@ def find_dependencies(ctx, **kwargs):
)
@pass_config
@click.pass_context
@logging_setup_decorator
def postman_codegen(
ctx,
config,
Expand All @@ -2692,6 +2697,11 @@ def postman_codegen(
**kwargs,
):
"""Generates a Cortex XSOAR integration given a Postman collection 2.1 JSON file."""
logger = logging_setup(
console_log_threshold=kwargs.get("console_log_threshold") or logging.INFO,
file_log_threshold=kwargs.get("file_log_threshold") or logging.DEBUG,
log_file_path=kwargs.get("log_file_path") or None,
)
from demisto_sdk.commands.postman_codegen.postman_codegen import (
postman_to_autogen_configuration,
)
Expand Down Expand Up @@ -3574,7 +3584,7 @@ def pre_commit(
dir_okay=True,
resolve_path=True,
show_default=False,
help="The paths to run pre-commit on. May pass multiple paths.",
help=("The paths to run pre-commit on. May pass multiple paths."),
),
staged_only: bool = typer.Option(
False, "--staged-only", help="Whether to run only on staged files"
Expand Down Expand Up @@ -3621,28 +3631,7 @@ def pre_commit(
True, "--docker/--no-docker", help="Whether to run docker based hooks or not."
),
run_hook: Optional[str] = typer.Argument(None, help="A specific hook to run"),
console_log_threshold: str = typer.Option(
"INFO",
"--console-log-threshold",
help="Minimum logging threshold for the console logger.",
),
file_log_threshold: str = typer.Option(
"DEBUG",
"--file-log-threshold",
help="Minimum logging threshold for the file logger.",
),
log_file_path: Optional[str] = typer.Option(
None,
"--log-file-path",
help="Path to save log files onto.",
),
):
logging_setup(
console_log_threshold=console_log_threshold,
file_log_threshold=file_log_threshold,
log_file_path=log_file_path,
)

from demisto_sdk.commands.pre_commit.pre_commit_command import pre_commit_manager

return_code = pre_commit_manager(
Expand Down
73 changes: 21 additions & 52 deletions demisto_sdk/commands/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,10 @@
import re
from enum import Enum
from functools import reduce
from pathlib import Path
from typing import Dict, List

from packaging.version import Version

# Note: Do NOT add imports of internal modules here, as it may cause circular imports.


PROJECT_DATA_DIR = Path.home() / ".demisto-sdk"
LOGS_DIR = PROJECT_DATA_DIR / "logs"
LOG_FILE_NAME = "demisto_sdk_debug.log"

# --- Environment Variables ---
# General
ENV_DEMISTO_SDK_MARKETPLACE = "DEMISTO_SDK_MARKETPLACE"
DEMISTO_GIT_PRIMARY_BRANCH = os.getenv("DEMISTO_DEFAULT_BRANCH", "master")
DEMISTO_GIT_UPSTREAM = os.getenv("DEMISTO_DEFAULT_REMOTE", "origin")
DEMISTO_SDK_CI_SERVER_HOST = os.getenv("CI_SERVER_HOST", "gitlab.xdr.pan.local")
DEMISTO_SDK_OFFICIAL_CONTENT_PROJECT_ID = os.getenv(
"CI_PROJECT_ID", "1061"
) # Default value is the ID of the content repo on GitLab
ENV_SDK_WORKING_OFFLINE = "DEMISTO_SDK_OFFLINE_ENV"


# Authentication
DEMISTO_BASE_URL = "DEMISTO_BASE_URL"
DEMISTO_USERNAME = "DEMISTO_USERNAME"
DEMISTO_PASSWORD = "DEMISTO_PASSWORD" # guardrails-disable-line
DEMISTO_KEY = "DEMISTO_API_KEY"
AUTH_ID = "XSIAM_AUTH_ID"
XSIAM_TOKEN = "XSIAM_TOKEN"
XSIAM_COLLECTOR_TOKEN = "XSIAM_COLLECTOR_TOKEN"
DEMISTO_VERIFY_SSL = "DEMISTO_VERIFY_SSL"

# Logging
DEMISTO_SDK_LOG_FILE_PATH = "DEMISTO_SDK_LOG_FILE_PATH"
DEMISTO_SDK_LOG_NOTIFY_PATH = "DEMISTO_SDK_LOG_NOTIFY_PATH"
DEMISTO_SDK_LOG_FILE_SIZE = "DEMISTO_SDK_LOG_FILE_SIZE"
DEMISTO_SDK_LOG_FILE_COUNT = "DEMISTO_SDK_LOG_FILE_COUNT"
DEMISTO_SDK_LOG_NO_COLORS = "DEMISTO_SDK_LOG_NO_COLORS"
# --- Environment Variables ---


CAN_START_WITH_DOT_SLASH = "(?:./)?"
NOT_TEST = "(?!Test)"

Expand Down Expand Up @@ -137,6 +98,26 @@
MARKETPLACE_KEY_PACK_METADATA = "marketplaces"
EVENT_COLLECTOR = "EventCollector"
ASSETS_MODELING_RULE = "assetsmodelingrule"
# ENV VARIABLES

ENV_DEMISTO_SDK_MARKETPLACE = "DEMISTO_SDK_MARKETPLACE"
DEMISTO_GIT_PRIMARY_BRANCH = os.getenv("DEMISTO_DEFAULT_BRANCH", "master")
DEMISTO_GIT_UPSTREAM = os.getenv("DEMISTO_DEFAULT_REMOTE", "origin")
DEMISTO_SDK_CI_SERVER_HOST = os.getenv("CI_SERVER_HOST", "gitlab.xdr.pan.local")
DEMISTO_SDK_OFFICIAL_CONTENT_PROJECT_ID = os.getenv(
"CI_PROJECT_ID", "1061"
) # the default is the id of the content repo in gitlab.xdr.pan.local

# authentication ENV VARIABLES
DEMISTO_BASE_URL = "DEMISTO_BASE_URL"
DEMISTO_USERNAME = "DEMISTO_USERNAME"
DEMISTO_PASSWORD = "DEMISTO_PASSWORD" # guardrails-disable-line
DEMISTO_KEY = "DEMISTO_API_KEY"
AUTH_ID = "XSIAM_AUTH_ID"
XSIAM_TOKEN = "XSIAM_TOKEN"
XSIAM_COLLECTOR_TOKEN = "XSIAM_COLLECTOR_TOKEN"
DEMISTO_VERIFY_SSL = "DEMISTO_VERIFY_SSL"


# Marketplaces

Expand Down Expand Up @@ -1951,6 +1932,7 @@ class ParameterType(Enum):

FORMATTING_SCRIPT = "indicator-format"

ENV_SDK_WORKING_OFFLINE = "DEMISTO_SDK_OFFLINE_ENV"
DOCKERFILES_INFO_REPO = "demisto/dockerfiles-info"

TEST_COVERAGE_DEFAULT_URL = f"https://storage.googleapis.com/{DEMISTO_SDK_MARKETPLACE_XSOAR_DIST_DEV}/code-coverage-reports/coverage-min.json"
Expand Down Expand Up @@ -1987,19 +1969,6 @@ class ParameterType(Enum):
MARKDOWN_IMAGES_ARTIFACT_FILE_NAME = "markdown_images.json"
SERVER_API_TO_STORAGE = "api/marketplace/file?name=content/packs"

STRING_TO_BOOL_MAP = {
"y": True,
"1": True,
"yes": True,
"true": True,
"n": False,
"0": False,
"no": False,
"false": False,
"t": True,
"f": False,
}


# date formats:
ISO_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
Expand Down
Loading

0 comments on commit f215e64

Please sign in to comment.