-
-
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
sphobjinv-textconv #307
Open
msftcangoblowm
wants to merge
32
commits into
bskinn:main
Choose a base branch
from
msftcangoblowm:textconv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
sphobjinv-textconv #307
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
55e0d00
sphobjinv-textconv
msftcangoblowm 27153cd
adjustments to pass linkcheck
msftcangoblowm 9d0c847
reduce fail under percentage
msftcangoblowm 04bd1d3
fix README.md doctest
msftcangoblowm a087e33
git diff support
msftcangoblowm e2cbd6a
fix py38
msftcangoblowm 2b8f4a9
kiss principle strikes back
msftcangoblowm dab90f2
when need add SCRIPTS folder to sys.path
msftcangoblowm 325697b
meant list.insert
msftcangoblowm 6f2a6b2
use relative not absolute path
msftcangoblowm 8bf128d
escape regex metacharacters
msftcangoblowm 2de2492
.git/config textconv executable resolve path
msftcangoblowm 3a1fa88
resolve both executables path
msftcangoblowm f898793
To be young resolved or unresolved
msftcangoblowm a7c760b
track down object count discrepency
msftcangoblowm 920b0fb
consistantly use import_infile
msftcangoblowm bc36bc9
compare existing resources
msftcangoblowm 9b6d7cf
.git/config algo refactor
msftcangoblowm a1450fa
git diff err message
msftcangoblowm 88b188f
specify encoding and linesep
msftcangoblowm 3578516
git config to the rescue
msftcangoblowm 617b132
inventory path need single quotes
msftcangoblowm 6011edd
what garble WindowsPath
msftcangoblowm 097aeb8
sandbox mystery no file .gitattributes
msftcangoblowm 17ae632
ci adjustments need
msftcangoblowm cd36666
restore fixture
msftcangoblowm c28a4a5
fix format and lint
msftcangoblowm 695aa55
remove py313 from pipeline
msftcangoblowm 9b313d4
Merge branch 'bskinn:main' into textconv
msftcangoblowm 71b914e
cleanup conftest
msftcangoblowm dc5ea78
no change semantic version
msftcangoblowm 0a30a83
one run_cmdline fixture
msftcangoblowm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
tests/resource/objects_mkdoc_zlib0.inv binary | ||
tests/resource/objects_attrs.txt binary | ||
*.inv binary diff=inv | ||
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
|
||
""" | ||
|
||
import os | ||
import os.path as osp | ||
import platform | ||
import re | ||
|
@@ -151,7 +152,7 @@ def scratch_path(tmp_path, res_path, misc_info, is_win, unix2dos): | |
# With the conversion of resources/objects_attrs.txt to Unix EOLs in order to | ||
# provide for a Unix-testable sdist, on Windows systems this resource needs | ||
# to be converted to DOS EOLs for consistency. | ||
if is_win: | ||
if is_win: # pragma: no cover | ||
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
win_path = tmp_path / f"{scr_base}{misc_info.Extensions.DEC.value}" | ||
win_path.write_bytes(unix2dos(win_path.read_bytes())) | ||
|
||
|
@@ -211,7 +212,7 @@ def func(path): | |
"""Perform the 'live' inventory load test.""" | ||
try: | ||
sphinx_ifile_load(path) | ||
except Exception as e: # noqa: PIE786 | ||
except Exception as e: # noqa: PIE786 # pragma: no cover | ||
# An exception here is a failing test, not a test error. | ||
pytest.fail(e) | ||
|
||
|
@@ -251,7 +252,7 @@ def func(arglist, *, expect=0): # , suffix=None): | |
except SystemExit as e: | ||
retcode = e.args[0] | ||
ok = True | ||
else: | ||
else: # pragma: no cover | ||
ok = False | ||
|
||
# Do all pytesty stuff outside monkeypatch context | ||
|
@@ -263,6 +264,45 @@ def func(arglist, *, expect=0): # , suffix=None): | |
return func | ||
|
||
|
||
@pytest.fixture() # Must be function scope since uses monkeypatch | ||
def run_cmdline_textconv(monkeypatch): | ||
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Return function to perform command line. So as to debug issues no tests. | ||
|
||
Consolidates: run_cmdline_textconv and run_cmdline_no_checks | ||
""" | ||
from sphobjinv.cli.core_textconv import main as main_textconv | ||
|
||
def func(arglist, *, prog="sphobjinv-textconv", is_check=False, expect=0): | ||
"""Perform the CLI exit-code test.""" | ||
|
||
# Assemble execution arguments | ||
runargs = [prog] | ||
runargs.extend(str(a) for a in arglist) | ||
|
||
# Mock sys.argv, run main, and restore sys.argv | ||
with monkeypatch.context() as m: | ||
m.setattr(sys, "argv", runargs) | ||
|
||
try: | ||
main_textconv() | ||
except SystemExit as e: | ||
retcode = e.args[0] | ||
is_system_exit = True | ||
else: # pragma: no cover | ||
is_system_exit = False | ||
|
||
if is_check: | ||
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Do all pytesty stuff outside monkeypatch context | ||
assert is_system_exit, "SystemExit not raised on termination." | ||
|
||
# Test that execution completed w/indicated exit code | ||
assert retcode == expect, runargs | ||
|
||
return retcode, is_system_exit | ||
|
||
return func | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def decomp_cmp_test(misc_info, is_win, unix2dos): | ||
"""Return function to confirm a decompressed file is identical to resource.""" | ||
|
@@ -273,7 +313,7 @@ def func(path): | |
res_bytes = Path(misc_info.res_decomp_path).read_bytes() | ||
tgt_bytes = Path(path).read_bytes() # .replace(b"\r\n", b"\n") | ||
|
||
if is_win: | ||
if is_win: # pragma: no cover | ||
# Have to explicitly convert these newlines, now that the | ||
# tests/resource/objects_attrs.txt file is marked 'binary' in | ||
# .gitattributes | ||
|
@@ -323,6 +363,12 @@ def is_win(): | |
return platform.system().lower() == "windows" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def is_linux(): | ||
"""Report boolean of whether the current system is Linux.""" | ||
return platform.system() in ("Linux",) | ||
|
||
|
||
Comment on lines
+338
to
+343
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see anywhere this fixture is currently used, do we need it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slated for removal |
||
@pytest.fixture(scope="session") | ||
def unix2dos(): | ||
"""Provide function for converting POSIX to Windows EOLs.""" | ||
|
@@ -333,3 +379,38 @@ def unix2dos(): | |
def jsonschema_validator(): | ||
"""Provide the standard JSON schema validator.""" | ||
return jsonschema.Draft4Validator | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def gitattributes(): | ||
bskinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Projects .gitattributes resource.""" | ||
|
||
def func(path_cwd): | ||
"""Copy over projects .gitattributes to test current sessions folder. | ||
|
||
Parameters | ||
---------- | ||
path_cwd | ||
|
||
|Path| -- test sessions current working directory | ||
|
||
""" | ||
path_dir = Path(__file__).parent | ||
path_f_src = path_dir.joinpath(".gitattributes") | ||
path_f_dst = path_cwd / path_f_src.name | ||
path_f_dst.touch() | ||
assert path_f_dst.is_file() | ||
if not path_f_src.exists(): # pragma: no cover | ||
# workflow "Run test suite in sandbox" fails to find .gitattributes | ||
sep = os.linesep | ||
contents = ( | ||
f"tests/resource/objects_mkdoc_zlib0.inv binary{sep}" | ||
f"tests/resource/objects_attrs.txt binary{sep}" | ||
f"*.inv binary diff=inv{sep}" | ||
) | ||
path_f_dst.write_text(contents) | ||
else: | ||
shutil.copy2(path_f_src, path_f_dst) | ||
return path_f_dst | ||
|
||
return func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
.. Description of configure git diff support for inventory files | ||
|
||
Integration -- git diff | ||
======================== | ||
|
||
.. program:: git diff | ||
|
||
|soi-textconv| converts .inv files to plain text sending the | ||
output to |stdout|. | ||
|
||
.. code-block:: shell | ||
|
||
sphobjinv-textconv objects.inv | ||
|
||
Which is equivalent to | ||
|
||
.. code-block:: shell | ||
|
||
sphobjinv convert plain objects.inv - | ||
|
||
Convenience aside, why the redundant CLI command, |soi-textconv|? | ||
|
||
To compare changes to a |objects.inv| file, :code:`git diff` won't | ||
produce a useful result without configuration. And git only accepts a | ||
CLI command with: | ||
|
||
- one input, the INFILE path | ||
|
||
- sends output to |stdout| | ||
|
||
Usage | ||
------ | ||
|
||
Initialize git | ||
""""""""""""""" | ||
|
||
.. code-block:: shell | ||
|
||
git init | ||
git config user.email [email protected] | ||
git config user.name "a test" | ||
|
||
Configure git | ||
"""""""""""""" | ||
|
||
``git diff`` is really useful, so it's time to configure git | ||
|
||
There is no CLI command to configure git for us. | ||
|
||
In ``.git/config`` (or $HOME/.config/git/config) append, | ||
|
||
.. code-block:: text | ||
|
||
[diff "inv"] | ||
textconv = [absolute path to venv bin folder]/sphobjinv-textconv | ||
|
||
Note has one tab, not whitespace(s) | ||
|
||
In ``.gitattributes`` append, | ||
|
||
.. code-block:: text | ||
|
||
*.inv binary diff=inv | ||
|
||
Example | ||
-------- | ||
|
||
Make one commit | ||
"""""""""""""""" | ||
|
||
Commit these files: | ||
|
||
- objects_attrs.inv | ||
|
||
- objects_attrs.txt | ||
|
||
- .gitattributes | ||
|
||
.. code-block:: shell | ||
|
||
git add . | ||
git commit --no-verify --no-gpg-sign -m "test textconv" | ||
|
||
Make a change to ``objects_attrs.inv`` | ||
""""""""""""""""""""""""""""""""""""""" | ||
|
||
By shell | ||
|
||
.. code-block:: shell | ||
|
||
URL="https://github.com/bskinn/sphobjinv/raw/main/tests/resource/objects_attrs.inv" | ||
wget "$URL" | ||
sphobjinv convert plain -qu "$URL" objects_attrs.txt | ||
export APPEND_THIS="attrs.validators.set_cheat_mode py:function 1 api.html#$ -" | ||
echo "$APPEND_THIS" >> objects_attrs.txt | ||
sphobjinv convert zlib -qu objects_attrs.txt objects_attrs.inv | ||
|
||
By python code | ||
|
||
.. versionadded:: 2.4.0 | ||
Append a line to .inv (compressed) inventory | ||
|
||
.. doctest:: append_a_line | ||
|
||
>>> from pathlib import Path | ||
>>> from sphobjinv import DataObjStr | ||
>>> from sphobjinv.cli.load import import_infile | ||
>>> from sphobjinv.cli.write import write_plaintext | ||
>>> | ||
>>> remote_url = ( | ||
... "https://github.com/bskinn/sphobjinv/" | ||
... "raw/main/tests/resource/objects_attrs.inv" | ||
... ) | ||
>>> cli_run(f'sphobjinv convert plain -qu {remote_url} objects_attrs.txt') | ||
<BLANKLINE> | ||
>>> path_dst_dec = Path('objects_attrs.txt') | ||
>>> path_dst_cmp = Path('objects_attrs.inv') | ||
>>> dst_dec_path = str(path_dst_dec) | ||
>>> path_dst_dec.is_file() | ||
True | ||
>>> inv_0 = import_infile(dst_dec_path) | ||
>>> obj_datum = DataObjStr( | ||
... name="attrs.validators.set_cheat_mode", | ||
... domain="py", | ||
... role="function", | ||
... priority="1", | ||
... uri="api.html#$", | ||
... dispname="-", | ||
... ) | ||
>>> inv_0.objects.append(obj_datum) | ||
>>> write_plaintext(inv_0, dst_dec_path) | ||
>>> cli_run('sphobjinv convert -q zlib objects_attrs.txt objects_attrs.inv') | ||
<BLANKLINE> | ||
>>> path_dst_cmp.is_file() | ||
True | ||
|
||
Show the diff | ||
"""""""""""""" | ||
|
||
To see the changes to objects_attrs.inv | ||
|
||
.. code-block:: shell | ||
|
||
git diff HEAD objects_attrs.inv 2>/dev/null | ||
|
||
Without |soi-textconv|, *These two binary files differ* | ||
|
||
With |soi-textconv| configured | ||
|
||
.. code-block:: text | ||
|
||
diff --git a/objects.inv b/objects.inv | ||
index 85189bd..65cc567 100644 | ||
--- a/objects.inv | ||
+++ b/objects.inv | ||
@@ -131,4 +131,5 @@ types std:doc -1 types.html Type Annotations | ||
validators std:label -1 init.html#$ Validators | ||
version-info std:label -1 api.html#$ - | ||
why std:doc -1 why.html Why not… | ||
+attrs.validators.set_cheat_mode py:function 1 api.html#$ - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. Module API page for cli/core_textconv.py | ||
|
||
sphobjinv.cli.core_textconv | ||
=========================== | ||
|
||
.. automodule:: sphobjinv.cli.core_textconv | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ sphobjinv.cli (non-API) | |
|
||
convert | ||
core | ||
core-textconv | ||
load | ||
parser | ||
paths | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Noticed this -- I'd be fine with adding
conftest.py
in here too, actually. It would both be a direct signal thatsetup.py
andconftest.py
are meant to not be covered, and I believe would result in them being excluded entirely from any coverage reports.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.
Oh nice! That's much better