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.

Accept pathlib model path

See original GitHub issue

Description of Problem: I am fond of pathlib and of this particular snippet to load the newest model I have:

import pathlib

from rasa.core.agent import Agent

models_folder = pathlib.Path("models")
latest_model = max(models_folder.glob("*.tar.gz"), key=lambda p: p.stat().st_ctime)

agent = Agent.load(str(latest_model))

The only friction here is str(latest_model). Adding support for pathlib paths would be quite convenient.

Overview of the Solution:

Since os.path functions are compatible with pathlib, the only change we would need to do is right there https://github.com/RasaHQ/rasa/blob/master/rasa/core/agent.py#L355:

model_path = get_model(str(model_path))

I could submit a PR if the feedback is positive. The interrogation left would be about the type hints: model_path is a Text right now, would a Union[Text, Path] type be acceptable?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Batalexcommented, Nov 24, 2020

Thanks @silvasara and @Henrike100, it works like a charm 👍 I am closing the issue.

1reaction
JustinaPetrcommented, Sep 24, 2020

That’s great @silvasara. Please let us know if you need any help with this.

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
In this tutorial, you will see how to work with file paths—names of directories and files—in Python. You will learn new ways to...
Read more >
Python Path – How to Use the Pathlib Module with Examples
In this example, we import the Pathlib module. Then, we create a new variable called p to store the path. Here, we use...
Read more >
Accept pathlib model path · Issue #4341 · RasaHQ/rasa - GitHub
Description of Problem: I am fond of pathlib and of this particular snippet to load the newest model I have: import pathlib from ......
Read more >
Pathlib module in Python - GeeksforGeeks
This method is used to check whether the path is absolute or not. This method returns True if the path is absolute otherwise...
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