Skip to content

Commit

Permalink
Replace safe_mkdir(path) with os.makedirs(path, exist_ok=True) (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Nov 10, 2024
2 parents 255d115 + 5934d4f commit e17700d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ def __exit__(self, *args):
os.chdir(self.previous_cwd)


def safe_mkdir(path):
if not os.path.exists(path):
os.makedirs(path)


def version_key(element):
fields = list(element.split("."))
if len(fields) == 1:
Expand Down Expand Up @@ -560,7 +555,7 @@ def __str__(self):

def save(self, path):
dirname = os.path.dirname(path)
safe_mkdir(dirname)
os.makedirs(dirname, exist_ok=True)

text = str(self)
with open(path, "wt", encoding="utf-8") as file:
Expand Down Expand Up @@ -1178,12 +1173,12 @@ def populate():
Creates and populates the Misc/NEWS.d directory tree.
"""
os.chdir("Misc")
safe_mkdir("NEWS.d/next")
os.makedirs("NEWS.d/next", exist_ok=True)

for section in sections:
dir_name = sanitize_section(section)
dir_path = f"NEWS.d/next/{dir_name}"
safe_mkdir(dir_path)
os.makedirs(dir_path, exist_ok=True)
readme_path = f"NEWS.d/next/{dir_name}/README.rst"
with open(readme_path, "wt", encoding="utf-8") as readme:
readme.write(f"Put news entry ``blurb`` files for the *{section}* section in this directory.\n")
Expand Down

0 comments on commit e17700d

Please sign in to comment.