-
Notifications
You must be signed in to change notification settings - Fork 22
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
SourceAnalysis.from_file: Allow passing open file handle #100
Comments
Sounds like a good idea. Can you provide a small, self-contained code example how you would read a (hard coded) example file from e.g. the pygount repository using |
Sure, here you go. To analyze the file from tempfile import TemporaryDirectory
import git
from pygount.analysis import SourceAnalysis
with TemporaryDirectory() as d:
repo = git.Repo.clone_from("https://github.com/roskakori/pygount", d)
file = repo.head.commit.parents[0].tree / "pygount" / "analysis.py"
# Now, file.path is the relative path and name of the file, and
# file.data_stream is an open file-like object to read() from
SourceAnalysis.from_file(file.path, fh=file.data_stream) |
Looking at the milestone in this issue: The new version should be 1.6.0, as this introduces a new feature. (cf. https://semver.org/) |
True, changed it. |
@Natureshadow Thanks for the PR, finally got a look at it. For the most part it looks fine, left some questions as review comments. |
#100 Allow analyzing code from an open file
In addition to only a path, it would be helpful if
SourceAnalysis.from_file
could be passed an open file handle.That would help for analyzing code from files not available in the local filesystem directly, like from the object database of a Git repository. Specifically, I am writing a statistical analytics software for full Git repositories, and am reading data directly from Git objects instead of a working tree. Gitpython gives me a filename and a file-like object to read from.
The text was updated successfully, but these errors were encountered: