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

Conversation

msftcangoblowm
Copy link

rebased local with bskinn/sphobjinv
sync'ed msftcangoblowm/textconv with bskinn/sphobjinv
git push
forced to create new PR

- chore: soi-textconv changes 1/33
- docs: adjustments to pass linkcheck
- docs(README.md): doctest ELLIPSIS wildcard avoid hardcode inventory count
- 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. Examples for bash and python
- docs: added sphobjinv-textconv API docs
- fix: py38 with statements multiple --> nested
- fix: py38 standard types typing isms e.g. List
- fix: use Windows friendly line seperators
- test: print diagnostic info on Windows bin and site folders
- 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
- 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
- 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
- refactor .git/config append algo
- refactor: print git diff err message
- fix: specify encoding and linesep
  - test: fix use git config to set textconv executable
  - test: add to WorkDir git config list/get/set support
- test: fix inventory path must surround by single quotes
- test: attempt to diagnose WindowsPath getting garbled
- test: file not found create a .gitattributes
- chore: soi-textconv changes 25/33
- test: restore fixture ensure_doc_scratch
- chore: fix format and lint
- docs: fix README doctest
- test: remove inventory objects_attrs_plus_one_entry
- test(conftest): remove res_cmp_plus_one_line
- test(conftest): consolidate run_cmdline_textconv and run_cmdline_no_checks
- chore: soi-textconv changes 30/33
- test(conftest.py): remove run_cmdline_textconv by consolidate into run_cmdline_test
- test(enum.py): add module for enum.Enum declarations
- chore(tox.ini): application-import-names include folder tests
- tests(.coveragerc): omit conftest.py
- tests(conftest): remove fixture is_linux
- tests: rename dotted path tests.enum to tests.enums
- docs(CONTRIBUTING.md): instructions to optionally configure pyenv and tox
- chore(tox.ini): remove tox usage comment
@bskinn
Copy link
Owner

bskinn commented Feb 14, 2025

Ah, I had to approve the workflows since it was a new PR. They should run automatically from here on out.

@bskinn
Copy link
Owner

bskinn commented Feb 14, 2025

And, ok, I've had it with Codecov. I thought I had it configured correctly per their docs, but apparently not.

Please remove this last step from all_core_tests.yml, and codecov from requirements-ci.txt.

@bskinn
Copy link
Owner

bskinn commented Feb 14, 2025

As far as next work steps on the PR, that was in this comment from the prior PR:


Code review wise -- I think it'll be best to work on the code first, and then follow with the docs once the code is settled.


First, high-level, I'm not sure what the value is for having so much re-implemented in the new textconv code. I don't really want to have two spellings for a bunch of stuff that's already in the original sphobjinv command. I was picturing sphobjinv-textconv to be a very narrow, single-purpose utility:

  • Only reading an .inv from disk (so, no --url support)
  • No --expand or --contract options
  • No 'adapt to survive' logic, really - you provide it a path to a file, it converts it to plaintext on stdout with no other modifications, and that's it.

It also seems like there's a lot of unnecessary/irrelevant logic in .core_textconv.main().

In sum -- I think all of the new functional code should be much slimmer. Is that workable, to make a trim-down refactoring pass on everything?


Second, related -- I'm having a hard time understanding the purpose/function of print_stderr_2 and _wrap_inv_stdin. Are they leftovers from the attempt to include live git textconv testing in the test suite? If they're not specifically needed for any remaining tests to function correctly, they should definitely be removed.

(If they are needed for some remaining tests to function correctly, please make an attempt to revise the tests so that they can successfully use the original print_stderr().)


Thanks!

@msftcangoblowm
Copy link
Author

msftcangoblowm commented Feb 18, 2025

Done with two lines of code in 61519e6

    is_quiet = params.get(PrsConst.QUIET, False)
    subparser_name = params.get(PrsConst.SUBPARSER_NAME, None)

    if not is_quiet or (subparser_name is None or subparser_name[:2] == "su"):
        print(thing, file=sys.stderr, end=end)

Changing function signature was not needed

CAN IGNORE EVERYTHING BELOW HERE

print_stderr is being passed all soi params, but only requires two. Should be refactored as optional kwargs with sane defaults.

Once this fix is deployed, print_stderr_2 and usage of unittest.mock.patch are no longer needed. And both soi and soi-textconv are more maintainable and faster.

How to defang print_stderr

Instead of passing in params dict (hated by static type checkers), accept only optional keyword args.

def print_stderr(thing, params, *, end="\n"):

becomes

in cli/ui.py

from __future__ import annotations

import os
import sys

def print_stderr(
    thing,
    *,
    subparser_name: str | None = None,
    is_quiet: bool | None = False,
    end: str | None = os.linesep,
):
    """doc str here"""
    # Harden against unexpected user input
    if subparser_name is not None and not isinstance(end, str):
        subparser_name = None

    #    bool not optional bool
    if is_quiet is None or not isinstance(end, bool):
        bool_is_quiet = False
    else:
        bool_is_quiet = is_quiet

    if end is not None and not isinstance(end, str):
        end = os.linesep

    if (
        not bool_is_quiet
        or (subparser_name is None or subparser_name[:2] == "su")
    ):
        print(thing, file=sys.stderr, end=end)

@msftcangoblowm
Copy link
Author

msftcangoblowm commented Feb 18, 2025

Here is a working example of how to post to codecov. Use the gh action, do not reinvent the wheel.

    - name: "Run coverage"
      run : |
        set -xe
        python -m coverage run --parallel -m pytest --showlocals --quiet tests
        python -m coverage combine
        python -m coverage xml --fail-under=95

    - name: "Upload to Codecov"
      uses: codecov/[email protected]
      with:
        name: unittest-py${{ matrix.python-version }}
        token: ${{ secrets.CODECOV_TOKEN }}
        slug: msftcangoblowm/wreck
        os: linux
        flags: unittests
        files: ./coverage.xml
        env_vars: OS,PYTHON
        fail_ci_if_error: true
        verbose: true

Whats known to work ftw!

  • the slug should be bskinn/sphobjinv

  • then setup the codecov badge if don't already have one

  • matrix.python-version is not set, so unavailable. Add py version to matrix or hard code it?

Would it be ok to use codecov/codecov-action? Ignoring coverage vs pytest-cov

commit

@msftcangoblowm
Copy link
Author

msftcangoblowm commented Feb 18, 2025

_wrap_inv_stdin

soi-textconv is only for use with git.

If git supplied it by redirect then _wrap_inv_stdin is the workaround.

soi-textconv is written to be UNIX standard utility. UNIX utils are expected to deal with pipes, redirects, or as cli options. I assume, git to expect textconv to be UNIX standards compliant utility. Then it's up to git on how to interact with the textconv. That's a git internal implementation decision.

- ci(all_core_tests): gh action to upload to codecov
@msftcangoblowm
Copy link
Author

added fix for all_core_tests.yml. codecov package removed from requirement-ci.txt

codecov should work

- refactor: remove print_stderr patching. Apply sane defaults
@bskinn
Copy link
Owner

bskinn commented Feb 25, 2025

added fix for all_core_tests.yml. codecov package removed from requirements-ci.txt.

Looks like there's a syntax error in the new YAML.

That said, please just remove the Codecov job step, instead of taking the time to fix it. Codecov is really for larger projects and large teams, where you want team-wide visibility and/or accountability over coverage. It's overkill for sphobjinv ... I added it a while back because I was curious about it, and curious if I could get it to work, and I never really got much value out of it.

@bskinn
Copy link
Owner

bskinn commented Feb 25, 2025

_wrap_inv_stdin

soi-textconv is only for use with git.

If git supplied it by redirect then _wrap_inv_stdin is the workaround.

soi-textconv is written to be UNIX standard utility. UNIX utils are expected to deal with pipes, redirects, or as cli options. I assume, git to expect textconv to be UNIX standards compliant utility. Then it's up to git on how to interact with the textconv. That's a git internal implementation decision.

Per the Git docs:

The program should take a single argument, the name of a file to convert, and produce the resulting text on stdout.

The input API contract for the textconv is specifically a string filename passed as a CLI argument. I suppose that may change someday, but I'd rather postpone uptaking that complexity to the project unless/until it's specifically needed. Please pare back to only this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants