Skip to content

Commit

Permalink
Merge pull request #17 from blink1073/ensure-newline
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 14, 2022
2 parents 91bbb3e + 870a705 commit 246b692
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Tests

on: [push]
on:
push:
branches: ["master"]
pull_request:
# Run once a day.
schedule:
- cron: "0 8 * * *"

concurrency:
group: 'tests-${{ github.head_ref || github.run_id }}'
Expand Down
8 changes: 7 additions & 1 deletion hatch_nodejs_version/version_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ def set_version(self, version: str, version_data):
if not os.path.isfile(path):
raise OSError(f"file does not exist: {self.path}")

# Read the original file so we can see if it has a trailing
# newline character.
with open(path, "r") as f:
data = json.load(f)
raw_data = f.read()

data = json.loads(raw_data)

data["version"] = self.python_version_to_node(version)
with open(path, "w") as f:
json.dump(data, f, indent=4)
if raw_data.endswith('\n'):
f.write('\n')

0 comments on commit 246b692

Please sign in to comment.