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

Prolog.consult method updates #177

Merged
merged 6 commits into from
Oct 13, 2024
Merged

Prolog.consult method updates #177

merged 6 commits into from
Oct 13, 2024

Conversation

yuce
Copy link
Owner

@yuce yuce commented Oct 13, 2024

This PR contains several enhancements to the Prolog.consult method.

Tilde character in paths are expanded to the user home directory

Prolog.consult("~/my_files/hanoi.pl")
# consults file /home/me/my_files/hanoi.pl

Both strings and pathlib.Path objects are allowed as paths

from pathlib import Path
Prolog.consult(Path("myfile.pl"))
# equivalent to:
Prolog.consult("myfile.pl")

Added relative_to keyword argument

relative_to keyword argument makes it easier to construct the consult path.
This keyword is no-op, if the consult path is absolute.

If the given relative_to path is a file, then the consult path is updated to become a sibling of that path.
Assume you have the /home/me/project/facts.pl that you want to consult from the run.py file which exists in the same directory /home/me/project.
Using the built-in __file__ constant which contains the path of the current Python file , it becomes very easy to do that:

# in run.py
Prolog.consult("facts.pl", relative_to=__file__)

If the given relative_path is a directory, then the consult path is updated to become a child of that path.

project_dir = "~/projects"
Prolog.consult("facts1.pl", relative_to=project_dir)
Prolog.consult("facts2.pl", relative_to=project_dir)

Symbolic links are not yet supported yet.

@yuce yuce changed the title Added relative_to keyword argument to prolog.consult Prolog.consult method updates Oct 13, 2024
@yuce yuce added this to the v0.3.1 milestone Oct 13, 2024
@yuce yuce merged commit 7f92e76 into master Oct 13, 2024
6 checks passed
@yuce yuce deleted the consult-relative_to branch October 13, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant