This commit is contained in:
Olivier 'reivilibre' 2021-03-10 15:22:19 +00:00
parent f5f9ae6ef9
commit 93678709c7
3 changed files with 50 additions and 51 deletions

View File

@ -232,9 +232,7 @@ def convert_textx_recipe(txrecipe_or_subblock, parent: Optional[MenuBlock]):
elif isinstance(directive, scoml_classes["IfSetDirective"]): elif isinstance(directive, scoml_classes["IfSetDirective"]):
var = directive.variable var = directive.variable
assert isinstance(var, str) assert isinstance(var, str)
recipe.control_directives.append( recipe.control_directives.append(IfSetDirective(var))
IfSetDirective(var)
)
else: else:
raise ValueError(f"Unknown directive {directive}") raise ValueError(f"Unknown directive {directive}")
@ -282,9 +280,7 @@ def convert_textx_block(txblock, parent: Optional[MenuBlock]) -> MenuBlock:
elif isinstance(directive, scoml_classes["IfSetDirective"]): elif isinstance(directive, scoml_classes["IfSetDirective"]):
var = directive.variable var = directive.variable
assert isinstance(var, str) assert isinstance(var, str)
block.control_directives.append( block.control_directives.append(IfSetDirective(var))
IfSetDirective(var)
)
elif isinstance(directive, scoml_classes["ImportDirective"]): elif isinstance(directive, scoml_classes["ImportDirective"]):
block.import_directives.append(directive.importee) block.import_directives.append(directive.importee)
elif isinstance(directive, scoml_classes["ResourceEdgeDirective"]): elif isinstance(directive, scoml_classes["ResourceEdgeDirective"]):
@ -469,7 +465,9 @@ class MenuLoader:
assert applicable_user is not None assert applicable_user is not None
sous_vars = self._head.variables[sous] sous_vars = self._head.variables[sous]
for context_vars, for_indices in self._control_apply(fors, sous_vars, tuple()): for context_vars, for_indices in self._control_apply(
fors, sous_vars, tuple()
):
context = RecipeContext( context = RecipeContext(
sous=sous, sous=sous,
user=applicable_user, user=applicable_user,
@ -663,7 +661,10 @@ class MenuLoader:
) )
def _control_apply( def _control_apply(
self, controls: Tuple[ControlDirective, ...], vars: "Variables", accum: Tuple[int, ...] self,
controls: Tuple[ControlDirective, ...],
vars: "Variables",
accum: Tuple[int, ...],
) -> Iterable[Tuple["Variables", Tuple[int, ...]]]: ) -> Iterable[Tuple["Variables", Tuple[int, ...]]]:
if not controls: if not controls:
yield vars, accum yield vars, accum

View File

@ -118,7 +118,9 @@ class Variables:
elif isinstance(current, list): elif isinstance(current, list):
current = current[int(k)] current = current[int(k)]
else: else:
raise ValueError(f"non-dictionary, non-list encountered when getting {name}") raise ValueError(
f"non-dictionary, non-list encountered when getting {name}"
)
return current return current
except KeyError: except KeyError:

View File

