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

Ensure paths mentioned in Sphinx docs are valid #1183

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

lbianchi-lbl
Copy link
Contributor

@lbianchi-lbl lbianchi-lbl commented Dec 14, 2023

Resolves: #1180

Changes proposed in this PR:

  • Add small Sphinx extension adding :path: and :filename: roles to display paths relative to repository root with validation (a warning is emitted if the referred path is not found during the build)
  • Convert a subset of the (non-role) paths found in the docs to use the :path:/:filename: roles
  • Fix non-existing paths until build passes

This is how it looks when non-existing paths are used:

image

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the copyright and license terms described in the LICENSE.md file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@lbianchi-lbl lbianchi-lbl changed the title Ensure files Ensure paths mentioned in Sphinx docs are valid Dec 14, 2023
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6694f80) 38.52% compared to head (bda6df5) 38.52%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1183   +/-   ##
=======================================
  Coverage   38.52%   38.52%           
=======================================
  Files         163      163           
  Lines       36852    36852           
  Branches     5994     5994           
=======================================
  Hits        14199    14199           
  Misses      21544    21544           
  Partials     1109     1109           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lbianchi-lbl lbianchi-lbl self-assigned this Dec 14, 2023

class PathRoleBase:
def __init__(self, base_path=""):
self.base_path = Path(base_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

why the Path constructor here? all the usage already passes a Path into the PathRoleBase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly for robustness/defensiveness: the internals only work if self.base_path is a pathlib.Path, and pathlib.Path instances are immutable so creating a new Path is easier than having isinstance(..., Path) checks.

if not path.exists():
relpath = path.relative_to(self.base_path)
_logger.warning(
"path %r does not exist within %r", str(relpath), str(self.base_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency maybe use os.fspath() rather than str() for both of these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I think I was just being lazy 😅

return os.fspath(path.relative_to(self.base_path))


class Filename(PathRoleBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe override validate to add a is_file() check as well for this type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll add that.

kbuma
kbuma previously approved these changes Dec 14, 2023
Copy link
Contributor

@kbuma kbuma left a comment

Choose a reason for hiding this comment

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

excellent solution. added just a few nit-picks in _repopath.py


class Filename(PathRoleBase):
def display(self, path: Path, text="") -> str:
return path.name
Copy link
Contributor

Choose a reason for hiding this comment

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

consider returning something like path.name + ", and this file is located in " + os.fspath(path.parent.relative_to(self.base_path)) since that pattern occurs repeatedly in the usage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, maybe to keep in mind for a future iteration? I see the pattern you're referring to, but having the role handle more complicated formatting (since the prose would have to be formatted differently than the actual path) looked quite a bit trickier than the current implementation.

Copy link
Member

@ksbeattie ksbeattie left a comment

Choose a reason for hiding this comment

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

LGTM

@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Dec 14, 2023
@lbianchi-lbl lbianchi-lbl merged commit f2a4cb6 into CCSI-Toolset:master Dec 14, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FOQUS documentation has incorrect paths to files in examples package
3 participants