-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
git diff support #296
git diff support #296
Conversation
- feat: entrypoint sphobjinv-textconv ([bskinn#295]) - test: add sphobjinv-textconv unittests offline and online - test: add integration test. Demonstrate git diff objects.inv - test: add pytest module with class to interact with git - docs: add step by step guide to configure git. Both bash and python code examples - docs: added sphobjinv-textconv API docs
- test: print entire os.environ rather than a single key
- test: for Windows, attempt add SCRIPTS folder to sys.path - test: for Windows, walk SCRIPTS folder print files and folders
- test: wrong params for list.append instead use list.insert
I'm flying blind Not a Windows user nor have access to a Windows box or VM This is a plea for help! On Windows, how to get the absolute path of these executables: sphobjinv and sphobjinv-textconv These are incorrect
Affects
|
Packages site path: C:\Users\VssAdministrator\AppData\Roaming\Python\Python38\site-packages site packages: ['c:\hostedtoolcache\windows\python\3.8.10\x64', 'c:\hostedtoolcache\windows\python\3.8.10\x64\lib\site-packages'] user site packages: 'C:\Users\VssAdministrator\AppData\Roaming\Python\Python38\site-packages' path_scripts: C:\Users\VssAdministrator\AppData\Roaming\Python\Python38\SCRIPTS |
I would say, take a look at the other CLI tests and see if it's possible to adapt the approach I took with them to your new tests. It's possible the needs here are different enough that my existing technique is insufficient, but I'd at least give it a shot first. (That is, if you haven't already.) |
I'm not sure where the script is; looking at the output of this job step, though, it looks like it's in You could try the |
I'm also not sure why you need to invoke the |
Will follow your advice and try with a relative path rather than an absolute path. You are right, the venv bin|SCRIPTS folder should already be on the path |
- test: for subprocess calls use relative path not absolute path
- test: carefully escape regex metacharacters - test: print source .inv file and diff. On windows, issue with regex - test: remove fixture windows_paths
- test: .git/config textconv executable resolve path - test: shutil.which to resolve path to executable
- test: resolve both soi and soi-textconv executables path
- test: regression when to use resolved or unresolved executable path
- test: read inventory on disk - test: print diagnostic before assertions
- test: consistantly use sphobjinv.cli.load:import_infile so compare apple with apples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few high-level thoughts/questions.
@@ -8,6 +8,101 @@ and this project follows an extension of | |||
fourth number represents an administrative maintenance release with no code | |||
changes. | |||
|
|||
### [2.4.1.10] - 2024-08-28 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msftcangoblowm Unless it strongly benefits your development process, please don't bother with bumping versions and documenting microchanges in the CHANGELOG this way.
I'll be cutting the actual v2.4.0 release only after this PR is merged to main
, and anything you've added to the CHANGELOG I'll coalesce and probably squash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.
These are actually development prereleases, not administrative prereleases. So these entries are wrong and spammy. The final changelog entries are left to your discretion
Also refrained from making any tags
tests/test_cli_textconv_with_git.py
Outdated
|
||
# .gitattributes | ||
# Informs git: .inv are binary files and which cmd converts .inv --> .txt | ||
path_ga = path_cwd / ".gitattributes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're doing this programmatically, instead of just revising the actual .gitattributes
for the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow your advice and use the projects .gitattributes file via a fixture
tests/test_cli_textconv_with_git.py
Outdated
wd.add_and_commit(reason="sphobjinv-textconv", signed=False) | ||
|
||
# Act | ||
# make change to .txt inventory (path_dst_dec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're generating the objects.inv
to be diffed on the fly?
It seems like it would be a lot easier to prepare one ahead of time and commit it to /tests/resource
... that's what the dir is there for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a realistic workflow. A line is added to a .txt --> soi --> .inv
soi convert -q zlib dec cmp
with resource absolute paths did not work on Windows. So that issue would not have been found, if had not gone thru the entire workflow.
Will isolate that issue into a separate test and then follow your advice on using two pre-built resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind on this -- I was thinking about it incorrectly. git diff
acts on the same file over time, not on two different files.
Instead, I'd recommend creating a small, trivial objects_textconv.inv
for this, and then making a new version and committing a new version of that same objects_textconv.inv
. That will give the two different versions of the files to be git diff
-ed.
And then, the git diff
command in the test would be something like git diff <sha1>..<sha2> tests/resource/objects_textconv.inv
.
I might still not have this quite right, but it's at least closer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
soi convert -q zlib dec cmp
with resource absolute paths did not work on Windows. So that issue would not have been found, if had not gone thru the entire workflow.
This doesn't make sense to me, I can use absolute paths on Windows without problems in normal operation mode.
It could be something going funny with the Azure CI environment, but it's concerning that absolute paths aren't working correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next commit, followed your advice on fixtures and created
tests/resource/objects_attrs_plus_one_entry.inv
tests/resource/objects_attrs_plus_one_entry.txt
tests/resource/objects_attrs_plus_one_entry.inv
overwrites cwd/objects.inv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a separate PR. Confirm, on Windows and Azure CI, what's the deal with absolute resource paths and soi convert
In this PR, that code has been removed
@@ -0,0 +1,239 @@ | |||
"""Class for working with pytest and git. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work to make these artifacts available to the tests using fixtures, instead of via relative import?
return ret | ||
|
||
|
||
class WorkDir: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this class is indeed specific for working with git, its name should reflect that.
from typing import List | ||
|
||
|
||
def run( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is a simpler variation of the shell-running capability elsewhere in the test suite. What motivated you to implement your own here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/wd_wrapper.py
is a standalone component under setuptools-scm author's copyright. (my voice not the setuptools-scm author) It should be fully functional by itself, without dependencies outside of StdLib
The (subprocess wrapper module func) run, i provided, replaces the one offered by setuptools-scm
in the original tests/wd_wrapper.py
. Adding a setuptools-scm
dependency for just one function in one module maybe a bad idea.
Elsewhere in the test suite, subprocess.check_output
is used. It's obsoleted by subprocess.run
.
sphobjinx has no dedicated _run_cmd
module
In test_cli_textconv.py
, TestTextconvStdioFail.test_cli_textconv_zlib_inv_stdin
uses param subprocess.run.input to pipe in stdin and do a subprocess in one command! It's a little exotic, non-typical usage. So different from what's normally in a _run_cmd
module.
# Ideally, the only place sys.exit calls occur within a codebase is in | ||
# entrypoint file(s). In this case, sphobjinv.cli.core | ||
# | ||
# Each unique custom Exception has a corresponding unique exit code. | ||
# | ||
# Testing looks at exit codes only. | ||
# | ||
# Not the error messages, which could change or be localized | ||
# | ||
# In command line utilities, relaying possible errors is common practice | ||
# | ||
# From an UX POV, running echo $? and getting 1 on error is | ||
# useless and frustrating. | ||
# | ||
# Not relaying errors and giving exact feedback on how to rectify | ||
# the issue is bad UX. | ||
# | ||
# So if the numerous exit codes of 1 looks strange. It is; but this is | ||
# a separate issue best solved within a dedicated commit | ||
assert f"EXIT CODES{os.linesep}" in str_out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll definitely be taking a closer look at this, for the project as a whole. I appreciate you pointing it out.
Could you actually duplicate these thoughts into a new ticket on the project?
(I'm aware that the exception handling in the project is substandard and intend to do something about it eventually (see #118), but it hadn't occurred to me to tie an exception hierarchy directly to the CLI exit codes in this way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- test: add resources objects_attrs_plus_one_entry.{txt|inv} - test: compare existing resources. Rather modify then .txt --> .inv - test: add fixtures res_cmp_plus_one_line is_linux gitconfig gitattributes
- test(test_api_good_nonlocal): provide explicit reasons to skip test
- refactor .git/config append algo
- refactor: print git diff err message
- fix: specify encoding and linesep
I did some digging and testing -- a separate Combining this Stack Overflow answer with this section of the Git docs, if I add the following to my
And add this to my
It works:
So, while I really appreciate all of the effort you've gone to here, I believe you can already do what you want with the above recipe. Open to correction, though, if I'm missing something. |
- test: fix use git config to set textconv executable - test: add to WorkDir git config list/get/set support
Editing the file manually is easy, via code nontrivial.
Bash quote escaping is a nightmare, best avoided. UX wise, this is a nasty ugly non-obvious non-trivial solution requiring advanced bash skills and substantial hair loss (stressful) and code hidden in a config file. End of the day, the end user needs smooth UX. These details at this level of complexity would have to be hidden. |
- test: fix inventory path must surround by single quotes
- test: attempt to diagnose WindowsPath getting garbled
- test: file not found create a .gitattributes
- ci: azure-pipelines coverage report omit setup.py - ci: azure-pipelines need --testall to get 100% coverage - ci: README.md affected by version. Update version - test: WorkDir - test: conftest fixture ensure_doc_scratch
- ci: Azure only issue skip
I used my above-noted setup successfully without modification on both Windows (with Git for Windows) and Debian WSL, so it definitely works across those platforms. What is the goal of editing the files via code? Providing the setup machinery so a user can run a command and the git textconv is set up automatically for them? I'm confident (but still possibly wrong!) that the sphobjinv-textconv entry point, and thus also all the new testing around it, are not actually needed. I like this capability a lot, but I don't want to add an 'automatically set up inv textconv' functionality to sphobjinv. It seems like it would be a bottomless source of support requests and edge case fixes. It seems to me this is best handled by documenting and publicizing the method for setting it up. Different users will want it set up differently, and so the knowledge will be more valuable than automation here anyways. |
So it's an UX issue. One command ... done. Much nicer than having to explain the intricacies of a complex sewer system. |
Simplicity. Zero learning curve. Doing less work. Type one uncomplicated command ... done.
Internally, soi-textconv runs Besides small changes to the parser, all the code for the setup has already been written and is known to work. Just refactor the integration unittest. After a refactor, the complexity of the integration test should be greatly reduced The scope of soi-textconv is it configures git to understand inventory files. That scope shouldn't change besides the |
TL;DR - You've done a lot of work here, but I'm afraid it's too much... more than I'm willing to add to the project. There's still an avenue to a smaller contribution, though. I'm on board with:
But I don't want to uptake anything more than that:
So—if you're interested in paring down the PR to just the above (or, starting a new PR to only implement the above, which might be easier/faster), I think there's still a path to a merge here. Let me know if you want to move forward, and I'll leave more thorough comments/feedback on the PR. I apologize that you went to all this work before getting this feedback, I didn't have any sense before you started that you were envisioning something of this scale. Lesson learned, I should've started a conversation about scale and approach before you started working! All of this said, I'm still not convinced that the new entrypoint is actually required. Using user-scope In
In
For WSL (similar but nonidentical on Win11): $ sudo apt install -y pipx
$ pipx install sphobjinv As we've already discussed, the benefit of It's really not much more than a quick post on a blog or Medium or wherever. (I do understand that a magic command to insert those snips for users would make it even simpler for those users; but, that magic command would end up needing to accommodate a wide variety of operating systems and user setups, and I'm confident it would run into all sorts of hairy edge cases that would be a nightmare to debug and develop around. Far better IMO just to educate users on how to set it up, rather than trying to write something that will attempt to automatically set it up for a wide range of users.) Regardless, again, if you're still interested in putting together the smaller-scope contribution for adding |
If you feel strongly This is actually a good idea that did not occur to me. If the flag should have another name, just suggest a better flag name.
The
On board with simple docs just saying for
Can move that out of fixtures and into code modules.
Yes would be interested. Would like to change the current PR rather than making a new PR. Please confirm i can go ahead. |
When modifying We, the maintainers, need to have read and understood the When modifying The setup changes are local; affecting one repo. Down the road, someone may request a local/global switch. Global setup goes into There is a Python package specifically for platform xdg user and site folders. The platform specific xdg folders location will not an issue. I already have a wrapper module and unittest for this. So copy paste ... done |
What I'm really hesitant about is whether I want to have a On one hand, I actually just used On the other hand, these manipulations of git config and gitattributes really seem like something that should be encapsulated into their own library, and not rewritten in every library they're needed in. E.g., it seems like
Yeah... and I could see at least the following sorts of requests popping up, too:
Just a really large possible CLI/API surface that might be requested. Ultimately, this sort of git config/attributes manipulation is solidly outside I'm open to continued discussion, but for now I'm only willing to consider the |
You are right. This should be a separate package, named git-filter, for interacting with git config and gitattributes. It's not a sphobjinv specific issue. sphobjinv users could benefit from such a package.
And yaml files describing changes need by each package. Was thinking plugins, but that is overkill |
Thanks again for the work you did on this, @msftcangoblowm -- sorry it didn't end up being merged. FYI, I did a bit of searching for other projects that have attempted this sort of git config, and found one: https://github.com/d12frosted/git-config-manager. I'm not sure what language it was written in, but it might be a useful resource. |
Is the PR a fix or a feature?
This is a new feature release
Bump the version up to 2.4.0
Describe the changes in the PR
Closes #295
Does this PR close any issues?
Closes #295
Does the PR change/update the following, if relevant?