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 test for windows #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use the retry library to delete a directory on Windows
  • Loading branch information
epicserve committed Oct 19, 2024
commit 8254fcdf3d2c83e45e6c676b5be80824a5a122c6
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ requires-python = ">=3.10"
dependencies = [
"inquirerpy>=0.3.4",
"requests>=2.32.3",
"retry>=0.9.2",
"setuptools>=75.1.0",
]

Expand Down
4 changes: 2 additions & 2 deletions src/dj_beat_drop/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from InquirerPy import inquirer

from dj_beat_drop import utils
from dj_beat_drop.utils import color
from dj_beat_drop.utils import color, remove_directory


def rename_template_files(project_dir):
Expand Down Expand Up @@ -125,7 +125,7 @@ def handle_new(name: str, use_lts: bool, overwrite_target_dir: bool) -> None:
if overwrite_response is False:
color.red("Operation cancelled.")
return
shutil.rmtree(project_dir)
remove_directory(project_dir)

initialize_uv = inquirer.confirm(message="Initialize your project with UV?", default=True).execute()
initialize_env = inquirer.confirm(
Expand Down
8 changes: 8 additions & 0 deletions src/dj_beat_drop/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import secrets
import shutil
from functools import lru_cache

import requests
from retry import retry


class Color:
Expand Down Expand Up @@ -66,3 +68,9 @@ def get_secret_key():
"""Return a 50 character random string usable as a SECRET_KEY setting value."""
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
return "".join(secrets.choice(chars) for _ in range(50))


@retry(tries=5, delay=2, backoff=2, exceptions=(PermissionError,))
def remove_directory(path):
"""Use retry to handle PermissionError when trying to remove a directory on Windows."""
shutil.rmtree(path)
6 changes: 3 additions & 3 deletions tests/test_new_command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import random
import re
import shutil
import string
from pathlib import Path
from unittest import TestCase

from dj_beat_drop.new import create_new_project
from dj_beat_drop.utils import remove_directory

ENV_SECRET_KEY_PATTERN = 'SECRET_KEY = env.str("SECRET_KEY")' # noqa: S105
FILE_ASSERTIONS = {
Expand Down Expand Up @@ -82,11 +82,11 @@ def setUp(self):
"initialize_env": True,
}
if self.project_dir.exists():
shutil.rmtree(self.project_dir)
remove_directory(self.project_dir)

def tearDown(self):
if self.project_dir.exists():
shutil.rmtree(self.project_dir)
remove_directory(self.project_dir)

@staticmethod
def assert_files_are_correct(
Expand Down
33 changes: 33 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading