Skip to content

Commit

Permalink
Merge pull request #1527 from zoli111/master
Browse files Browse the repository at this point in the history
Use Mako instead of Jinja2
  • Loading branch information
TheJJ authored Aug 6, 2023
2 parents 3ca720b + 4c541ed commit 58cb4d7
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macosx-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
# cython, numpy and pygments are in homebrew,
# but "cython is keg-only, which means it was not symlinked into /usr/local"
# numpy pulls gcc as dep? and pygments doesn't work.
run: pip3 install --upgrade cython numpy jinja2 lz4 pillow pygments toml
run: pip3 install --upgrade cython numpy mako lz4 pillow pygments toml
- name: Configure
run: |
CLANG_PATH="$HOME/clang-15.0.0/bin/clang++"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-server-2019.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install dependencies [Python]
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade Cython wheel numpy lz4 toml pillow pygments pyreadline3 Jinja2
python -m pip install --upgrade Cython wheel numpy lz4 toml pillow pygments pyreadline3 mako
shell: pwsh
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-server-2022.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install dependencies [Python]
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade Cython wheel numpy lz4 toml pillow pygments pyreadline3 Jinja2
python -m pip install --upgrade Cython wheel numpy lz4 toml pillow pygments pyreadline3 mako
shell: pwsh
- name: Build
run: |
Expand Down
4 changes: 2 additions & 2 deletions buildsystem/CheckRuntimeDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2015-2022 the openage authors. See copying.md for legal info.
# Copyright 2015-2023 the openage authors. See copying.md for legal info.

# python modules
# a list of imported modules may be obtained via
#
# grep -RE '^ *(import |from [^.])' | cut -d: -f2- | \
# sed 's/^ *//g' | sort -u | grep -v openage
set(REQUIRED_PYTHON_MODULES "PIL.Image" "PIL.ImageDraw" "numpy" "pygments" "jinja2" "toml" "lz4")
set(REQUIRED_PYTHON_MODULES "PIL.Image" "PIL.ImageDraw" "numpy" "pygments" "mako.template" "toml" "lz4")

# command-line tools
# example: set(REQUIRED_UTILITIES "foobar")
Expand Down
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ _the openage authors_ are:
| Tarun Samanta | TS | tarunsamanta77 à gmail dawt com |
| Derek Frogget | FoggyLight | fro22003 à byui dawt edu |
| Martin | Starman | mstarman à seznam dawt cz |
| Zoltán Ács | zoli111 | acszoltan111 à gmail dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
2 changes: 1 addition & 1 deletion doc/build_instructions/arch_linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This command should provide required packages for Arch Linux installation:

`sudo pacman -S --needed eigen python python-jinja python-pillow python-numpy python-lz4 python-pygments cython libepoxy libogg libpng ttf-dejavu freetype2 fontconfig harfbuzz cmake sdl2 sdl2_image opusfile opus python-pylint python-toml qt6-declarative`
`sudo pacman -S --needed eigen python python-mako python-pillow python-numpy python-lz4 python-pygments cython libepoxy libogg libpng ttf-dejavu freetype2 fontconfig harfbuzz cmake sdl2 sdl2_image opusfile opus python-pylint python-toml qt6-declarative`

If you don't have a compiler installed, you can select between these commands to install it:
- `sudo pacman -S --needed gcc`
Expand Down
2 changes: 1 addition & 1 deletion doc/build_instructions/debian.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prerequisite steps for Debian Sid users

- `sudo apt-get update`
- `sudo apt-get install cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libsdl2-dev libsdl2-image-dev libtoml11-dev python3-dev python3-jinja2 python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev`
- `sudo apt-get install cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libsdl2-dev libsdl2-image-dev libtoml11-dev python3-dev python3-mako python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev`

You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.
2 changes: 1 addition & 1 deletion doc/build_instructions/fedora.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Run the following command:

