Skip to content
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

os.path converted pathlib.Path #94

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ademhilmibozkurt
Copy link

pull request for issue #90. Every path coverted to pathlib. Please, test the code and warn if there is a mistake.

Copy link
Collaborator

@Teque5 Teque5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting there, but we are still passing around strings as paths and folders.
I think we have some vars like filename and extension but those are just properties of Path now.

sigmf/archive.py Outdated
@@ -65,9 +65,9 @@ def __init__(self, sigmffile, name=None, fileobj=None):
sigmf_archive = tarfile.TarFile(mode="w", fileobj=sigmf_fileobj, format=tarfile.PAX_FORMAT)
tmpdir = tempfile.mkdtemp()
sigmf_md_filename = archive_name + SIGMF_METADATA_EXT
sigmf_md_path = os.path.join(tmpdir, sigmf_md_filename)
sigmf_md_path = Path.joinpath(tmpdir, sigmf_md_filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So whenever we create or handle a path it should be a Path already. So in this example a few lines up it should be tmpdir = Path(tempfile.mkdtemp()), then on this line and the one below you can just do tempdir / sigmf_md_filename.

sigmf/archive.py Outdated
@@ -108,7 +108,7 @@ def _ensure_name_has_correct_extension(self):
has_extension = "." in name
has_correct_extension = name.endswith(SIGMF_ARCHIVE_EXT)
if has_extension and not has_correct_extension:
apparent_ext = os.path.splitext(name)[-1]
apparent_ext = Path(name).suffix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here name will already be a path.

sigmf/schema.py Outdated
schema_file
)

schema_path = Path.joinpath(utils.get_schema_path(Path(utils.__file__).parent), schema_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_schema_path should be different:

def get_schema_path(version: str=__version__) -> Path:
    """
    TODO: Allow getting different schemas for specific SigMF versions
    """
    return Path(__file__)

so this line would just be schema_path = utils.get_schema_path() / schema_file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, get_schema_path() take module_path: str as parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanna ask something. What version is this __version__.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do from . import __version__ which will import the current version string stored in __init__.py.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@@ -248,7 +248,7 @@ def _is_conforming_dataset(self):
# check for any non-zero `header_bytes` fields in captures segments
if capture.get(self.HEADER_BYTES_KEY, 0):
return False
if self.data_file is not None and not path.isfile(self.data_file):
if self.data_file is not None and not Path.is_file(self.data_file):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly self.data_file will already be a Path

@Teque5
Copy link
Collaborator

Teque5 commented Dec 23, 2024

Tests are also not passing yet. On your machine you should be able to do pytest in the root folder or maybe coverage run. You can re-run a single test verbosely with pytest -rA test_utils.py or similar.

@ademhilmibozkurt
Copy link
Author

ademhilmibozkurt commented Dec 24, 2024

I will work on it. But, there are some issue that original codes test not work either.

@@ -948,7 +948,8 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None):
compliant_filename = get_sigmf_filenames(meta_fn)["data_fn"]
noncompliant_filename = metadata["global"].get(SigMFFile.DATASET_KEY, None)

if path.isfile(compliant_filename):
if Path.is_file(compliant_filename):
# if path.isfile(compliant_filename):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is looking almost ready. You have a few commented lines leftover and I see lots of places where you just need some formatting like a/ b to a / b

@Teque5
Copy link
Collaborator

Teque5 commented Jan 2, 2025

Try to get all the tests passing too, you can look here in the build log or try on your own machine. If you are stuck let me know and I can try to resolve.

@Teque5
Copy link
Collaborator

Teque5 commented Jan 7, 2025

Tests still not passing due to changes needed in archive.py (probably other changes needed too).

I started working on it but didn't complete today. The implementation within that area is more complicated because there is .name which can be None and .fileobj with refers to the writable tar file that archive works within. There is also .path which refers to the path of the eventual fileobj.

Copy link
Collaborator

@Teque5 Teque5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After rewriting archive.py I think this is ready to merge with all tests passing.

I may add an additional test to check that we can accept any type of path for fromfile and frombytes (bytes | str | PathLike).

@Teque5 Teque5 added the enhancement New feature or request label Jan 10, 2025
@ademhilmibozkurt
Copy link
Author

I'm sorry I couldn't take care of it. Congrats, you did a good job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants