Skip to content

Commit 5af5f83

Browse files
authored
fix: typing issues (#8)
* fix: typing issues * bump ci versions
1 parent c51d487 commit 5af5f83

5 files changed

Lines changed: 36 additions & 22 deletions

File tree

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
name: Release
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

1313
- name: Setup Node.js
14-
uses: actions/setup-node@v2
14+
uses: actions/setup-node@v4
1515

1616
- name: Install npm dependencies
1717
run: yarn install --frozen-lockfile

.github/workflows/test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
name: Test
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616

1717
- name: Setup Python
18-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v5
1919
with:
20-
python-version: "3.10"
20+
python-version: "3.12"
2121

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

2424
- name: Install pyright
2525
run: pip install pyright

platform_cli/groups/release.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ def _build_deb_in_docker(
332332

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

335+
if not package_info.module_info:
336+
raise Exception("Module info is required to build debs")
337+
335338
package_relative_to_platform_module = package_info.package_path.relative_to(
336339
package_info.module_info.platform_module_path
337340
)
@@ -409,6 +412,9 @@ def setup(package: str, package_dir: str): # type: ignore
409412
release_mode = self._get_release_mode()
410413
module_info = get_module_info()
411414

415+
if not module_info:
416+
raise Exception("Could not find module info")
417+
412418
# If a Dockerfile does not exist in the module root, create it
413419
docker_file_exists = (module_info.platform_module_path / "Dockerfile").exists()
414420
echo(f"Dockerfile exists: {docker_file_exists}", "blue")
@@ -563,6 +569,10 @@ def deb_prepare(version: str, arch: List[Architecture], package: str, package_di
563569
package_info = packages[package]
564570
else:
565571
package_info = get_package_info()
572+
573+
if not package_info.module_info:
574+
raise Exception("Module info is required to build debs")
575+
566576
docker_image_name = self._get_docker_image_name(
567577
package_info.module_info.platform_module_name
568578
)

platform_cli/groups/ws.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
from git import Repo
99
from platform_cli.groups.release import find_packages
1010
from platform_cli.groups.base import PlatformCliGroup
11-
from platform_cli.helpers import get_env, echo, call
11+
from platform_cli.helpers import echo
1212

13-
from python_on_whales import docker
13+
from python_on_whales import docker, Container
1414

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

1717

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

2323

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

139+
if not isinstance(container, Container):
140+
# Handle other possible return types
141+
raise TypeError("Expected a Container, but got a different type")
142+
139143
echo(f"Container '{container_name}' created", "green")
140144
container.execute(
141145
["mkdir", "-p", "ws/src"], tty=True

platform_cli/helpers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def on_modified(self, event: FileSystemEvent):
5454
if event.is_directory:
5555
return
5656

57-
file_type = Path(event.src_path).suffix
57+
file_type = Path(str(event.src_path)).suffix
5858

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

9595

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

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

104104

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

108108

109109
def is_ci_environment() -> bool:
@@ -205,7 +205,7 @@ def start_watcher(
205205

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

210210
observer.start()
211211

@@ -262,24 +262,24 @@ def call(
262262
try:
263263
with subprocess.Popen(
264264
command, shell=True, executable="/bin/bash", cwd=cwd, env=env_extended
265-
) as process:
265+
) as proc:
266266
# this is the internal time to wait for the process to exit after SIGINT, and then SIGTERM is sent
267-
process._sigint_wait_secs = 10.0
267+
proc._sigint_wait_secs = 10.0 # type: ignore
268268
try:
269-
stdout, stderr = process.communicate(input, timeout=None)
269+
stdout, stderr = proc.communicate()
270270
except Exception as e: # Including KeyboardInterrupt, communicate handled that.
271271
# looking at the python stdlib code, the SIGINT is already sent in the communicate/wait method
272272
# so if we reach this point the process hasn't exited yet, so we need to send SIGTERM
273273
print("Sending SIGTERM to process")
274-
process.send_signal(signal.SIGTERM)
275-
process.wait()
274+
proc.send_signal(signal.SIGTERM)
275+
proc.wait()
276276
raise e
277-
retcode = process.poll()
277+
retcode = proc.poll() or 0
278278
if abort and retcode:
279279
raise subprocess.CalledProcessError(
280-
retcode, process.args, output=stdout, stderr=stderr
280+
retcode, proc.args, output=stdout, stderr=stderr
281281
)
282-
return subprocess.CompletedProcess(process.args, retcode, stdout, stderr)
282+
return subprocess.CompletedProcess(proc.args, retcode, stdout, stderr)
283283

284284
except subprocess.CalledProcessError as e:
285285
if retry > 0:

0 commit comments

Comments
 (0)