`sudo dnf install clang cmake eigen3-devel fontconfig-devel gcc-c harfbuzz-devel libepoxy-devel libogg-devel libopusenc-devel libpng-devel opusfile-devel python3-Cython python3-devel python3-jinja2 python3-numpy python3-lz4 python3-pillow python3-pygments python3-toml SDL2-devel SDL2_image-devel++ toml11-devel qt6-qtdeclarative-devel`
`sudo dnf install clang cmake eigen3-devel fontconfig-devel gcc-c harfbuzz-devel libepoxy-devel libogg-devel libopusenc-devel libpng-devel opusfile-devel python3-Cython python3-devel python3-mako python3-numpy python3-lz4 python3-pillow python3-pygments python3-toml SDL2-devel SDL2_image-devel++ toml11-devel qt6-qtdeclarative-devel`

You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.
2 changes: 1 addition & 1 deletion doc/build_instructions/freebsd.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This command should provide required packages for FreeBSD installation:

`sudo pkg install cmake cython eigen3 harfbuzz opus-tools opusfile png py-numpy py-lz4 py-pillow py-pygments py-toml pylint python qt6 sdl2 sdl2_image toml11`
`sudo pkg install cmake cython eigen3 harfbuzz opus-tools opusfile png py-mako py-numpy py-lz4 py-pillow py-pygments py-toml pylint python qt6 sdl2 sdl2_image toml11`

You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.

Expand Down
2 changes: 1 addition & 1 deletion doc/build_instructions/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ brew tap homebrew/cask-fonts
brew install font-dejavu
brew install cmake python3 libepoxy freetype fontconfig harfbuzz sdl2 sdl2_image opus opusfile qt6 libogg libpng toml11 eigen
brew install llvm
pip3 install cython numpy jinja2 lz4 pillow pygments toml
pip3 install cython numpy mako lz4 pillow pygments toml
# optional, for documentation generation
brew install doxygen
Expand Down
2 changes: 1 addition & 1 deletion doc/build_instructions/opensuse.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Prerequisite steps for openSUSE users

- `zypper install --no-recommends cmake doxygen eigen3-devel fontconfig-devel gcc-c graphviz++ harfbuzz-devel libSDL2-devel libSDL2_image-devel libepoxy-devel libfreetype6 libogg-devel libopus-devel libpng-devel libtoml11-dev libqt6-qtdeclarative-devel libqt6-qtquickcontrols opusfile-devel python3-Cython python3-Jinja2 python3-lz4 python3-Pillow python3-Pygments python3-toml python3-devel`
- `zypper install --no-recommends cmake doxygen eigen3-devel fontconfig-devel gcc-c graphviz++ harfbuzz-devel libSDL2-devel libSDL2_image-devel libepoxy-devel libfreetype6 libogg-devel libopus-devel libpng-devel libtoml11-dev libqt6-qtdeclarative-devel libqt6-qtquickcontrols opusfile-devel python3-Cython python3-Mako python3-lz4 python3-Pillow python3-Pygments python3-toml python3-devel`

You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.
2 changes: 1 addition & 1 deletion doc/build_instructions/ubuntu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Run the following commands:

- `sudo apt-get update`
- `sudo apt-get install g++ cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libsdl2-dev libsdl2-image-dev libtoml11-dev python3-dev python3-jinja2 python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev`
- `sudo apt-get install g++ cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libsdl2-dev libsdl2-image-dev libtoml11-dev python3-dev python3-mako python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev`

You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.
2 changes: 1 addition & 1 deletion doc/build_instructions/windows_msvc.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ __NOTE:__ You need to manually make sure and doublecheck if the system you are b
### Python Modules
Open a command prompt at `<Python 3 installation directory>/Scripts`

pip install cython numpy lz4 toml pillow pygments pyreadline3 Jinja2
pip install cython numpy lz4 toml pillow pygments pyreadline3 mako

