Skip to content
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

Bump pytest-mock from 1.11.1 to 3.6.0 in /requirements #16

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
from awx.main.utils.encryption import encrypt_value
from awx.main.utils.filters import SmartFilter
from awx.main.utils.insights import filter_insights_api_response
from awx.main.utils.common import get_custom_venv_choices, get_custom_venv_pip_freeze
from awx.main.redact import UriCleaner
from awx.api.permissions import (
JobTemplateCallbackPermission,
Expand Down Expand Up @@ -295,6 +296,7 @@ def get(self, request, format=None):
data['teams'] = {'url': reverse('api:team_list', request=request), 'total': team_list.count()}
data['credentials'] = {'url': reverse('api:credential_list', request=request), 'total': credential_list.count()}
data['job_templates'] = {'url': reverse('api:job_template_list', request=request), 'total': job_template_list.count()}
data['custom_venvs'] = {'url': reverse('api:custom_venv_list', request=request)}
return Response(data)


Expand Down
30 changes: 30 additions & 0 deletions awx/main/management/commands/custom_venvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved

import json

from awx.main.utils.common import get_custom_venv_choices, get_custom_venv_pip_freeze
from django.core.management.base import BaseCommand


class Command(BaseCommand):
"""Returns either a list of custom venv paths or outputs the pip freeze from the path passed in the argument"""

def add_arguments(self, parser):
parser.add_argument(
'--path',
dest='path',
type=str,
default='',
help='run without arguments to see a list of paths, run with one of those paths as an argument and see the pip freeze data',
)

def handle(self, *args, **options):
super(Command, self).__init__()
if options.get('path'):
pip_data = get_custom_venv_pip_freeze(options.get('path'))
print(pip_data)
else:
venvs = get_custom_venv_choices()
for venv in venvs:
print(venv)
33 changes: 21 additions & 12 deletions awx/main/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import yaml
import logging
import os
import subprocess
import re
import stat
import urllib.parse
Expand Down Expand Up @@ -887,30 +888,38 @@ def get_current_apps():
return current_apps


def get_custom_venv_choices(custom_paths=None):
def get_custom_venv_choices():
from django.conf import settings

custom_paths = custom_paths or settings.CUSTOM_VENV_PATHS
all_venv_paths = [settings.BASE_VENV_PATH] + custom_paths
all_venv_paths = []

all_venv_paths.append(settings.BASE_VENV_PATH) # get paths from settings

for root, dir, files in os.walk('../awx_devel/var/lib/awx/venv/'): # get paths on machine
all_venv_paths.append(root)

custom_venv_choices = []

for custom_venv_path in all_venv_paths:
for venv_path in all_venv_paths:
try:
if os.path.exists(custom_venv_path):
if os.path.exists(venv_path):
custom_venv_choices.extend(
[
os.path.join(custom_venv_path, x, '')
for x in os.listdir(custom_venv_path)
if x != 'awx'
and os.path.isdir(os.path.join(custom_venv_path, x))
and os.path.exists(os.path.join(custom_venv_path, x, 'bin', 'activate'))
]
[os.path.join(venv_path.replace('..', ''), x, '') for x in os.listdir(venv_path) if os.path.exists(os.path.join(venv_path, x, 'activate'))]
)
except Exception:
logger.exception("Encountered an error while discovering custom virtual environments.")
return custom_venv_choices


def get_custom_venv_pip_freeze(venv_path):
try:
freeze_data = subprocess.run([f"{venv_path}/pip", "freeze"], capture_output=True)
pip_data = (freeze_data.stdout).decode('ascii')
except Exception:
logger.exception("Encountered an error while discovering Pip Freeze data for custom virtual environments.")
return pip_data


def is_ansible_variable(key):
return key.startswith('ansible_')

Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pytest
pytest-cov
pytest-django
pytest-pythonpath
pytest-mock==1.11.1
pytest-mock==3.6.0
pytest-timeout
pytest-xdist==1.34.0 # 2.0.0 broke zuul for some reason
tox # for awxkit
Expand Down