Skip to content

Commit

Permalink
fixed handling of system vars
Browse files Browse the repository at this point in the history
  • Loading branch information
christophevg committed Nov 25, 2024
1 parent 6275c31 commit cb13286
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pypi-template
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ skip:
- tests
- docs
- (package_module_name)
version: 0.5.0
version: 0.8.0
your_author_name: Christophe VG
your_email_address: [email protected]
your_full_name: Christophe VG
Expand Down
30 changes: 20 additions & 10 deletions pypi_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.7.0"
__version__ = "0.8.0"

import os
import datetime
Expand Down Expand Up @@ -49,6 +49,7 @@ class PyPiTemplate():
def __init__(self):
# operational setup
self._be_verbose = False
self._force = False
self._show_debug = False
self._say_yes_to_all = False
self._as_json = False
Expand Down Expand Up @@ -77,7 +78,9 @@ def __init__(self):
self._template_vars = {}

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

Expand Down Expand Up @@ -116,6 +119,13 @@ def verbose(self):
self._be_verbose = True
return self

def force(self):
"""
Force everything that can done. (chainable)
"""
self._force = True
return self

def debug(self):
"""
Don't actually do it, but tell what would have been done. (chainable)
Expand Down Expand Up @@ -219,11 +229,11 @@ def save(self):
"""
Save the current set of variables to `.pypi-template` (chainable)
"""
if self._changes:
if self._changes or self._force:
if self._going_to("💾 saving variables"):
with open(".pypi-template", "w", encoding="utf-8") as outfile:
yaml.safe_dump(
{**self._template_vars, **self._system_template_vars},
{**self._template_vars, **self._system_template_vars_defaults},
outfile, default_flow_style=False
)
self._changes = {}
Expand Down Expand Up @@ -267,7 +277,7 @@ def _check_config_version(self):
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!")
print( " 👉 issue 'force save' to update!")
return False
return True

Expand Down Expand Up @@ -301,11 +311,11 @@ def _load_vars(self):
self._template_vars = yaml.safe_load(fp)
self._debugging("💾 loaded .pypy-template")
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)
self._debugging(f" {key} = {value} {'⚙️' if key in self._system_template_vars_defaults else ''}")
# extract system_template_vars since it aren't real (template) vars
for key in self._system_template_vars_defaults.keys():
self._system_template_vars[key] = self._template_vars.pop(key, None)
except FileNotFoundError:
pass
except KeyError:
Expand Down

0 comments on commit cb13286

Please sign in to comment.