Skip to content

Commit

Permalink
made config version special again 🤷‍♂️
Browse files Browse the repository at this point in the history
  • Loading branch information
christophevg committed Apr 3, 2024
1 parent 3a539d6 commit 4ab9e25
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions pypi_template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def __init__(self):
# key/value substitution/template variables
self._template_vars = {}

# system vars that are in the .pypi-template
self._system_template_vars = {
"version" : __version__
}

# all templates
self._templates = {}

Expand Down Expand Up @@ -214,11 +219,13 @@ def save(self):
"""
Save the current set of variables to `.pypi-template` (chainable)
"""
self["version"] = self.version
if self._changes:
if self._going_to("💾 saving variables"):
with open(".pypi-template", "w", encoding="utf-8") as outfile:
yaml.safe_dump(self._template_vars, outfile, default_flow_style=False)
yaml.safe_dump(
{**self._template_vars, **self._system_template_vars},
outfile, default_flow_style=False
)
self._changes = {}
return self

Expand Down Expand Up @@ -257,8 +264,9 @@ def _check_uninitialized_variables(self):

def _check_config_version(self):
# notify if version in config isn't current
if self["version"] != self.version:
print(f"🚨 pypi-template config version {self['version']} != {self.version}")
config_version = self._system_template_vars["version"]
if config_version != self.version:
print(f"🚨 pypi-template config version {config_version} != {self.version}")
print( " 👉 issue 'save' to update!")
return False
return True
Expand All @@ -282,13 +290,25 @@ def __setitem__(self, var, value):
"new" : value
}

def __delitem__(self, key):
del self._template_vars[key]

# variables helpers

def _load_vars(self):
try:
with open(".pypi-template", encoding="utf-8") as fp:
self._template_vars = yaml.safe_load(fp)
except Exception:
self._debugging(f"💾 loaded .pypy-template")

Check failure on line 302 in pypi_template/__init__.py

View workflow job for this annotation

GitHub Actions / build (3.8)

Ruff (F541)

pypi_template/__init__.py:302:23: F541 f-string without any placeholders

Check failure on line 302 in pypi_template/__init__.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F541)

pypi_template/__init__.py:302:23: F541 f-string without any placeholders

Check failure on line 302 in pypi_template/__init__.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F541)

pypi_template/__init__.py:302:23: F541 f-string without any placeholders
for key, value in self._template_vars.items():
self._debugging(f" {key} = {value} {'⚙️' if key in self._system_template_vars else ''}")
# move the version to the system_template_vars
# since it isn't a real (template) var
for key in self._system_template_vars.keys():
self._system_template_vars[key] = self._template_vars.pop("version", None)
except FileNotFoundError:
pass
except KeyError:
pass

def _load_personal_default_values(self):
Expand Down

0 comments on commit 4ab9e25

Please sign in to comment.