Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
russkel committed Oct 30, 2024
1 parent 570a150 commit c62acaf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
args: ["--line-length=99"]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.1.1
hooks:
- id: flake8
args: ["--ignore=E203, E266, E501, W503, F403, F401 --max-line-length = 99"]
Expand Down
5 changes: 3 additions & 2 deletions platform_cli/groups/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_apt_repo_url(public: bool = False) -> str:
return f"[email protected]:{packages_repo}.git"


def apt_clone(public: bool=False, sparse: bool=False):
def apt_clone(public: bool = False, sparse: bool = False):
"""Checks out the GR apt repo"""
if GR_APT_REPO_PATH.is_dir():
echo(f"Packages repo has already been cloned to {GR_APT_REPO_PATH}", "blue")
Expand Down Expand Up @@ -93,7 +93,7 @@ def apt_push():
raise click.ClickException("Failed to push to apt repo")


def apt_add(deb: Optional[Path]=None, sparse: bool=False):
def apt_add(deb: Optional[Path] = None, sparse: bool = False):
"""Adds a .deb to the GR apt repo"""

if not GR_APT_REPO_PATH.exists():
Expand Down Expand Up @@ -122,6 +122,7 @@ def apt_add(deb: Optional[Path]=None, sparse: bool=False):
cwd=GR_APT_REPO_PATH,
)


class Packaging(PlatformCliGroup):
def create(self, cli: click.Group):
@cli.group(help="Packaging commands")
Expand Down
8 changes: 5 additions & 3 deletions platform_cli/groups/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def check_parents_for_file(filename: str, path: Optional[Path] = None) -> Path:
file_path = current_path / filename
if file_path.exists():
return file_path.parent

if current_path == current_path.parent:
break
else:
Expand All @@ -79,7 +79,9 @@ def get_module_info(path: Optional[Path] = None) -> Optional[ModuleInfo]:
return None


def get_package_info(package_path: Optional[Path] = None, obtain_module_info: bool=True) -> PackageInfo:
def get_package_info(
package_path: Optional[Path] = None, obtain_module_info: bool = True
) -> PackageInfo:
"""
Returns the package info for the directory (or CWD if no path provided).
This assumes the cwd is a package. It will find out the name of the platform module.
Expand Down Expand Up @@ -172,7 +174,7 @@ def get_package_version_from_package_xml(package_xml: Path) -> str:
return root.find("version").text # type: ignore


def find_packages(path: Optional[Path] = None, module_info: bool=True) -> Dict[str, PackageInfo]:
def find_packages(path: Optional[Path] = None, module_info: bool = True) -> Dict[str, PackageInfo]:
"""
Finds all the packages in the given path
"""
Expand Down
66 changes: 44 additions & 22 deletions platform_cli/groups/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

BASE_IMAGE = "ghcr.io/greenroom-robotics/ros_builder:iron-latest"


def get_auth_file() -> Dict[str, str]:
entries = (Path().home()/ ".gr" / "auth").read_text().strip().split("\n")
entries = (Path().home() / ".gr" / "auth").read_text().strip().split("\n")
matches = [re.match(r"export (?P<key>\w+)=(?P<value>.+)", e) for e in entries]
return {m.group("key"): m.group("value") for m in matches}

Expand All @@ -24,14 +25,19 @@ def get_system_platform_path() -> Path:
return Path.home() / "work/platform"


def ws_symlinks_to_platform_paths(workspace_path: Path, packages: Dict[Any, Any]) -> Tuple[Dict[str, Path], Dict[str, Path]]:
def ws_symlinks_to_platform_paths(
workspace_path: Path, packages: Dict[Any, Any]
) -> Tuple[Dict[str, Path], Dict[str, Path]]:
platform_paths = {}
other_paths = {}
for path in (workspace_path / "src").iterdir():
if path.is_symlink():
pkg_name = path.name
pkg_path = path.resolve()
if pkg_path.parts[:len(get_system_platform_path().parts)] != get_system_platform_path().parts:
if (
pkg_path.parts[: len(get_system_platform_path().parts)]
!= get_system_platform_path().parts
):
echo(f"Non platform based package: {pkg_path}", "yellow")
other_paths[pkg_name] = pkg_path
else:
Expand All @@ -50,8 +56,7 @@ def ws():
def base_image():

setup_proxy().callback()



@ws.command(name="setup-proxy")
@click.argument("container_name", type=str)
def setup_proxy(container_name: str): # type: ignore
Expand Down Expand Up @@ -101,7 +106,9 @@ def container(base_image: Optional[str], path: List[str]): # type: ignore
echo(f"Container '{container_name}' already exists - removing", "red")
container.remove(force=True)

echo(f"Creating container '{container_name}' for workspace {workspace_path}...", "green")
echo(
f"Creating container '{container_name}' for workspace {workspace_path}...", "green"
)

# workspace_volume = docker.volume.create(f"{container_name}_src", "local",
# options={
Expand All @@ -110,23 +117,29 @@ def container(base_image: Optional[str], path: List[str]): # type: ignore
# "device": "overlay"
# })

other_volumes = [
(p, container_other_path / pkg, "rw") for pkg, p in other_pkgs.items()
]

other_volumes = [(p, container_other_path / pkg, "rw") for pkg, p in other_pkgs.items()]

container = docker.run(base_image,
["tail", "-f", "/dev/null"],
container = docker.run(
base_image,
["tail", "-f", "/dev/null"],
name=container_name,
envs=get_auth_file(),
volumes=[
# (workspace_path / "src", "/home/ros/ws/src", "ro"),
(system_platform_path, container_platform_path, "rw"),
] + other_volumes,
# (workspace_path / "src", "/home/ros/ws/src", "ro"),
(system_platform_path, container_platform_path, "rw"),
]
+ other_volumes,
workdir=container_home_path,
detach=True, remove=False
detach=True,
remove=False,
)

echo(f"Container '{container_name}' created", "green")
container.execute(["mkdir", "-p", "ws/src"], tty=True) # , "chown", "ros:ros", "/home/ros/ws"
container.execute(
["mkdir", "-p", "ws/src"], tty=True
) # , "chown", "ros:ros", "/home/ros/ws"

for p in platform_paths.values():
p_rel = container_platform_path / p.relative_to(system_platform_path)
Expand All @@ -136,10 +149,12 @@ def container(base_image: Optional[str], path: List[str]): # type: ignore
p_rel = container_other_path / p.name
container.execute(["ln", "-s", str(p_rel), "ws/src"], tty=True)

container.execute(["pip", "install", str(container_platform_path / "tools/platform_cli")], tty=True)
container.execute(
["pip", "install", str(container_platform_path / "tools/platform_cli")], tty=True
)
container.execute(["platform", "pkg", "setup"], tty=True)
# container.execute(["platform", "pkg", "refresh-deps"], tty=True)

# how do we source the setup.bash files? needs to be ran as bash -l -c COMMAND
# container.execute(["colcon", "build"], tty=True)

Expand Down Expand Up @@ -208,11 +223,18 @@ def build_pkg(package: str, version: str, no_rosdep: bool): # type: ignore
if package not in packages:
echo(f"Package '{package}' not found", "red")
return

rel_path = packages[package].package_path.relative_to(workspace_path)

container.execute(["platform", "pkg", "clean"], tty=True, workdir=container_ws / rel_path)
container.execute(
["platform", "pkg", "clean"], tty=True, workdir=container_ws / rel_path
)
if not no_rosdep:
container.execute(["platform", "pkg", "install-deps"], tty=True, workdir=container_ws / rel_path)
container.execute(["platform", "pkg", "build", "--version", version], tty=True, workdir=container_ws / rel_path)

container.execute(
["platform", "pkg", "install-deps"], tty=True, workdir=container_ws / rel_path
)
container.execute(
["platform", "pkg", "build", "--version", version],
tty=True,
workdir=container_ws / rel_path,
)

0 comments on commit c62acaf

Please sign in to comment.