@ -12,13 +12,13 @@ from shutil import rmtree
from setuptools import find_packages, setup, Command from setuptools import find_packages, setup, Command
# Package meta-data. # Package meta-data.
NAME = 'scone' NAME = "scone"
DESCRIPTION = 'Simple CONfiguration Engine' DESCRIPTION = "Simple CONfiguration Engine"
URL = 'https://librepush.net/project/scone' URL = "https://librepush.net/project/scone"
EMAIL = 'rei@librepush.net' EMAIL = "rei@librepush.net"
AUTHOR = 'Olivier \'reivilibre\'' AUTHOR = "Olivier 'reivilibre'"
REQUIRES_PYTHON = '>=3.7.0' REQUIRES_PYTHON = ">=3.7.0"
VERSION = '0.1.0' VERSION = "0.1.0"
# What packages are required for this module to be executed? # What packages are required for this module to be executed?
REQUIRED = [ REQUIRED = [
@ -28,7 +28,7 @@ REQUIRED = [
"attrs~=19.3.0", "attrs~=19.3.0",
"cattrs~=1.0.0", "cattrs~=1.0.0",
"canonicaljson~=1.2.0", "canonicaljson~=1.2.0",
"immutabledict==1.0.0" "immutabledict==1.0.0",
] ]
@ -49,14 +49,13 @@ EXTRAS = {
"aiosqlite~=0.15.0", "aiosqlite~=0.15.0",
"requests", "requests",
"Jinja2", "Jinja2",
"typeguard" "typeguard",
], ],
"sous": EX_SOUS_ALL, "sous": EX_SOUS_ALL,
"sous-core": EX_SOUS_BASE, "sous-core": EX_SOUS_BASE,
"sous-pg": EX_SOUS_PG, "sous-pg": EX_SOUS_PG,
"sous-mysql": EX_SOUS_MYSQL, "sous-mysql": EX_SOUS_MYSQL,
"docker": ["docker"], # TODO do this more properly if we can...
"docker": ["docker"] # TODO do this more properly if we can...
} }
# The rest you shouldn't have to touch too much :) # The rest you shouldn't have to touch too much :)
@ -69,8 +68,8 @@ here = os.path.abspath(os.path.dirname(__file__))
# Import the README and use it as the long-description. # Import the README and use it as the long-description.
# Note: this will only work if 'README.md' is present in your MANIFEST.in file! # Note: this will only work if 'README.md' is present in your MANIFEST.in file!
try: try:
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
long_description = '\n' + f.read() long_description = "\n" + f.read()
except FileNotFoundError: except FileNotFoundError:
long_description = DESCRIPTION long_description = DESCRIPTION
@ -78,22 +77,22 @@ except FileNotFoundError:
about = {} about = {}
if not VERSION: if not VERSION:
project_slug = NAME.lower().replace("-", "_").replace(" ", "_") project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
with open(os.path.join(here, project_slug, '__version__.py')) as f: with open(os.path.join(here, project_slug, "__version__.py")) as f:
exec(f.read(), about) exec(f.read(), about)
else: else:
about['__version__'] = VERSION about["__version__"] = VERSION
class UploadCommand(Command): class UploadCommand(Command):
"""Support setup.py upload.""" """Support setup.py upload."""
description = 'Build and publish the package.' description = "Build and publish the package."
user_options = [] user_options = []
@staticmethod @staticmethod
def status(s): def status(s):
"""Prints things in bold.""" """Prints things in bold."""
print('\033[1m{0}\033[0m'.format(s)) print("\033[1m{0}\033[0m".format(s))
def initialize_options(self): def initialize_options(self):
pass pass
@ -103,20 +102,20 @@ class UploadCommand(Command):
def run(self): def run(self):
try: try:
self.status('Removing previous builds…') self.status("Removing previous builds…")
rmtree(os.path.join(here, 'dist')) rmtree(os.path.join(here, "dist"))
except OSError: except OSError:
pass pass
self.status('Building Source and Wheel (universal) distribution…') self.status("Building Source and Wheel (universal) distribution…")
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) os.system("{0} setup.py sdist bdist_wheel --universal".format(sys.executable))
self.status('Uploading the package to PyPI via Twine…') self.status("Uploading the package to PyPI via Twine…")
os.system('twine upload dist/*') os.system("twine upload dist/*")
self.status('Pushing git tags…') self.status("Pushing git tags…")
os.system('git tag v{0}'.format(about['__version__'])) os.system("git tag v{0}".format(about["__version__"]))
os.system('git push --tags') os.system("git push --tags")
sys.exit() sys.exit()
@ -124,10 +123,10 @@ class UploadCommand(Command):
# Where the magic happens: # Where the magic happens:
setup( setup(
name=NAME, name=NAME,
version=about['__version__'], version=about["__version__"],
description=DESCRIPTION, description=DESCRIPTION,
long_description=long_description, long_description=long_description,
long_description_content_type='text/markdown', long_description_content_type="text/markdown",
author=AUTHOR, author=AUTHOR,
author_email=EMAIL, author_email=EMAIL,
python_requires=REQUIRES_PYTHON, python_requires=REQUIRES_PYTHON,
@ -135,12 +134,11 @@ setup(
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
# If your package is a single module, use this instead of 'packages': # If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'], # py_modules=['mypackage'],
entry_points={ entry_points={
'console_scripts': [ "console_scripts": [
'scone=scone.head.cli:cli', "scone=scone.head.cli:cli",
'scone-freezer=scone.head.cli.freezer:cli', "scone-freezer=scone.head.cli.freezer:cli",
'michelin=scone.head.cli.michelin:cli' "michelin=scone.head.cli.michelin:cli",
], ],
}, },
install_requires=REQUIRED, install_requires=REQUIRED,
@ -150,14 +148,12 @@ setup(
classifiers=[ classifiers=[
# Trove classifiers # Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
'Programming Language :: Python', "Programming Language :: Python",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.7', "Programming Language :: Python :: 3.7",
'Programming Language :: Python :: Implementation :: CPython', "Programming Language :: Python :: Implementation :: CPython",
'Programming Language :: Python :: Implementation :: PyPy' "Programming Language :: Python :: Implementation :: PyPy",
], ],
# $ setup.py publish support. # $ setup.py publish support.
cmdclass={ cmdclass={"upload": UploadCommand,},
'upload': UploadCommand,
},
) )