Skip to content
Snippets Groups Projects

h2t/absolute_encoder_calibration: Module for absolute encoder calibration on all robots

Merged Christian Dreher requested to merge feature/absolute_encoder_calibration into main
8 files
+ 227
5
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -36,7 +36,7 @@ $(VENV_ACTIVATE): $(MANIFEST_FILE)
{install_editable_lines}
""".replace(" ", "\t").strip() + "\n"
PREINSTALL_TEMPLATE = '"$(VENV_PIP_BIN)" install "{path}"'
PREINSTALL_TEMPLATE = '"$(VENV_PIP_BIN)" install {path}'
INSTALL_EDITABLE_TEMPLATE = '@"$(VENV_PIP_BIN)" install -e "{path}"'
@classmethod
@@ -84,6 +84,30 @@ $(VENV_ACTIVATE): $(MANIFEST_FILE)
return "\n\t".join(lines)
class SetupPyFile:
TEMPLATE = """
#!/usr/bin/env python
from distutils.core import setup
setup(name="{name}",
version="1.0",
description="{pretty_name}",
author="Axii Auto-Generator",
author_email="axii@h2t",
url="https://git.h2t.iar.kit.edu/",
packages=[],
)
"""
@classmethod
def fill_template(cls, name) -> str:
words = name.split("_")
words = [word.capitalize() for word in words]
pretty_name = " ".join(words)
return cls.TEMPLATE.format(name=name, pretty_name=pretty_name)
@dc.dataclass
class PythonPackage(Hook):
relative_path: str
@@ -94,6 +118,7 @@ class PythonPackage(Hook):
preinstall: ty.List[str] = dc.field(default_factory=list)
install_editable: ty.List[str] = dc.field(default_factory=list)
auto_generate_setup_py: bool = False
def __call__(self, *args, verbose=0, ignore_errors=False, **kwargs) -> common.StepResult:
"""
@@ -112,6 +137,9 @@ class PythonPackage(Hook):
# Create the venv directory, if it does not exist.
os.makedirs(venv_dir, exist_ok=True)
if self.auto_generate_setup_py:
self.generate_and_write_setup_py()
# Create the Makefile if it does not exist.
# We put it _into_ the venv, so it is ignored automatically.
makefile_filename = "Makefile"
@@ -139,7 +167,7 @@ class PythonPackage(Hook):
def content_changed():
assert os.path.isfile(makefile_path), makefile_path
with open(makefile_path, "r") as file:
with open(makefile_path, "r", encoding="utf-8") as file:
current_content = file.read()
return current_content != makefile_content
@@ -153,12 +181,21 @@ class PythonPackage(Hook):
if recreate_makefile:
console.print(f"Generate Makefile in '{venv_dir}' ...")
# Dirs are relative to the venv.
with open(makefile_path, "w") as file:
with open(makefile_path, "w", encoding="utf-8") as file:
file.write(makefile_content)
# Call make.
return common.execute_command(["make"], cwd=os.path.dirname(makefile_path), env={})
def generate_and_write_setup_py(self):
setup_py_path = self.ctx.path
setup_py_file = os.path.join(setup_py_path, "setup.py")
generated_package_name = self.ctx.name.replace("/", "_")
setup_py_contents = SetupPyFile.fill_template(generated_package_name)
with open(setup_py_file, "w", encoding="utf-8") as file:
file.write(setup_py_contents)
def test(self, **kwargs):
pass
Loading