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

Add pyupgrade plugin for ruff #2320

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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: 1 addition & 1 deletion dev/common/tdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_changed_files(pr_branch, target_branch="master"):
cmd = f'curl -s -o /tmp/pr.diff {url}'
pid = subprocess.run(cmd, shell=True)
assert pid.returncode == 0
with open('/tmp/pr.diff', 'r') as f:
with open('/tmp/pr.diff') as f:
raw = f.read()
filenames = raw.split('\n')
filenames = [x for x in filenames if x.startswith('---') or x.startswith('+++')]
Expand Down
2 changes: 1 addition & 1 deletion dev/oci_env_integration/actions/rbac-parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rbac_parallel_group = sys.argv[1] if len(sys.argv) == 2 else None
rbac_marker = rbac_parallel_group if rbac_parallel_group else "rbac_roles"

pytest_flags = "-m {0}".format(rbac_marker)
pytest_flags = f"-m {rbac_marker}"

env = action_lib.OCIEnvIntegrationTest(
envs=[
Expand Down
2 changes: 1 addition & 1 deletion galaxy-operator/bin/readyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def is_content_healthy(path):
/usr/bin/python3.9/usr/bin/gunicorn--bind[::]:2481{6,7}pulpcore.app.wsgi:application--namepulp-{api,content}--timeout90--workers2
```
"""
with open("/proc/1/cmdline", "r") as f:
with open("/proc/1/cmdline") as f:
cmdline = f.readline()

if "pulp-api" in cmdline:
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/app/api/ui/v1/views/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def get(self, request, *args, **kwargs):
"id": "ansible-partner",
"icon": "bulb",
"action": {
"title": "Check out our partner %s" % namespace.company,
"href": "./ansible/automation-hub/partners/%s" % namespace.name,
"title": f"Check out our partner {namespace.company}",
"href": f"./ansible/automation-hub/partners/{namespace.name}",
},
"description": "Discover automation from our partners.",
}
Expand Down
5 changes: 4 additions & 1 deletion galaxy_ng/app/api/ui/v1/viewsets/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def version_range_filter(self, queryset, name, value):

return queryset.filter(version__in=version_list)
except ValueError:
raise ValidationError(_('%s must be a valid semantic version range.' % name))
# FIXME(cutwater): String interpolation must be applied AFTER localization
raise ValidationError(
_('%s must be a valid semantic version range.' % name) # noqa: UP031
)

sort = OrderingFilter(
fields=(
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ def get_object(self):

def get_aap_version():
if os.path.isfile(AAP_VERSION_FILE_PATH):
with open(AAP_VERSION_FILE_PATH, "r") as f:
with open(AAP_VERSION_FILE_PATH) as f:
return f.read().strip('\n')
return None
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def get_results(self, obj):
return results


class LegacyTaskSerializer():
class LegacyTaskSerializer:

@property
def data(self):
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/v1/viewsets/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def list(self, request, *args, **kwargs):
"""
if request.query_params.get('id'):
return self.get_task(request, id=int(request.query_params['id']))
return super(LegacyRoleImportsViewSet, self).list(request, *args, **kwargs)
return super().list(request, *args, **kwargs)

def retrieve(self, request, *args, **kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/v3/serializers/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CollectionUploadSerializer(Serializer):

sha256 = serializers.CharField(required=False, default=None)

class Meta():
class Meta:
ref_name = "CollectionUploadWithDownloadUrlSerializer"

def to_internal_value(self, data):
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/v3/viewsets/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def create(self, request, *args, **kwargs):
self.check_object_permissions(request, namespace)

try:
response = super(CollectionUploadViewSet, self).create(request, path)
response = super().create(request, path)
except ValidationError:
log.exception('Failed to publish artifact %s (namespace=%s, sha256=%s)', # noqa
data['file'].name, namespace, data.get('sha256'))
Expand Down
4 changes: 1 addition & 3 deletions galaxy_ng/app/common/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ def parse(self, stream, media_type=None, parser_context=None):

new_stream.seek(0)

return super(AnsibleGalaxy29MultiPartParser, self).parse(new_stream,
media_type=media_type,
parser_context=parser_context)
return super().parse(new_stream, media_type=media_type, parser_context=parser_context)
6 changes: 3 additions & 3 deletions galaxy_ng/app/tasks/namespaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import aiohttp
import asyncio
import contextlib
import xml.etree.cElementTree as et
import xml.etree.ElementTree as ET

from django.db import transaction
from django.forms.fields import ImageField
Expand Down Expand Up @@ -72,9 +72,9 @@ def _download_avatar(url, namespace_name):
except ValidationError:
# Not a PIL valid image lets handle SVG case
tag = None
with contextlib.suppress(et.ParseError):
with contextlib.suppress(ET.ParseError):
f.seek(0)
tag = et.parse(f).find(".").tag
tag = ET.parse(f).find(".").tag
if tag != '{http://www.w3.org/2000/svg}svg':
raise ValidationError(
f"Provided avatar_url for {namespace_name} on {url} is not a valid image"
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/tasks/promotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def auto_approve(src_repo_pk, cv_pk, ns_pk=None):
try:
signing_service = AUTO_SIGN and SigningService.objects.get(name=SIGNING_SERVICE_NAME)
except SigningService.DoesNotExist:
raise RuntimeError('Signing %s service not found' % SIGNING_SERVICE_NAME)
raise RuntimeError(f'Signing {SIGNING_SERVICE_NAME} service not found')

# Sign the collection if auto sign is enabled
if AUTO_SIGN:
Expand Down
8 changes: 4 additions & 4 deletions galaxy_ng/app/utils/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_path_role_repository(path):
def get_path_role_meta(path):
""" Retrive the meta/main.yml from a role """
metaf = os.path.join(path, 'meta', 'main.yml')
with open(metaf, 'r') as f:
with open(metaf) as f:
meta = yaml.safe_load(f.read())
return meta

Expand All @@ -48,7 +48,7 @@ def get_path_role_name(path):
metaf = os.path.join(path, 'meta', 'main.yml')
meta = None
if os.path.exists(metaf):
with open(metaf, 'r') as f:
with open(metaf) as f:
meta = yaml.safe_load(f.read())

if meta and 'role_name' in meta['galaxy_info']:
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_path_galaxy_key(path, key):
if not os.path.exists(gfn):
return None

with open(gfn, 'r') as f:
with open(gfn) as f:
ds = yaml.safe_load(f.read())

return ds.get(key)
Expand All @@ -171,7 +171,7 @@ def get_path_galaxy_key(path, key):
def set_path_galaxy_key(path, key, value):
""" Set a specific key in a galaxy.yml """
gfn = os.path.join(path, 'galaxy.yml')
with open(gfn, 'r') as f:
with open(gfn) as f:
ds = yaml.safe_load(f.read())

ds[key] = value
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get(self, request, api_path):

args = request.META.get("QUERY_STRING", "")
if args:
url = "%s?%s" % (url, args)
url = f"{url}?{args}"

# Returning 308 instead of 302 since 308 requires that clients maintain the
# same method as the original request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _upload_collection_common(user, password, expect_pass, extra, base_path=None
server,
artifact.filename
]
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, capture_output=True)

del_collection(name, extra['collection'].get_namespace()["name"], repo=base_path)

Expand Down
6 changes: 3 additions & 3 deletions galaxy_ng/tests/integration/api/rbac_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def wait_for_all_tasks():
def ensure_test_container_is_pulled():
container_engine = CLIENT_CONFIG["container_engine"]
cmd = [container_engine, "image", "exists", TEST_CONTAINER]
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, capture_output=True)
if proc.returncode == 1:
cmd = [container_engine, "image", "pull", TEST_CONTAINER]
rc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rc = subprocess.run(cmd, capture_output=True)
assert rc.returncode == 0


Expand Down Expand Up @@ -459,7 +459,7 @@ def _add_collection(self):
server,
artifact.filename
]
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, capture_output=True)
assert proc.returncode == 0
wait_for_all_tasks()

Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_artifact_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_long_field_values(galaxy_client, field):
resp = wait_for_task(gc, resp)
assert resp["state"] == "failed"
# Should END with an error
assert "must not be greater than %s characters" % fieldmax in resp["error"]["description"]
assert f"must not be greater than {fieldmax} characters" in resp["error"]["description"]
assert fieldname in resp["error"]["description"]


Expand Down
17 changes: 3 additions & 14 deletions galaxy_ng/tests/integration/api/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ def test_openapi_bindings_generation(ansible_config, galaxy_client):
pulp_spec = gc.get('pulp/api/v3/docs/api.json')
status = gc.get('pulp/api/v3/status/')
version = [x['version'] for x in status['versions'] if x['component'] == 'galaxy'][0]
my_id = subprocess.run(
'id -u',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).stdout.decode('utf-8').strip()
my_id = subprocess.run('id -u', shell=True, capture_output=True).stdout.decode('utf-8').strip()
volume_name = '/local'
generator_repo = 'https://github.com/pulp/pulp-openapi-generator'

Expand All @@ -105,8 +100,7 @@ def test_openapi_bindings_generation(ansible_config, galaxy_client):
clone_pid = subprocess.run(
f'git clone {generator_repo} {generator_checkout}',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
capture_output=True,
)
assert clone_pid.returncode == 0, clone_pid.stderr.decode('utf-8')

Expand Down Expand Up @@ -137,12 +131,7 @@ def test_openapi_bindings_generation(ansible_config, galaxy_client):
'--strict-spec=false'
]

docker_pid = subprocess.run(
' '.join(cmd),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
docker_pid = subprocess.run(' '.join(cmd), shell=True, capture_output=True)
try:
assert docker_pid.returncode == 0, docker_pid.stderr.decode('utf-8')
except AssertionError as e:
Expand Down
3 changes: 2 additions & 1 deletion galaxy_ng/tests/integration/api/test_ui_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,8 @@ def _sync_role(github_user, role_name):
def _populate_tags_cmd():
proc = subprocess.run(
"django-admin populate-role-tags",
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
shell=True,
capture_output=True,
)
assert proc.returncode == 0

Expand Down
3 changes: 1 addition & 2 deletions galaxy_ng/tests/integration/cli/test_community_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def test_community_collection_download_count_sync(ansible_config):
pid = subprocess.run(
'pulpcore-manager sync-collection-download-counts',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
capture_output=True,
)
assert pid.returncode == 0

Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/community/test_community_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def test_v1_username_autocomplete_search(ansible_config):
+ " --server "
+ server
]
proc = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, shell=True, capture_output=True)
assert b"Found 5 roles matching your search" in proc.stdout

cmd = [
Expand All @@ -599,7 +599,7 @@ def test_v1_username_autocomplete_search(ansible_config):
+ " --server "
+ server
]
proc = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, shell=True, capture_output=True)
assert b"Found 1 roles matching your search" in proc.stdout
assert b"geerlingguy.adminer" in proc.stdout

Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/community/test_community_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_delete_role_with_cli(ansible_config):
+ f' {github_user}'
+ f' {role_name}'
)
delete_pid = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
delete_pid = subprocess.run(cmd, shell=True, capture_output=True)

# FIXME: for some reason, returncode is 1 even if it runs correctly and role is deleted
# assert delete_pid.returncode == 0 #, delete_pid.stderr.decode('utf-8')
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_delete_missing_role_with_cli(ansible_config):
+ f' {github_user}'
+ f' {github_repo}'
)
delete_pid = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
delete_pid = subprocess.run(cmd, shell=True, capture_output=True)
# FIXME: should return 1?
# assert delete_pid.returncode == 0 # , delete_pid.stderr.decode('utf-8')

Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def keep_generated_test_artifact(ansible_config):
@pytest.fixture(scope="session")
def data():
path = 'galaxy_ng/tests/integration/load_data.yaml'
with open(path, 'r') as yaml_file:
with open(path) as yaml_file:
data = yaml.safe_load(yaml_file)
return data

Expand Down
11 changes: 8 additions & 3 deletions galaxy_ng/tests/integration/utils/client_ansible_galaxy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import shutil
import tempfile
import time

from subprocess import run, PIPE
import subprocess

from galaxy_ng.tests.integration.constants import SLEEP_SECONDS_POLLING

Expand Down Expand Up @@ -77,7 +76,13 @@ def ansible_galaxy(

for x in range(0, retries + 1):
try:
p = run(command_string, cwd=tdir, shell=True, stdout=PIPE, stderr=PIPE, env=os.environ)
p = subprocess.run(
command_string,
cwd=tdir,
shell=True,
capture_output=True,
env=os.environ,
)
logger.debug(f"RUN [retry #{x}] {command_string}")
logger.debug("STDOUT---")
for line in p.stdout.decode("utf8").split("\n"):
Expand Down
9 changes: 2 additions & 7 deletions galaxy_ng/tests/integration/utils/collection_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ def _enumerate(self):
if self.tarball:
self._extract_path = tempfile.mkdtemp(prefix='collection-extract-')
cmd = f'cd {self._extract_path}; tar xzvf {self.tarball}'
subprocess.run(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
subprocess.run(cmd, shell=True, capture_output=True)
else:
self._extract_path = self.directory

with open(os.path.join(self._extract_path, 'MANIFEST.json'), 'r') as f:
with open(os.path.join(self._extract_path, 'MANIFEST.json')) as f:
self.manifest = json.loads(f.read())

if self.tarball:
Expand Down
Loading
Loading