Skip to content

Replace flake8 with ruff #112

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 3 commits into from
Mar 11, 2023
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 Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lint:
flake8 --ignore=E402,E501,E712,W503,E203,I002 --exclude=ctfcli/templates **/*.py
ruff check --ignore=E402,E501,E712,I002 --exclude=ctfcli/templates --exclude=build .
black --check --exclude=ctfcli/templates .

format:
Expand Down
12 changes: 6 additions & 6 deletions ctfcli/cli/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def install(self, challenge=None, force=False, ignore=()):
else: # If we don't break because of duplicated challenge names
click.secho(f'Installing {challenge["name"]}', fg="yellow")
create_challenge(challenge=challenge, ignore=ignore)
click.secho(f"Success!", fg="green")
click.secho("Success!", fg="green")

def sync(self, challenge=None, ignore=()):
if challenge is None:
Expand Down Expand Up @@ -209,7 +209,7 @@ def sync(self, challenge=None, ignore=()):

click.secho(f'Syncing {challenge["name"]}', fg="yellow")
sync_challenge(challenge=challenge, ignore=ignore)
click.secho(f"Success!", fg="green")
click.secho("Success!", fg="green")

def update(self, challenge=None):
config = load_config()
Expand Down Expand Up @@ -339,7 +339,7 @@ def deploy(self, challenge, host=None):
)
else:
click.secho(
f"An error occured during deployment", fg="red",
"An error occured during deployment", fg="red",
)

def push(self, challenge=None):
Expand All @@ -364,7 +364,7 @@ def push(self, challenge=None):

def healthcheck(self, challenge):
config = load_config()
challenges = config["challenges"]
_challenges = config["challenges"]

# challenge_path = challenges[challenge]
path = Path(challenge)
Expand Down Expand Up @@ -406,11 +406,11 @@ def healthcheck(self, challenge):

if rcode != 0:
click.secho(
f"Healcheck failed", fg="red",
"Healcheck failed", fg="red",
)
sys.exit(1)
else:
click.secho(
f"Success", fg="green",
"Success", fg="green",
)
sys.exit(0)
5 changes: 3 additions & 2 deletions ctfcli/cli/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Pages(object):
def install(self):
try:
_config = load_config()
except:
except Exception as e:
print(e)
click.secho("No ctfcli configuration found", fg="red")
sys.exit(1)

pages = Path("./pages")
if pages.is_dir() is False:
click.secho(
f'"pages" folder not found. All pages must exist in the "pages" folder.',
'"pages" folder not found. All pages must exist in the "pages" folder.',
fg="red",
)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion ctfcli/cli/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def install(self, url):
pip3 = shutil.which("pip3")

if pip is None and pip3 is None:
click.secho(f"Neither pip nor pip3 was found, is it in the PATH?", fg="red")
click.secho("Neither pip nor pip3 was found, is it in the PATH?", fg="red")
return

if pip is None:
Expand Down
32 changes: 16 additions & 16 deletions ctfcli/utils/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def sync_challenge(challenge, ignore=[]):
# Create new flags
if challenge.get("flags") and "flags" not in ignore:
# Delete existing flags
current_flags = s.get(f"/api/v1/flags", json=data).json()["data"]
current_flags = s.get("/api/v1/flags", json=data).json()["data"]
for flag in current_flags:
if flag["challenge_id"] == challenge_id:
flag_id = flag["id"]
Expand All @@ -88,11 +88,11 @@ def sync_challenge(challenge, ignore=[]):
for flag in challenge["flags"]:
if type(flag) == str:
data = {"content": flag, "type": "static", "challenge_id": challenge_id}
r = s.post(f"/api/v1/flags", json=data)
r = s.post("/api/v1/flags", json=data)
r.raise_for_status()
elif type(flag) == dict:
flag["challenge_id"] = challenge_id
r = s.post(f"/api/v1/flags", json=flag)
r = s.post("/api/v1/flags", json=flag)
r.raise_for_status()

# Update topics
Expand All @@ -110,7 +110,7 @@ def sync_challenge(challenge, ignore=[]):
# Add new challenge topics
for topic in challenge["topics"]:
r = s.post(
f"/api/v1/topics",
"/api/v1/topics",
json={
"value": topic,
"type": "challenge",
Expand All @@ -122,22 +122,22 @@ def sync_challenge(challenge, ignore=[]):
# Update tags
if challenge.get("tags") and "tags" not in ignore:
# Delete existing tags
current_tags = s.get(f"/api/v1/tags", json=data).json()["data"]
current_tags = s.get("/api/v1/tags", json=data).json()["data"]
for tag in current_tags:
if tag["challenge_id"] == challenge_id:
tag_id = tag["id"]
r = s.delete(f"/api/v1/tags/{tag_id}", json=True)
r.raise_for_status()
for tag in challenge["tags"]:
r = s.post(
f"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag}
"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag}
)
r.raise_for_status()

# Upload files
if challenge.get("files") and "files" not in ignore:
# Delete existing files
all_current_files = s.get(f"/api/v1/files?type=challenge", json=data).json()[
all_current_files = s.get("/api/v1/files?type=challenge", json=data).json()[
"data"
]
for f in all_current_files:
Expand All @@ -158,13 +158,13 @@ def sync_challenge(challenge, ignore=[]):

data = {"challenge_id": challenge_id, "type": "challenge"}
# Specifically use data= here instead of json= to send multipart/form-data
r = s.post(f"/api/v1/files", files=files, data=data)
r = s.post("/api/v1/files", files=files, data=data)
r.raise_for_status()

# Create hints
if challenge.get("hints") and "hints" not in ignore:
# Delete existing hints
current_hints = s.get(f"/api/v1/hints", json=data).json()["data"]
current_hints = s.get("/api/v1/hints", json=data).json()["data"]
for hint in current_hints:
if hint["challenge_id"] == challenge_id:
hint_id = hint["id"]
Expand All @@ -181,7 +181,7 @@ def sync_challenge(challenge, ignore=[]):
"challenge_id": challenge_id,
}

r = s.post(f"/api/v1/hints", json=data)
r = s.post("/api/v1/hints", json=data)
r.raise_for_status()

# Update requirements
Expand Down Expand Up @@ -246,18 +246,18 @@ def create_challenge(challenge, ignore=[]):
for flag in challenge["flags"]:
if type(flag) == str:
data = {"content": flag, "type": "static", "challenge_id": challenge_id}
r = s.post(f"/api/v1/flags", json=data)
r = s.post("/api/v1/flags", json=data)
r.raise_for_status()
elif type(flag) == dict:
flag["challenge"] = challenge_id
r = s.post(f"/api/v1/flags", json=flag)
r = s.post("/api/v1/flags", json=flag)
r.raise_for_status()

# Create topics
if challenge.get("topics") and "topics" not in ignore:
for topic in challenge["topics"]:
r = s.post(
f"/api/v1/topics",
"/api/v1/topics",
json={
"value": topic,
"type": "challenge",
Expand All @@ -270,7 +270,7 @@ def create_challenge(challenge, ignore=[]):
if challenge.get("tags") and "tags" not in ignore:
for tag in challenge["tags"]:
r = s.post(
f"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag}
"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag}
)
r.raise_for_status()

Expand All @@ -288,7 +288,7 @@ def create_challenge(challenge, ignore=[]):

data = {"challenge_id": challenge_id, "type": "challenge"}
# Specifically use data= here instead of json= to send multipart/form-data
r = s.post(f"/api/v1/files", files=files, data=data)
r = s.post("/api/v1/files", files=files, data=data)
r.raise_for_status()

# Add hints
Expand All @@ -303,7 +303,7 @@ def create_challenge(challenge, ignore=[]):
"challenge_id": challenge_id,
}

r = s.post(f"/api/v1/hints", json=data)
r = s.post("/api/v1/hints", json=data)
r.raise_for_status()

# Add requirements
Expand Down
4 changes: 2 additions & 2 deletions ctfcli/utils/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def get_current_pages():
s = generate_session()
return s.get(f"/api/v1/pages", json=True).json()["data"]
return s.get("/api/v1/pages", json=True).json()["data"]


def get_existing_page(route, pageset=None):
Expand Down Expand Up @@ -67,5 +67,5 @@ def install_page(matter, path_obj):
"auth_required": auth_required,
"format": format,
}
r = s.post(f"/api/v1/pages", json=data)
r = s.post("/api/v1/pages", json=data)
r.raise_for_status()
5 changes: 1 addition & 4 deletions development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ twine==3.1.1
setuptools==46.1.3
wheel==0.34.2
black==19.10b0
flake8==3.7.9
flake8-bugbear==20.1.2
flake8-comprehensions==3.1.4
isort==4.3.21
flake8-isort==2.8.0
ruff==0.0.254