_Note:_ Make sure the Python 3 instance you're installing these scripts for is the one you call `python` in CMD
_Note:_ Also ensure that `python` and `python3` both point to the correct and the same version of Python 3
Expand Down
2 changes: 1 addition & 1 deletion doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Dependency list:
C O include-what-you-use
CR nyan (https://github.com/SFTtech/nyan)
CR O ncurses
C jinja2
C mako
CR sdl2
CR sdl2_image
CR opusfile
Expand Down
4 changes: 2 additions & 2 deletions libopenage/coord/coord.cpp.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2016-2016 the openage authors. See copying.md for legal info.
// Copyright 2016-2023 the openage authors. See copying.md for legal info.

{{ "#" }}include "coord_{{ formatted_members("{}", join_with="") }}.gen.h"
${"#"}include "coord_${formatted_members("{}", join_with="")}.gen.h"

#include <cstdio>

Expand Down
60 changes: 30 additions & 30 deletions libopenage/coord/coord.h.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2019 the openage authors. See copying.md for legal info.
// Copyright 2016-2023 the openage authors. See copying.md for legal info.

#pragma once

Expand All @@ -8,7 +8,7 @@ namespace openage {
namespace coord {

/**
* Template class for all coordinate types that have the members ({{ formatted_members("{}") }}).
* Template class for all coordinate types that have the members (${formatted_members("{}")}).
*
* There is a distinction between relative and absolute coordinate values
* to disallow semantically-nonsensical origin-sensitive operations:
Expand All @@ -26,39 +26,39 @@ namespace coord {
* derived class (CRTP).
*/
template<typename CoordType, typename Absolute, typename Relative>
struct Coord{{ camelcase }}Absolute {
struct Coord${camelcase}Absolute {

using elem_t = CoordType;

// The member variables to store the actual data.
{{ formatted_members("CoordType {0};", join_with="\n\t") }}
${formatted_members("CoordType {0};", join_with="\n\t")}

/**
* We don't want to have a default constructor,
* because zero-initialization of absolute coordinates is
* origin-sensitive and thus non-sensical.
*/
Coord{{ camelcase }}Absolute() = delete;
Coord${camelcase}Absolute() = delete;

/**
* From-individual-values constructor
*/
constexpr Coord{{ camelcase }}Absolute({{ formatted_members("const CoordType &{}") }}) : {{ formatted_members("{0}{{{0}}}") }} {}
constexpr Coord${camelcase}Absolute(${formatted_members("const CoordType &{}")}) : ${formatted_members("{0}{{{0}}}")} {}

// copy constructor + assignment operator
constexpr Coord{{ camelcase }}Absolute(const Coord{{ camelcase }}Absolute &other) = default;
constexpr Coord{{ camelcase }}Absolute &operator =(const Coord{{ camelcase }}Absolute &other) = default;
constexpr Coord${camelcase}Absolute(const Coord${camelcase}Absolute &other) = default;
constexpr Coord${camelcase}Absolute &operator =(const Coord${camelcase}Absolute &other) = default;

constexpr Absolute operator +(const Relative &other) const {
return Absolute({{ formatted_members("this->{0} + other.{0}") }});
return Absolute(${formatted_members("this->{0} + other.{0}")});
}

constexpr Relative operator -(const Absolute &other) const {
return Relative({{ formatted_members("this->{0} - other.{0}") }});
return Relative(${formatted_members("this->{0} - other.{0}")});
}

constexpr Absolute operator -(const Relative &other) const {
return Absolute({{ formatted_members("this->{0} - other.{0}") }});
return Absolute(${formatted_members("this->{0} - other.{0}")});
}

constexpr Absolute &operator +=(const Relative &other) {
Expand All @@ -72,7 +72,7 @@ struct Coord{{ camelcase }}Absolute {
}

constexpr bool operator ==(const Absolute &other) const {
return {{ formatted_members("(this->{0} == other.{0})", join_with=" && ") }};
return ${formatted_members("(this->{0} == other.{0})", join_with=" && ")};
}

constexpr bool operator !=(const Absolute &other) const {
Expand All @@ -89,54 +89,54 @@ struct Coord{{ camelcase }}Absolute {
* derived class (CRTP).
*/
template<typename CoordType, typename Absolute, typename Relative>
struct Coord{{ camelcase }}Relative {
struct Coord${camelcase}Relative {
using elem_t = CoordType;

// The member variables to store the actual data.
{{ formatted_members("CoordType {0};", join_with="\n\t") }}
${formatted_members("CoordType {0};", join_with="\n\t")}

/**
* Default constructor: sets the values to their defaults.
*/
Coord{{ camelcase }}Relative() : {{ formatted_members("{}{{}}") }} {}
Coord${camelcase}Relative() : ${formatted_members("{}{{}}")} {}

/**
* From-individual-values constructor
*/
constexpr Coord{{ camelcase }}Relative({{ formatted_members("const CoordType &{}") }}) : {{ formatted_members("{0}{{{0}}}") }} {}
constexpr Coord${camelcase}Relative(${formatted_members("const CoordType &{}")}) : ${formatted_members("{0}{{{0}}}")} {}

// copy constructor and assignment operator
constexpr Coord{{ camelcase }}Relative(const Coord{{ camelcase }}Relative &other) = default;
constexpr Coord{{ camelcase }}Relative &operator =(const Coord{{ camelcase }}Relative &other) = default;
constexpr Coord${camelcase}Relative(const Coord${camelcase}Relative &other) = default;
constexpr Coord${camelcase}Relative &operator =(const Coord${camelcase}Relative &other) = default;

constexpr Relative operator +() const {
return Relative({{ formatted_members("+this->{}") }});
return Relative(${formatted_members("+this->{}")});
}

constexpr Relative operator -() const {
return Relative({{ formatted_members("-this->{}") }});
return Relative(${formatted_members("-this->{}")});
}

constexpr Absolute operator +(const Absolute &other) const {
return Absolute({{ formatted_members("this->{0} + other.{0}") }});
return Absolute(${formatted_members("this->{0} + other.{0}")});
}

constexpr Relative operator +(const Relative &other) const {
return Relative({{ formatted_members("this->{0} + other.{0}") }});
return Relative(${formatted_members("this->{0} + other.{0}")});
}

constexpr Relative operator -(const Relative &other) const {
return Relative({{ formatted_members("this->{0} - other.{0}") }});
return Relative(${formatted_members("this->{0} - other.{0}")});
}

template<typename ScalarType>
constexpr Relative operator *(const ScalarType &scalar) const {
return Relative({{ formatted_members("this->{0} * scalar") }});
return Relative(${formatted_members("this->{0} * scalar")});
}

template<typename ScalarType>
constexpr Relative operator /(const ScalarType &scalar) const {
return Relative({{ formatted_members("this->{} / scalar") }});
return Relative(${formatted_members("this->{} / scalar")});
}

constexpr Relative &operator +=(const Relative &other) {
Expand All @@ -162,7 +162,7 @@ struct Coord{{ camelcase }}Relative {
}

constexpr bool operator ==(const Relative &other) const {
return {{ formatted_members("(this->{0} == other.{0})", join_with=" && ") }};
return ${formatted_members("(this->{0} == other.{0})", join_with=" && ")};
}

constexpr bool operator !=(const Relative &other) const {
Expand All @@ -172,15 +172,15 @@ struct Coord{{ camelcase }}Relative {


template<typename CoordType, typename Absolute, typename Relative>
std::ostream &operator <<(std::ostream &os, Coord{{ camelcase }}Absolute<CoordType, Absolute, Relative> coord) {
os << "[{{ formatted_members('{0}: " << coord.{0} << "') }}]";
std::ostream &operator <<(std::ostream &os, Coord${camelcase}Absolute<CoordType, Absolute, Relative> coord) {
os << "[${formatted_members('{0}: " << coord.{0} << "')}]";
return os;
}


template<typename CoordType, typename Absolute, typename Relative>
std::ostream &operator <<(std::ostream &os, Coord{{ camelcase }}Relative<CoordType, Absolute, Relative> coord) {
os << "({{ formatted_members('{0}: " << coord.{0} << "') }})";
std::ostream &operator <<(std::ostream &os, Coord${camelcase}Relative<CoordType, Absolute, Relative> coord) {
os << "(${formatted_members('{0}: " << coord.{0} << "')})";
return os;
}

Expand Down
2 changes: 1 addition & 1 deletion openage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
f"Python {config.PYTHONINTERPRETER}\n"
f"Python C API {config.PYTHONCAPI}\n"
f"Cython {config.CYTHONVERSION}\n"
f"Jinja2 {config.JINJAVERSION}\n"
f"Mako {config.MAKOVERSION}\n"
f"NumPy {config.NUMPYVERSION}\n"
f"Pillow {config.PILVERSION}\n"
f"Pygments {config.PYGMENTSVERSION}\n"
Expand Down
12 changes: 6 additions & 6 deletions openage/codegen/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Generates libopenage/coord/coord_{xy, xyz, ne_se, ne_se_up}.{h, cpp}
"""

from jinja2 import Template
from mako.template import Template


def generate_coord_basetypes(projectdir):
Expand All @@ -23,12 +23,12 @@ def generate_coord_basetypes(projectdir):
]

# this list maps template file name to output file name.
# the output filename is a jinja2 template itself.
# the output filename is a mako template itself.
template_files_spec = [
("libopenage/coord/coord.h.template",
"libopenage/coord/coord_{{ ''.join(members) }}.gen.h"),
"libopenage/coord/coord_${''.join(members)}.gen.h"),
("libopenage/coord/coord.cpp.template",
"libopenage/coord/coord_{{ ''.join(members) }}.gen.cpp")
"libopenage/coord/coord_${''.join(members)}.gen.cpp")
]

templates = []
Expand Down Expand Up @@ -56,9 +56,9 @@ def format_members(formatstring, join_with=", "):
}

for template, output_filename_template in templates:
output_filename = output_filename_template.render(template_dict)
output_filename = output_filename_template.render(**template_dict)
with projectdir.joinpath(output_filename).open("w") as output_file:
output = template.render(template_dict)
output = template.render(**template_dict)
output_file.write(output)
if not output.endswith('\n'):
output_file.write('\n')
6 changes: 3 additions & 3 deletions openage/config.py.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2020 the openage authors. See copying.md for legal info.
# Copyright 2014-2023 the openage authors. See copying.md for legal info.

# ${AUTOGEN_WARNING}

Expand All @@ -12,7 +12,7 @@ Project configuration, written by the build system.
import sys
import importlib
import cython
import jinja2
import mako
import numpy
import PIL
import pygments
Expand All @@ -33,7 +33,7 @@ CICFGVERSION = "${CI_CFG_VERSION}"
PYTHONINTERPRETER = sys.version
PYTHONCAPI = sys.api_version
CYTHONVERSION = cython.__version__
JINJAVERSION = jinja2.__version__
MAKOVERSION = mako.__version__
NUMPYVERSION = numpy.__version__
PILVERSION = PIL.__version__
PYGMENTSVERSION = pygments.__version__
Expand Down
2 changes: 1 addition & 1 deletion packaging/docker/devenv/Dockerfile.ubuntu.2204
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y sudo \
make \
ninja-build \
python3-dev \
python3-jinja2 \
python3-mako \
python3-numpy \
python3-lz4 \
python3-pil \
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pkgs.mkShell {

pkgs.eigen
pkgs.python39
pkgs.python39Packages.jinja2
pkgs.python39Packages.mako
pkgs.python39Packages.pillow
pkgs.python39Packages.numpy
pkgs.python39Packages.lz4
Expand Down

0 comments on commit 58cb4d7

Please sign in to comment.