Skip to content

Commit

Permalink
fix: typing issues (#8)
Browse files Browse the repository at this point in the history
* fix: typing issues

* bump ci versions
  • Loading branch information
russkel authored Nov 18, 2024
1 parent c51d487 commit 5af5f83
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4

- name: Install npm dependencies
run: yarn install --frozen-lockfile
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- uses: pre-commit/action@v2.0.3
- uses: pre-commit/action@v3.0.1

- name: Install pyright
run: pip install pyright
Expand Down
10 changes: 10 additions & 0 deletions platform_cli/groups/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def _build_deb_in_docker(

docker_plaform = f"linux/{architecture.value}"

if not package_info.module_info:
raise Exception("Module info is required to build debs")

package_relative_to_platform_module = package_info.package_path.relative_to(
package_info.module_info.platform_module_path
)
Expand Down Expand Up @@ -409,6 +412,9 @@ def setup(package: str, package_dir: str): # type: ignore
release_mode = self._get_release_mode()
module_info = get_module_info()

if not module_info:
raise Exception("Could not find module info")

# If a Dockerfile does not exist in the module root, create it
docker_file_exists = (module_info.platform_module_path / "Dockerfile").exists()
echo(f"Dockerfile exists: {docker_file_exists}", "blue")
Expand Down Expand Up @@ -563,6 +569,10 @@ def deb_prepare(version: str, arch: List[Architecture], package: str, package_di
package_info = packages[package]
else:
package_info = get_package_info()

if not package_info.module_info:
raise Exception("Module info is required to build debs")

docker_image_name = self._get_docker_image_name(
package_info.module_info.platform_module_name
)
Expand Down
10 changes: 7 additions & 3 deletions platform_cli/groups/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from git import Repo
from platform_cli.groups.release import find_packages
from platform_cli.groups.base import PlatformCliGroup
from platform_cli.helpers import get_env, echo, call
from platform_cli.helpers import echo

from python_on_whales import docker
from python_on_whales import docker, Container

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")
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}
return {m.group("key"): m.group("value") for m in matches if m}


def get_system_platform_path() -> Path:
Expand Down Expand Up @@ -136,6 +136,10 @@ def container(base_image: Optional[str], path: List[str]): # type: ignore
remove=False,
)

if not isinstance(container, Container):
# Handle other possible return types
raise TypeError("Expected a Container, but got a different type")

echo(f"Container '{container_name}' created", "green")
container.execute(
["mkdir", "-p", "ws/src"], tty=True
Expand Down
26 changes: 13 additions & 13 deletions platform_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def on_modified(self, event: FileSystemEvent):
if event.is_directory:
return

file_type = Path(event.src_path).suffix
file_type = Path(str(event.src_path)).suffix

# Ignore files that don't match the file types
if file_type not in self.file_types:
Expand Down Expand Up @@ -93,17 +93,17 @@ def check_directory_ownership(path: Path) -> bool:
return stat.st_uid == os.getuid() and stat.st_gid == os.getgid()


def get_env(env_type: Union[Type[TypedDict], Type[TypedDict]], abort: bool = True) -> TypedDict:
def get_env(env_type: RosEnv, abort: bool = True) -> RosEnv:
if abort:
for env in env_type.__required_keys__: # type: ignore
if env not in os.environ:
raise click.ClickException(f"{env} environment variable must be set.")

return cast(env_type, {k: os.environ[k] for k in env_type.__required_keys__})
return cast(env_type, {k: os.environ[k] for k in env_type.__required_keys__}) # type: ignore


def get_ros_env(abort: bool = True) -> RosEnv:
return get_env(RosEnv, abort)
return get_env(RosEnv, abort) # type: ignore


def is_ci_environment() -> bool:
Expand Down Expand Up @@ -205,7 +205,7 @@ def start_watcher(

for folder in folders:
# Watch all folders in the current directory
observer.schedule(handler, cwd / folder, recursive=True)
observer.schedule(handler, str(cwd / folder), recursive=True)

observer.start()

Expand Down Expand Up @@ -262,24 +262,24 @@ def call(
try:
with subprocess.Popen(
command, shell=True, executable="/bin/bash", cwd=cwd, env=env_extended
) as process:
) as proc:
# this is the internal time to wait for the process to exit after SIGINT, and then SIGTERM is sent
process._sigint_wait_secs = 10.0
proc._sigint_wait_secs = 10.0 # type: ignore
try:
stdout, stderr = process.communicate(input, timeout=None)
stdout, stderr = proc.communicate()
except Exception as e: # Including KeyboardInterrupt, communicate handled that.
# looking at the python stdlib code, the SIGINT is already sent in the communicate/wait method
# so if we reach this point the process hasn't exited yet, so we need to send SIGTERM
print("Sending SIGTERM to process")
process.send_signal(signal.SIGTERM)
process.wait()
proc.send_signal(signal.SIGTERM)
proc.wait()
raise e
retcode = process.poll()
retcode = proc.poll() or 0
if abort and retcode:
raise subprocess.CalledProcessError(
retcode, process.args, output=stdout, stderr=stderr
retcode, proc.args, output=stdout, stderr=stderr
)
return subprocess.CompletedProcess(process.args, retcode, stdout, stderr)
return subprocess.CompletedProcess(proc.args, retcode, stdout, stderr)

except subprocess.CalledProcessError as e:
if retry > 0:
Expand Down

0 comments on commit 5af5f83

Please sign in to comment.