Skip to content

Commit

Permalink
fix personalize.py on Windows (#112)
Browse files Browse the repository at this point in the history
* fix personalize.py on Windows

* fix
  • Loading branch information
epwalsh authored Jul 16, 2023
1 parent 908bdbf commit 3a58ecf
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions scripts/personalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This script is interactive and will prompt you for various inputs.
"""

import sys
from pathlib import Path
from typing import Generator, List, Tuple

Expand Down Expand Up @@ -91,15 +92,7 @@ def main(
if not yes:
raise click.ClickException("Aborted, please run script again")

# Delete files that we don't need.
for path in FILES_TO_REMOVE:
assert path.is_file(), path
if not dry_run:
path.unlink()
else:
print(f"Removing {path}")

# Personalize remaining files.
# Personalize files.
replacements = [
(BASE_URL_TO_REPLACE, repo_url),
(REPO_NAME_TO_REPLACE, github_repo),
Expand All @@ -110,7 +103,8 @@ def main(
for old, new in replacements:
print(f"Replacing '{old}' with '{new}'")
for path in iterfiles(REPO_BASE):
personalize_file(path, dry_run, replacements)
if path.resolve() not in FILES_TO_REMOVE:
personalize_file(path, dry_run, replacements)

# Rename 'my_package' directory to `package_dir_name`.
if not dry_run:
Expand All @@ -132,6 +126,16 @@ def main(
install_example,
)

# Lastly, remove that we don't need.
for path in FILES_TO_REMOVE:
assert path.is_file(), path
if not dry_run:
if path.name == "personalize.py" and sys.platform.startswith("win"):
# We can't unlink/remove an open file on Windows.
print("You can remove the 'scripts/personalize.py' file now")
else:
path.unlink()


def iterfiles(dir: Path) -> Generator[Path, None, None]:
assert dir.is_dir()
Expand Down

0 comments on commit 3a58ecf

Please sign in to comment.