question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] add `self.*_path` properties that return `pathlib.Path`

See original GitHub issue

We have recipe_folder, source_folder, etc that return Optional[str].

It would be nice to work with filesystem paths using pathlib.Path.

As the *_folder can be None in certain stages, it is usually a programming error accessing them when they are None.

It would be nice to have the following accessors on the ConanFile:

    @property
    def package_path(self) -> Path:
        """
        :returns: The location of the final packaging location              
        """
        assert self.package_folder is not None, "`package_folder` is `None`"
        return Path(self.package_folder)

Then we can use it like so:

    def build(self) -> None:
        exe = self.package_path / "bin" / "hello-world"
        exe.parent.mkdir()
        with exe.open(encoding="utf8") as stream:
            stream.write("#! /bin/sh\necho 'Hello, world!'')
        exe.chmod(0o755)

Which is much nicer that the equivalent code with os.path.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SSE4commented, Jul 7, 2022

here we go: #11585

1reaction
memshardedcommented, May 19, 2022

The problem with this is that Conan 1.X still supports Python 2.7 (sigh, I know…), so this couldn’t be added. Then we need to keep the current xxx_folder as strings for the Conan 1.X -> Conan 2.0 migration.

We will probably start to use Pathlib gradually at Conan 2.X (once the migration cliff has been surpassed), and from there we might be able to consider this request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >
Python 3's pathlib Module: Taming the File System
It gathers the necessary functionality in one place and makes it available through methods and properties on an easy-to-use Path object.
Read more >
How to use the pathlib.Path.home function in pathlib - Snyk
To help you get started, we've selected a few pathlib examples, based on popular ways it is used in public projects. ; is...
Read more >
python 3.7 - Custom pathlib.Path() - Stack Overflow
It works if you subclass from a derived concrete class instead of Path. from pathlib import PosixPath import os class mypath(PosixPath): def ...
Read more >
pathlib — Filesystem Paths as Objects — PyMOTW 3
Path objects have methods and properties for extracting partial values from the name. For example, the parts property produces a sequence of path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found