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

Use pathlib instead of os.path module #641

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Secrus
Copy link
Member

@Secrus Secrus commented Sep 16, 2023

Migrated from os.path to pathlib usage.

@Secrus Secrus force-pushed the use-pathlib branch 2 times, most recently from 18d0424 to 86ccc11 Compare September 26, 2023 21:50
@sonarcloud
Copy link

sonarcloud bot commented Sep 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link

sonarcloud bot commented Nov 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -147,11 +146,11 @@ def test_temporary_directory_python_3_9_or_older(mocker: MockerFixture) -> None:
mocked_temp_dir = mocker.patch("tempfile.TemporaryDirectory")
mocked_mkdtemp = mocker.patch("tempfile.mkdtemp")

mocked_mkdtemp.return_value = "hello from test"
mocked_mkdtemp.return_value = Path("hello from test")
Copy link
Member

Choose a reason for hiding this comment

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

That does not make sense, since we are mocking tempfile.mkdtemp.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have any better idea? I am tempted to just noqa this and leave it as it was...

Copy link
Member

Choose a reason for hiding this comment

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

Does it result in a warning? I wonder how ruff would decide that this string should be Path?

@@ -135,7 +134,7 @@ def test_temporary_directory_python_3_10_or_newer(mocker: MockerFixture) -> None

mocker.patch.object(sys, "version_info", (3, 10))
with temporary_directory() as tmp:
assert tmp
assert str(tmp)
Copy link
Member

Choose a reason for hiding this comment

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

This assert has always been quite weak. Now it does not make any sense since the string representation of a Path will always be truthy as far as I know. We should probably do it similar to the test some lines below and set the return value of mocked_temp_dir. Then, we can check for the correct path.

Copy link

sonarcloud bot commented Jan 21, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

"""Like os.path.splitext, but take off .tar too"""
base, ext = posixpath.splitext(path)
base, ext = path.stem, path.suffix
Copy link
Member

Choose a reason for hiding this comment

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

That's not the same:

>>> posixpath.splitext('foo/bar.baz')
('foo/bar', '.baz')
>>> path = Path('foo/bar.baz')
>>> path.stem, path.suffix
('bar', '.baz')

However, it does not matter for our uses so it might still be ok (if we fix the docstring).

On the other side, we could change the signature to allow str | Path and keep the old implementation. We don't even need a noqa as it seems. I slightly tend to this variant. Then, we don't have to convert the str to Path in link.py.

@@ -133,19 +132,19 @@ def is_python_project(path: Path) -> bool:
return pyproject or setuptools_project


def is_archive_file(name: str) -> bool:
def is_archive_file(name: Path) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def is_archive_file(name: Path) -> bool:
def is_archive_file(name: str | Path) -> bool:

From an interface's point of view, I think it makes sense to allow plain file names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants