Skip to content

Commit

Permalink
feat: workspace functionality aka russ's super cool secret branch (#7)
Browse files Browse the repository at this point in the history
* feat: add `ws` branch of commands

* feat: add proxy setup cmd, use an overlay fs for src ws

* feat: add symlink command for workspaces

* fix: find_packages would find xmls in install folders

* feat: resolve symlinks to platform and other pkgs, mount respectively

* fix: check apt directory exists
  • Loading branch information
russkel committed Oct 30, 2024
1 parent 2a1d993 commit b4cd70b
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 26 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
2 changes: 2 additions & 0 deletions platform_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List
from platform_cli.groups.base import PlatformCliGroup
from platform_cli.groups.ros import Ros
from platform_cli.groups.ws import Workspace
from platform_cli.groups.poetry import Poetry
from platform_cli.groups.packaging import Packaging
from platform_cli.groups.release import Release
Expand All @@ -15,6 +16,7 @@
Packaging(),
Release(),
Py(),
Workspace(),
]

help = f"""
Expand Down
11 changes: 6 additions & 5 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,10 +93,10 @@ 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:
if not GR_APT_REPO_PATH.exists():
raise click.ClickException("GR apt repo has not been cloned.")

if deb:
Expand All @@ -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 Expand Up @@ -209,7 +210,7 @@ def get_sources(): # type: ignore reportUnusedFunction
default="debs",
help="The output directory for the debs",
)
@click.option("--no-tests", type=bool, default=True)
@click.option("--no-tests", type=bool, is_flag=True, default=True)
def build(version: str, output: str, no_tests: bool): # type: ignore reportUnusedFunction
"""Builds the package using bloom"""

Expand Down Expand Up @@ -290,7 +291,7 @@ def apt_push(): # type: ignore reportUnusedFunction
@pkg.command(name="apt-update")
def apt_update(): # type: ignore reportUnusedFunction
"""Update the GR apt repo"""
if not GR_APT_REPO_PATH:
if not GR_APT_REPO_PATH.exists():
raise click.ClickException("GR apt repo has not been cloned.")
call("git pull --rebase", cwd=GR_APT_REPO_PATH)

Expand Down
45 changes: 31 additions & 14 deletions platform_cli/groups/release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
import shutil

from glob import glob
import os
from typing import List, Optional, Dict, Iterable, Any
from enum import Enum
Expand Down Expand Up @@ -41,35 +42,46 @@ class PackageInfo:
package_path: Path
package_name: str
package_version: str
module_info: ModuleInfo
module_info: Optional[ModuleInfo]


def check_parents_for_file(filename: str, path: Optional[Path] = None) -> Path:
"""Checks each parent directory for a file"""
current_path = path if path else Path.cwd()

while current_path.exists():
file_path = current_path / filename
if file_path.exists():
return file_path.parent
current_path = current_path.parent

if current_path == current_path.parent:
break
else:
current_path = current_path.parent

raise Exception(f"Could not find {filename} in any parent directory")


def get_module_info(path: Optional[Path] = None) -> ModuleInfo:
def get_module_info(path: Optional[Path] = None) -> Optional[ModuleInfo]:
"""
Returns the module info for the directory (or CWD).
"""
platform_module_path = check_parents_for_file(".git", path)
platform_module_name = platform_module_path.name

return ModuleInfo(
platform_module_path=platform_module_path,
platform_module_name=platform_module_name,
)
try:
platform_module_path = check_parents_for_file(".git", path)
platform_module_name = platform_module_path.name

return ModuleInfo(
platform_module_path=platform_module_path,
platform_module_name=platform_module_name,
)
except Exception:
return None


def get_package_info(package_path: Optional[Path] = None) -> 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 All @@ -86,7 +98,7 @@ def get_package_info(package_path: Optional[Path] = None) -> PackageInfo:
package_path=package_path,
package_name=get_package_name_from_package_xml(package_path / "package.xml"),
package_version=get_package_version_from_package_xml(package_path / "package.xml"),
module_info=get_module_info(package_path),
module_info=get_module_info(package_path) if obtain_module_info else None,
)


Expand Down Expand Up @@ -162,17 +174,22 @@ 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) -> 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
"""

path = path if path else Path.cwd()
package_xmls = path.glob("**/package.xml")

# Path.glob does not seem to traverse into symlink directories
package_xmls = [Path(p) for p in glob(f"{path}/**/package.xml", recursive=True)]

packages = {}
for package_xml in package_xmls:
package = get_package_info(package_xml.parent)
if package_xml.parent.parent.name == "share":
# this package is inside an install directory, so ignore it
continue
package = get_package_info(package_xml.parent, module_info)
packages[package.package_name] = package

return packages
Expand Down
Loading

0 comments on commit b4cd70b

Please sign in to comment.