Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
epicserve committed Oct 19, 2024
1 parent f3ca0a6 commit a284a9e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
12 changes: 9 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ format: format_just format_python

@format_just:
just _start_command "Formatting Justfile"
ruff format
just --fmt --unstable

@format_python:
just _start_command "Formatting Python"
ruff format
uv run ruff format

@pre_commit: format test
@lint: lint_python

@lint_python:
just _start_command "Linting Python"
uv run ruff check

@pre_commit: format lint test

@test:
uv run pytest
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ ignore = ["D100", "D101", "D102", "D103", "D104", "D106", "D203", "D212"]

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder", ]

[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = ["S101"]
10 changes: 5 additions & 5 deletions scripts/update_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import requests

from dj_beat_drop.utils import red, get_latest_django_version, get_lts_django_version
from dj_beat_drop.utils import color, get_latest_django_version, get_lts_django_version


def download_django(version):
template_url = f"https://github.com/django/django/archive/refs/tags/{version}.zip"
target_dir = f"/tmp/django_template/{version}"
response = requests.get(template_url)
target_dir = f"/tmp/django_template/{version}" # noqa: S108
response = requests.get(template_url, timeout=10)
if response.status_code != 200:
red("Failed to download the Django template.")
color.red("Failed to download the Django template.")
else:
with zipfile.ZipFile(BytesIO(response.content)) as zip_ref:
zip_ref.extractall(target_dir)
Expand All @@ -36,7 +36,7 @@ def main():
lts_version, lts_minor_version = get_lts_django_version()
download_dir = download_django(lts_version)
copy_template_dir(download_dir, lts_version, lts_minor_version)
shutil.rmtree("/tmp/django_template")
shutil.rmtree("/tmp/django_template") # noqa: S108


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions src/dj_beat_drop/main_cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import argparse

import requests

from dj_beat_drop.new import handle_new
from pkg_resources import get_distribution, parse_version

from dj_beat_drop.new import handle_new
from dj_beat_drop.utils import green


Expand All @@ -23,12 +22,13 @@ def check_version():
package_name = "dj-beat-drop"
current_version = get_distribution(package_name).version

response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
response = requests.get(f"https://pypi.org/pypi/{package_name}/json", timeout=10)
latest_version = response.json()["info"]["version"]

if parse_version(current_version) < parse_version(latest_version):
green(
f"\033[0;33m\nA new version of {package_name} is available ({latest_version}). You are using {current_version}. To update, run:\n\033[0m"
f"\033[0;33m\nA new version of {package_name} is available ({latest_version}). You are using "
f"{current_version}. To update, run:\n\033[0m"
)
print(f" pip install --upgrade {package_name}\n")

Expand Down
10 changes: 5 additions & 5 deletions src/dj_beat_drop/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def create_new_project(

if initialize_uv is True:
os.chdir(project_dir)
os.system("uv init")
os.system("rm hello.py")
os.system(f"uv add django~='{minor_version}'")
os.system("uv init") # noqa: S605, S607
os.system("rm hello.py") # noqa: S605, S607
os.system(f"uv add django~='{minor_version}'") # noqa: S605
if initialize_env is True:
os.system("uv add environs[django]")
os.system("uv run manage.py migrate")
os.system("uv add environs[django]") # noqa: S605, S607
os.system("uv run manage.py migrate") # noqa: S605, S607

color.green("New Django project created.\n")

Expand Down
6 changes: 2 additions & 4 deletions src/dj_beat_drop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def red(text):

@lru_cache
def get_django_releases():
response = requests.get("https://pypi.org/pypi/Django/json")
response = requests.get("https://pypi.org/pypi/Django/json", timeout=10)
if response.status_code == 200:
data = response.json()
return {"latest": data["info"]["version"], "releases": data["releases"]}
Expand Down Expand Up @@ -63,8 +63,6 @@ def get_template_context(*, use_lts: bool):


def get_secret_key():
"""
Return a 50 character random string usable as a SECRET_KEY setting value.
"""
"""Return a 50 character random string usable as a SECRET_KEY setting value."""
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
return "".join(secrets.choice(chars) for _ in range(50))
6 changes: 3 additions & 3 deletions tests/test_new_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from dj_beat_drop.new import create_new_project


ENV_SECRET_KEY_PATTERN = 'SECRET_KEY = env.str("SECRET_KEY")'
ENV_SECRET_KEY_PATTERN = 'SECRET_KEY = env.str("SECRET_KEY")' # noqa: S105
FILE_ASSERTIONS = {
"manage.py": [
"os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')",
Expand Down Expand Up @@ -61,7 +60,8 @@

class SafeDict(dict):
def __missing__(self, key):
return f"{{{key}}}" # Keeps the original placeholder if the key is missing
"""Make sure to keep the original placeholder if the key is missing."""
return f"{{{key}}}"


class TestNewCommand(TestCase):
Expand Down

0 comments on commit a284a9e

Please sign in to comment.