Skip to content

Enable flake8-pie plugin for ruff #2339

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

Merged
merged 1 commit into from
Oct 25, 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 @@ -30,7 +30,7 @@ def get_changed_files(pr_branch, target_branch="master"):
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('+++')]
filenames = [x for x in filenames if x.startswith(('---', '+++'))]
filenames = [x.split(None, 1)[1] for x in filenames if len(x.split(None, 1)) > 1]
filenames = [x for x in filenames if not x.startswith('/dev/null')]
filenames = [x.lstrip('a/') for x in filenames]
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/api/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_move_cv_endpoint(self, galaxy_client):
# read tcp 172.18.0.2:47338->172.18.0.3:55001: read: connection reset by peer
repo_pulp_href_2 = None
retries = 10
for _ in range(0, retries):
for _ in range(retries):
try:
repo_pulp_href_2 = create_repo_and_dist(gc_admin, test_repo_name_2)
break
Expand All @@ -141,7 +141,7 @@ def test_move_cv_endpoint(self, galaxy_client):
# readfrom tcp 172.18.0.3:37490->172.18.0.2:55001:
# write tcp 172.18.0.3:37490->172.18.0.2:55001: use of closed network connection
retries = 10
for _ in range(0, retries):
for _ in range(retries):
try:
move_content_between_repos(
gc_admin, content_units, repo_pulp_href_1, [repo_pulp_href_2]
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_repository_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_repository_labels(galaxy_client):
# to take them into account in this test case
repos_to_remove = []
for repo in repos:
if repo.startswith("repo-test-") or repo.startswith("repo_ansible-"):
if repo.startswith(("repo-test-", "repo_ansible-")):
repos_to_remove.append(repo)
for repo in repos_to_remove:
repos.remove(repo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_api_ui_v1_namespace_owners_users_and_group_separation(ansible_config):
cfg = ansible_config('partner_engineer')
with UIClient(config=cfg) as uclient:

suffix = random.choice(range(0, 1000))
suffix = random.choice(range(1000))
group_name = f'group{suffix}'
user_name = f'user{suffix}'
namespace_name = f'namespace{suffix}'
Expand Down
8 changes: 4 additions & 4 deletions galaxy_ng/tests/integration/api/test_ui_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_api_ui_v1_execution_environments_registries(ansible_config):
validate_json(instance=ds, schema=schema_objectlist)

# try to create one
suffix = random.choice(range(0, 1000))
suffix = random.choice(range(1000))
rname = f'redhat.io.{suffix}'
payload = {
'name': rname,
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_api_ui_v1_groups(ansible_config):
validate_json(instance=grp, schema=schema_group)

# try to make a group
suffix = random.choice(range(0, 1000))
suffix = random.choice(range(1000))
payload = {'name': f'foobar{suffix}'}
resp = uclient.post('_ui/v1/groups/', payload=payload)
assert resp.status_code == 201
Expand Down Expand Up @@ -448,7 +448,7 @@ def test_api_ui_v1_groups_users_add_delete(ansible_config):
cfg = ansible_config('partner_engineer')
with UIClient(config=cfg) as uclient:

suffix = random.choice(range(0, 1000))
suffix = random.choice(range(1000))
group_name = f'group{suffix}'
user_name = f'user{suffix}'

Expand Down Expand Up @@ -972,7 +972,7 @@ def test_api_ui_v1_users(ansible_config):
validate_json(instance=user, schema=schema_user)

# try creating a user
suffix = random.choice(range(0, 9999))
suffix = random.choice(range(9999))
payload = {
'username': f'foobar{suffix}',
'first_name': 'foobar',
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_ui_paths_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_gw_api_ui_v1_execution_environments_registries(galaxy_client):
validate_json(instance=ds, schema=schema_objectlist)

# try to create one
suffix = random.choice(range(0, 1000))
suffix = random.choice(range(1000))
rname = f'redhat.io.{suffix}'
payload = {
'name': rname,
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/api/test_upload_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client):
create_repo_and_dist(gc, repo_name) # publishing fails 504 gateway error

# make 10 namespaces
namespaces = [create_test_namespace(gc) for x in range(0, total)]
namespaces = [create_test_namespace(gc) for x in range(total)]

# make a collection for each namespace
artifacts = []
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client):
else:
print(f"Function returned: {result}")

for _ in range(0, 10):
for _ in range(10):
matches, _ = search_collection_endpoint(
gc, repository_name=repo_name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_legacy_role_download_counter_via_cli(ansible_config):
assert role['download_count'] == 0

# validate install command
for _ in range(0, 5):
for _ in range(5):
with tempfile.TemporaryDirectory() as roles_path:
cfg = ansible_config(github_user)
install_pid = ansible_galaxy(
Expand Down Expand Up @@ -146,8 +146,8 @@ def fake_install_role(number):
# fetch the correct url N times at once validate no race conditions ...
total = 20
total_threads = total
args_list = [[x] for x in range(0, total)]
kwargs_list = [{} for x in range(0, total)]
args_list = [[x] for x in range(total)]
kwargs_list = [{} for x in range(total)]
with concurrent.futures.ThreadPoolExecutor(max_workers=total_threads) as executor:

future_to_args_kwargs = {
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 @@ -278,7 +278,7 @@ def test_social_auth_delete_collection(ansible_config):
token=client.get_hub_token(),
)

for _ in range(0, 20):
for _ in range(20):
exists_resp = client.get(
f"v3/plugin/ansible/content/published/collections/index/{namespace}/{name}/"
)
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_social_auth_deprecate_collection(ansible_config):
token=client.get_hub_token(),
)

for _ in range(0, 20):
for _ in range(20):
exists_resp = client.get(
f"v3/plugin/ansible/content/published/collections/index/{namespace}/{name}/"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_social_auth_v3_rbac_workflow(ansible_config):
base_cfg = ansible_config('github_user_1')

ga = GithubAdminClient()
suffix = ''.join([random.choice(string.ascii_lowercase) for x in range(0, 5)])
suffix = ''.join([random.choice(string.ascii_lowercase) for x in range(5)])
user_a = ga.create_user(login='0xEEE-32i-' + suffix)
user_a['username'] = user_a['login']
user_a['token'] = None
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_social_auth_no_duplicated_namespaces(ansible_config):
sean.update(default_cfg)

# login 10 times ...
for _ in range(0, 10):
for _ in range(10):
with SocialGithubClient(config=sean) as client:
client.get('_ui/v1/me/')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def extract_default_config(ansible_config):
def test_v1_user_github_ids(ansible_config):
"""" The github_id should show up in the v1 user serializer """

for x in range(0, 10):
for x in range(10):

github_user = 'deleteme' + str(x)
cleanup_social_user(github_user, ansible_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ansible_galaxy(

command_string = f"ansible-galaxy {command} -vvv --server={server} --ignore-certs"

for x in range(0, retries + 1):
for x in range(retries + 1):
try:
p = subprocess.run(
command_string,
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/utils/client_ansible_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def request(
if isinstance(args, (dict, list)):
args = json.dumps(args)
is_json = True
elif args and (args.startswith(b'{') or args.startswith(b'[')):
elif args and args.startswith((b'{', b'[')):
args = json.dumps(json.loads(args))
is_json = True

Expand Down
1 change: 0 additions & 1 deletion galaxy_ng/tests/integration/utils/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ def recursive_delete_gk(gc_admin, namespace_name, cname, crepo="published"):
resp = delete_collection(gc_admin, namespace=namespace_name, collection=cname)
except GalaxyClientError as ge:
print(ge)
pass
# wait for the orphan_cleanup job to finish ...
try:
wait_for_task(gc_admin, resp, timeout=10000)
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/utils/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def is_valid(ns):
while not is_valid(namespace):
namespace = ''
namespace += random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits)
for _ in range(0, random.choice(range(3, 63))):
for _ in range(random.choice(range(3, 63))):
namespace += random.choice(string.ascii_lowercase + string.digits + '_')

return namespace
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/utils/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_valid(ns):
while not is_valid(namespace):
namespace = ''
namespace += random.choice(string.ascii_lowercase)
for _ in range(0, random.choice(range(3, 63))):
for _ in range(random.choice(range(3, 63))):
namespace += random.choice(string.ascii_lowercase + string.digits + '_')

return namespace
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/utils/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_user(username, password, api_client=None):
assert api_client is not None, "api_client is a required param"

if password is None:
password = ''.join([random.choice(string.printable) for x in range(0, 12)])
password = ''.join([random.choice(string.printable) for x in range(12)])

payload = {
"username": username,
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/unit/app/utils/test_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UUIDConversionTestCase(TestCase):

def test_uuid_to_int_and_back(self):
"""Make sure uuids can become ints and then back to uuids"""
for _i in range(0, 1000):
for _i in range(1000):
test_uuid = str(uuid.uuid4())
test_int = uuid_to_int(test_uuid)
reversed_uuid = int_to_uuid(test_int)
Expand Down
4 changes: 2 additions & 2 deletions profiles/community/github_mock/flaskapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ def get_new_uid():


def get_new_login():
return ''.join([random.choice(string.ascii_lowercase) for x in range(0, 5)])
return ''.join([random.choice(string.ascii_lowercase) for x in range(5)])


def get_new_password():
return ''.join([random.choice(string.ascii_lowercase) for x in range(0, 12)])
return ''.join([random.choice(string.ascii_lowercase) for x in range(12)])


# ----------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ select = [
"INT",
# pyupgrade
"UP",
# flake8-pie
"PIE",
# flake8-pytest-style
"PT",
# ruff specific rules
Expand Down
Loading