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

Textconv previously 307 #312

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
368f83b
rebase hell start
msftcangoblowm Dec 12, 2024
7a5bec1
adjustments to pass linkcheck
msftcangoblowm Dec 12, 2024
2886fab
fix README.md doctest
msftcangoblowm Dec 12, 2024
065bb14
git diff support
msftcangoblowm Aug 26, 2024
afdb654
fix py38
msftcangoblowm Aug 27, 2024
a8c07c0
kiss principle strikes back
msftcangoblowm Aug 27, 2024
819cea2
when need add SCRIPTS folder to sys.path
msftcangoblowm Aug 27, 2024
96aa5fe
meant list.insert
msftcangoblowm Aug 27, 2024
2b9d370
use relative not absolute path
msftcangoblowm Aug 28, 2024
422f1fd
escape regex metacharacters
msftcangoblowm Aug 28, 2024
7cff4b3
.git/config textconv executable resolve path
msftcangoblowm Aug 28, 2024
f5d0c6c
resolve both executables path
msftcangoblowm Aug 28, 2024
2007187
To be young resolved or unresolved
msftcangoblowm Aug 28, 2024
35bc32f
track down object count discrepency
msftcangoblowm Aug 28, 2024
e6e09fc
consistantly use import_infile
msftcangoblowm Aug 28, 2024
02f5c18
compare existing resources
msftcangoblowm Aug 29, 2024
511c038
.git/config algo refactor
msftcangoblowm Aug 29, 2024
13f53fd
git diff err message
msftcangoblowm Aug 29, 2024
6b46ea0
specify encoding and linesep
msftcangoblowm Aug 29, 2024
90ea1e7
git config to the rescue
msftcangoblowm Aug 30, 2024
772ed88
inventory path need single quotes
msftcangoblowm Aug 30, 2024
42ac5c0
what garble WindowsPath
msftcangoblowm Aug 30, 2024
c7d7fba
sandbox mystery no file .gitattributes
msftcangoblowm Aug 30, 2024
dc90e4f
rebase hell 25/33
msftcangoblowm Feb 13, 2025
f2bcba1
restore fixture
msftcangoblowm Dec 31, 2024
a6b7c87
fix format and lint
msftcangoblowm Dec 31, 2024
102e71c
cleanup conftest
msftcangoblowm Jan 7, 2025
3f37db7
rebase hell 30/33
msftcangoblowm Feb 13, 2025
1f92f22
one run_cmdline fixture
msftcangoblowm Jan 14, 2025
aa8f11b
cleanup tests configuration
msftcangoblowm Jan 18, 2025
275c498
configure pyenv and tox instructions
msftcangoblowm Feb 13, 2025
f54a260
fix upload to codecov
msftcangoblowm Feb 19, 2025
61519e6
remove print_stderr patching
msftcangoblowm Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source =
omit =
# Don't worry about covering vendored libraries
src/sphobjinv/_vendored/*
setup.py
conftest.py

[report]
exclude_lines =
Expand Down
26 changes: 18 additions & 8 deletions .github/workflows/all_core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ jobs:
cancel-in-progress: true
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']

os:
- windows-latest
- ubuntu-latest
python-version:
- '3.12'
steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: "${{ matrix.python-version }}"
cache: 'pip'
cache-dependency-path: requirements-ci.txt

Expand All @@ -43,11 +46,18 @@ jobs:
- name: Run tests & report source coverage
run: |
pytest --cov --testall --nonloc
coverage xml -o coverage-service.xml

- name: Submit to Codecov if Linux, ready status, and main/stable
if: ${{ matrix.os == 'ubuntu-latest' && !github.event.pull_request.draft && (github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'stable') }}
run: |
coverage xml -o coverage-service.xml
curl -Os https://cli.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f coverage-service.xml
uses: codecov/[email protected]
with:
name: 'service'-${{ github.run_id }}
token: ${{ secrets.CODECOV_TOKEN }}
slug: bskinn/sphobjinv
os: linux
flags: unittests
files: ./coverage.xml
env_vars: OS,PYTHON
fail_ci_if_error: true
verbose: true
35 changes: 34 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ interact with them:
(sphobjinv) doc $ make html
```


## Working with git

There's no way I can fit a whole git tutorial in here, so this just highlights a
Expand Down Expand Up @@ -150,6 +149,40 @@ e.g.:
$ tox -rp2
```


### pyenv and tox

Contributors are **not expected** to do exhaustive testing on all
supported py interpreters, leave that to the CI. Not saying can't.

Assumes familiarity with pyenv and shims already installed for various
py interpreters.

Notable pyenv commands

```bash
pyenv version
pyenv versions --bare
```

Gets the active pyenv version and get all installed pyenv versions respectively.

To configure pyenv within the `.tox/` folder.

```bash
pyenv versions --bare > .tox/.python-version
```

Within the package base folder only one py interpreter is available.

Run tox for py39

```bash
cd .tox; PYTHONPATH=../ tox --root=.. -c ../tox.ini \
-e py39-sphx_latest-attrs_latest-jsch_latest --workdir=.; cd - &>/dev/null
```


## Code Autoformatting

The project is set up with a `tox` environment to blacken the codebase; run with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ inventory creation/modification:
>>> import sphobjinv as soi
>>> inv = soi.Inventory('doc/build/html/objects.inv')
>>> print(inv)
<Inventory (fname_zlib): sphobjinv v2.3, 220 objects>
<Inventory (fname_zlib): sphobjinv v2.3, ... objects>
>>> inv.project
'sphobjinv'
>>> inv.version
Expand Down
20 changes: 16 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from sphinx.util.inventory import InventoryFile as IFile

import sphobjinv as soi
from tests.enums import Entrypoints


def pytest_addoption(parser):
Expand Down Expand Up @@ -233,21 +234,32 @@ def sphinx_version():
@pytest.fixture() # Must be function scope since uses monkeypatch
def run_cmdline_test(monkeypatch):
"""Return function to perform command line exit code test."""
from sphobjinv.cli.core import main

def func(arglist, *, expect=0): # , suffix=None):
def func(arglist, *, expect=0, prog: Entrypoints = Entrypoints.SOI):
"""Perform the CLI exit-code test."""

# Assemble execution arguments
runargs = ["sphobjinv"]
assert isinstance(prog, Entrypoints)
runargs = []
if prog == Entrypoints.SOI:
from sphobjinv.cli.core import main

ep_fcn = main
runargs.append(Entrypoints.SOI.value)
else:
from sphobjinv.cli.core_textconv import main as main_textconv

ep_fcn = main_textconv
runargs.append(Entrypoints.SOI_TEXTCONV.value)

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()
ep_fcn()
except SystemExit as e:
retcode = e.args[0]
ok = True
Expand Down
160 changes: 160 additions & 0 deletions doc/source/cli/git_diff.rst
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#$ -
7 changes: 7 additions & 0 deletions doc/source/cli/implementation/core-textconv.rst
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:
1 change: 1 addition & 0 deletions doc/source/cli/implementation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sphobjinv.cli (non-API)

convert
core
core-textconv
load
parser
paths
Expand Down
Loading