-
-
Notifications
You must be signed in to change notification settings - Fork 111
355 convert long num arrays #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1690f2a
first try on lockfile logic
songmeo 980601b
Merge branch 'dev' of github.com:OpenCyphal/pycyphal into 335-create-…
songmeo aa158ea
fix couple path problems
songmeo 3bd33cb
create lockfile class
songmeo 5be4ba5
remove compiled_dir from nox
songmeo c22ac68
address comments
songmeo f4c07c4
add tests
songmeo adacb45
fix tests
songmeo 3ddafbc
Merge branch '335-create-lockfile' of github.com:OpenCyphal/pycyphal …
songmeo 657d727
address comments
songmeo ed79fd3
Merge branch '335-create-lockfile' of github.com:OpenCyphal/pycyphal …
songmeo 3fcb454
add context manager
songmeo 3892925
Add a function for removing import hooks (#356)
songmeo e0423d9
fix couple path problems
songmeo 541e1b1
create lockfile class
songmeo 6ef87ae
remove compiled_dir from nox
songmeo 37fb27f
address comments
songmeo ee9f06a
add tests
songmeo 2540db3
fix tests
songmeo 106b4ba
address comments
songmeo 5d79b75
add context manager
songmeo 7df9e8c
choose value type based on the list length
songmeo b55b456
address comments
songmeo f331a60
remove the improve UX code
songmeo 171bb12
create separate lockfile for support
songmeo 50a414b
remove test related to old UX code
songmeo 64dd205
change to elif
songmeo 22a4dca
Trigger CI rebuild
songmeo 7d978d7
choose value type based on the list length
songmeo c587a23
change to elif
songmeo d4a7a45
Trigger CI rebuild
songmeo d3ef982
Merge branch '355-convert-long-num-arrays' of github.com:OpenCyphal/p…
songmeo b7a23e0
merge changes from dev
songmeo e83708b
first tests
songmeo ad67509
attempt to fix uavcan import error
songmeo b0109c9
Merge branch 'master' of github.com:OpenCyphal/pycyphal into 355-conv…
songmeo f0992a3
fix mypy
songmeo 53ce134
Merge branch 'dev' of github.com:OpenCyphal/pycyphal into 355-convert…
songmeo 52c43e9
remove redundant condition
songmeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
import pathlib | ||
import time | ||
from io import TextIOWrapper | ||
from pathlib import Path | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class Locker: | ||
|
||
def __init__(self, output_directory: pathlib.Path, root_namespace_name: str) -> None: | ||
self._output_directory = output_directory | ||
self._root_namespace_name = root_namespace_name | ||
self._lockfile: TextIOWrapper | None = None | ||
|
||
@property | ||
def _lockfile_path(self) -> Path: | ||
return self._output_directory / f"{self._root_namespace_name}.lock" | ||
|
||
def create(self) -> bool: | ||
""" | ||
True means compilation needs to proceed. | ||
False means another process already compiled the namespace so we just waited for the lockfile to disappear before returning. | ||
""" | ||
# TODO Read about context manager | ||
try: | ||
pathlib.Path(self._output_directory).mkdir(parents=True, exist_ok=True) | ||
self._lockfile = open(self._lockfile_path, "x") | ||
_logger.debug("Created lockfile %s", self._lockfile_path) | ||
return True | ||
except FileExistsError: | ||
pass | ||
while pathlib.Path(self._lockfile_path).exists(): | ||
_logger.debug("Waiting for lockfile %s", self._lockfile_path) | ||
time.sleep(1) | ||
|
||
_logger.debug("Done waiting %s", self._lockfile_path) | ||
|
||
return False | ||
|
||
def remove(self) -> None: | ||
""" | ||
Invoking remove before creating lockfile is not allowed. | ||
""" | ||
assert self._lockfile is not None | ||
self._lockfile.close() | ||
pathlib.Path(self._lockfile_path).unlink() | ||
_logger.debug("Removed lockfile %s", self._lockfile_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,18 @@ | |
# This software is distributed under the terms of the MIT License. | ||
# Author: Pavel Kirienko <[email protected]> | ||
|
||
import random | ||
import sys | ||
import threading | ||
import time | ||
import typing | ||
import logging | ||
import pathlib | ||
import tempfile | ||
import pytest | ||
import pycyphal.dsdl | ||
from pycyphal.dsdl import remove_import_hooks, add_import_hook | ||
|
||
from pycyphal.dsdl._lockfile import Locker | ||
from .conftest import DEMO_DIR | ||
|
||
|
||
|
@@ -64,3 +67,28 @@ def _unittest_remove_import_hooks() -> None: | |
def _unittest_issue_133() -> None: | ||
with pytest.raises(ValueError, match=".*output directory.*"): | ||
pycyphal.dsdl.compile(pathlib.Path.cwd() / "irrelevant") | ||
|
||
|
||
def _unittest_lockfile_cant_be_recreated() -> None: | ||
output_directory = pathlib.Path(tempfile.gettempdir()) | ||
root_namespace_name = str(random.getrandbits(64)) | ||
|
||
lockfile1 = Locker(output_directory, root_namespace_name) | ||
lockfile2 = Locker(output_directory, root_namespace_name) | ||
|
||
assert lockfile1.create() is True | ||
|
||
def remove_lockfile1() -> None: | ||
time.sleep(5) | ||
lockfile1.remove() | ||
|
||
threading.Thread(target=remove_lockfile1).start() | ||
assert lockfile2.create() is False | ||
|
||
|
||
def _unittest_lockfile_is_removed() -> None: | ||
output_directory = pathlib.Path(tempfile.gettempdir()) | ||
|
||
pycyphal.dsdl.compile(DEMO_DIR / "public_regulated_data_types" / "uavcan", output_directory=output_directory.name) | ||
|
||
assert pathlib.Path.exists(output_directory / "uavcan.lock") is False |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need either this, or raise an exception in the previous if