Skip to content

Commit

Permalink
fix path to dev env and scripts dir (#45)
Browse files Browse the repository at this point in the history
* run mypy on the devenv

* currect sdk_dir_path

* fix mypy it worksksksklsks

* fix whitespace

* test

* test

* test

* change things

* removed content dir

* maybe?

* fme

* end file blank line

* revert run mypy sh
  • Loading branch information
jochman authored Dec 2, 2019
1 parent 0b5ec1d commit 8d5fd91
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
4 changes: 1 addition & 3 deletions demisto_sdk/common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ class Configuration:
def __init__(self, env_dir=None, log_verbose=False, logging_level=logging.INFO):
logging.basicConfig(level=logging_level)
self.log_verbose = log_verbose
self.sdk_env_dir = os.path.dirname(os.path.abspath(os.path.join(__file__, '/../')))
self.sdk_env_dir = os.path.dirname(os.path.dirname(os.path.join(__file__)))
if not env_dir:
self.env_dir = os.getcwd()
else:
self.env_dir = env_dir
self.envs_dirs_base = '{}/dev_envs/default_python'.format(self.sdk_env_dir)

self.content_dir = os.path.abspath(os.getcwd())
5 changes: 2 additions & 3 deletions demisto_sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def extract_code(self, yml_path: str, dest_path: str, add_demisto_mock=True, add
return extractor.extract_code(dest_path)

def validate(self, **kwargs):
sys.path.append(self.configuration.content_dir)
sys.path.append(self.configuration.env_dir)

print_color('Starting validating files structure', LOG_COLORS.GREEN)

Expand All @@ -139,11 +139,10 @@ def lint(self, project_dir: str, **kwargs):
"""
linter = Linter(configuration=self.configuration, project_dir=project_dir, **kwargs)
ans = linter.run_dev_packages()
linter.remove_common_server_python()
return ans

def secrets(self, **kwargs):
sys.path.append(self.configuration.content_dir)
sys.path.append(self.configuration.env_dir)

print_color('Starting secrets detection', LOG_COLORS.GREEN)

Expand Down
28 changes: 16 additions & 12 deletions demisto_sdk/dev_tools/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, project_dir: str, no_test: bool = False, no_pylint: bool = Fa
raise ValueError("Nothing to run as all --no-* options specified.")

self.configuration = configuration
dev_scripts_dir = os.path.join(self.configuration.sdk_env_dir, 'scripts', 'dev_scripts')
dev_scripts_dir = os.path.join(self.configuration.sdk_env_dir, 'common', 'scripts', 'dev_scripts')
self.run_dev_tasks_script_name = 'run_dev_tasks.sh'
self.run_mypy_script_name = 'run_mypy.sh'
self.container_setup_script_name = 'pkg_dev_container_setup.sh'
Expand All @@ -45,15 +45,14 @@ def __init__(self, project_dir: str, no_test: bool = False, no_pylint: bool = Fa
self.keep_container = keep_container
self.cpu_num = cpu_num
self.common_server_created = False
self._get_common_server_python()
self.run_args = {
'pylint': not no_pylint,
'flake8': not no_flake8,
'mypy': not no_mypy,
'tests': not no_test
}

def _get_common_server_python(self) -> bool:
def get_common_server_python(self) -> bool:
"""Getting common server python in not exists
changes self.common_server_created to True if needed.
Returns:
Expand Down Expand Up @@ -130,15 +129,20 @@ def run_flake8(self, py_num):
python_exe = 'python2' if py_num < 3 else 'python3'
print_v('Using: {} to run flake8'.format(python_exe))
sys.stdout.flush()
subprocess.check_call([python_exe, '-m', 'flake8', self.project_dir], cwd=self.configuration.content_dir)
subprocess.check_call([python_exe, '-m', 'flake8', self.project_dir], cwd=self.configuration.env_dir)
print("flake8 completed")

def run_mypy(self, py_num):
lint_files = self._get_lint_files()
print("========= Running mypy on: {} ===============".format(lint_files))
sys.stdout.flush()
subprocess.check_call(['bash', self.run_mypy_script, str(py_num), lint_files], cwd=self.project_dir)
print("mypy completed")
try:
self.get_common_server_python()
lint_files = self._get_lint_files()
print("========= Running mypy on: {} ===============".format(lint_files))
sys.stdout.flush()
script_path = os.path.abspath(os.path.join(self.configuration.sdk_env_dir, self.run_mypy_script))
subprocess.check_call(['bash', script_path, str(py_num), lint_files], cwd=self.project_dir)
print("mypy completed")
finally:
self.remove_common_server_python()

def _docker_login(self):
if self.docker_login_completed:
Expand Down Expand Up @@ -277,13 +281,13 @@ def _docker_run(self, docker_image):
def _setup_dev_files(self):
# copy demistomock and common server
try:
shutil.copy(self.configuration.content_dir + '/Tests/demistomock/demistomock.py', self.project_dir)
shutil.copy(self.configuration.env_dir + '/Tests/demistomock/demistomock.py', self.project_dir)
open(self.project_dir + '/CommonServerUserPython.py', 'a').close() # create empty file
shutil.rmtree(self.project_dir + '/__pycache__', ignore_errors=True)
shutil.copy(self.configuration.content_dir + '/Tests/scripts/dev_envs/pytest/conftest.py', self.project_dir)
shutil.copy(self.configuration.env_dir + '/Tests/scripts/dev_envs/pytest/conftest.py', self.project_dir)
if "/Scripts/CommonServerPython" not in self.project_dir:
# Otherwise we already have the CommonServerPython.py file
shutil.copy(self.configuration.content_dir + '/Scripts/CommonServerPython/CommonServerPython.py',
shutil.copy(self.configuration.env_dir + '/Scripts/CommonServerPython/CommonServerPython.py',
self.project_dir)
except Exception as e:
print_v('Could not copy demistomock and CommonServer files: {}'.format(str(e)), self.log_verbose)
Expand Down
10 changes: 8 additions & 2 deletions tests/linter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@


class TestLinter:

DIR_LIST = [
"tests/test_files/fake_integration"
]

@pytest.mark.parametrize("directory", DIR_LIST)
def test_get_common_server_python(self, directory):
linter = Linter(directory)
ans = linter._get_common_server_python()
ans = linter.get_common_server_python()
linter.remove_common_server_python()
assert ans

@pytest.mark.skip(reason="No mypy")
@pytest.mark.parametrize("directory", DIR_LIST)
def test_run_mypy(self, directory):
linter = Linter(directory)
linter.run_mypy("2.7")

0 comments on commit 8d5fd91

Please sign in to comment.