Skip to content

Conversation

@mundanevision20
Copy link

While I mainly adapted the Python code to work with Python 3.12 I also enhanced the formatting and logging to ease future maintenance.

@mundanevision20 mundanevision20 force-pushed the mundanevision20-python3-migration branch from 86fa289 to 29a20e6 Compare September 21, 2024 10:44
@mundanevision20
Copy link
Author

I also merged #237 by @rugk, #248 by @apoorvlathey and #293 by @Strahinja into this PR as the original PRs are apparently no longer active.

Based on #232 by @wesinator I updated the references to use manpages of Ubuntu noble (24.04 LTS). Due to the high number of merge conflicts I decided to apply the changes without merging.

@idank
Copy link
Owner

idank commented Sep 21, 2024 via email

connorblack added a commit to connorblack/explainshell that referenced this pull request Sep 12, 2025
@JoaoHCopetti
Copy link

Why is this not merged in the master branch yet?
The project isn't currently working because the docker image python:2.7 is based on a older version of Debian and the repositories are archived.

I get this when I try to run docker compose up

 > [2/6] RUN apt-get update   && apt-get install man-db -y   && apt-get clean:                                                                                 
0.478 Ign:1 http://security.debian.org/debian-security buster/updates InRelease                                                                                
0.507 Err:2 http://security.debian.org/debian-security buster/updates Release                                                                                  
0.507   404  Not Found [IP: 151.101.250.132 80]                                                                                                                
0.522 Ign:3 http://deb.debian.org/debian buster InRelease                                                                                                      
0.550 Ign:4 http://deb.debian.org/debian buster-updates InRelease
0.749 Err:5 http://deb.debian.org/debian buster Release
0.749   404  Not Found [IP: 151.101.250.132 80]
0.778 Err:6 http://deb.debian.org/debian buster-updates Release
0.778   404  Not Found [IP: 151.101.250.132 80]
0.781 Reading package lists...
0.789 E: The repository 'http://security.debian.org/debian-security buster/updates Release' does not have a Release file.
0.789 E: The repository 'http://deb.debian.org/debian buster Release' does not have a Release file.
0.789 E: The repository 'http://deb.debian.org/debian buster-updates Release' does not have a Release file.

This branch works fine tho.

@idank
Copy link
Owner

idank commented Oct 1, 2025

After not touching the code for years, a PR this size (even though organized quite well) is extremely difficult to review. I want to do it though.

@rugk
Copy link
Contributor

rugk commented Oct 6, 2025

Awesome to hear back and take your time! One tip if I may tell you though: You can also review and merge the other PRs (like mine apparently) that were merged into here, first – and then merge them. This should decrease the effort as the diff decreases, theoretically.
That said, this assumes that the PRs merge cleanly and no conflicts are found.

tobiashochguertel added a commit to tobiashochguertel/explainshell that referenced this pull request Oct 26, 2025
- Fix iterator protocol: def next() → def __next__() in Peekable class
- Fix iterator calls: it.next() → next(it) throughout codebase
- Fix map() iterator: yield map() → yield list(map()) in group_continuous
- Fix dictionary methods: .iteritems() → .items() in doctests
- Fix function names in doctests to match actual definitions
- Migrate testing framework: nose → pytest (Python 3.12 compatible)
- Update requirements.txt with pytest 8.3.3 and pytest-cov 6.0.0
- Update Makefile to use pytest --doctest-modules

These fixes complete the Python 3.12 migration on top of PR idank#330.
All 12 tests now passing (100% success rate).

Test results:
- explainshell/algo/features.py: 1 passed
- explainshell/fixer.py: 1 passed
- explainshell/manpage.py: 3 passed
- explainshell/options.py: 3 passed
- explainshell/util.py: 3 passed
- explainshell/web/views.py: 1 passed

Total: 12 passed in 0.37s

Database integration verified with 72,349 documents.
Full functionality tested with ls, grep, and tar commands.
tobiashochguertel added a commit to tobiashochguertel/explainshell that referenced this pull request Oct 26, 2025
- Fix iterator protocol: def next() → def __next__() in Peekable class
- Fix iterator calls: it.next() → next(it) throughout codebase
- Fix map() iterator: yield map() → yield list(map()) in group_continuous
- Fix dictionary methods: .iteritems() → .items() in doctests
- Fix function names in doctests to match actual definitions
- Migrate testing framework: nose → pytest (Python 3.12 compatible)
- Update requirements.txt with pytest 8.3.3 and pytest-cov 6.0.0
- Update Makefile to use pytest --doctest-modules

These fixes complete the Python 3.12 migration on top of PR idank#330.
All 12 tests now passing (100% success rate).

Test results:
- explainshell/algo/features.py: 1 passed
- explainshell/fixer.py: 1 passed
- explainshell/manpage.py: 3 passed
- explainshell/options.py: 3 passed
- explainshell/util.py: 3 passed
- explainshell/web/views.py: 1 passed

Total: 12 passed in 0.37s

Database integration verified with 72,349 documents.
Full functionality tested with ls, grep, and tar commands.
tobiashochguertel added a commit to tobiashochguertel/explainshell that referenced this pull request Oct 26, 2025
- Fix iterator protocol: def next() → def __next__() in Peekable class
- Fix iterator calls: it.next() → next(it) throughout codebase
- Fix map() iterator: yield map() → yield list(map()) in group_continuous
- Fix dictionary methods: .iteritems() → .items() in doctests
- Fix function names in doctests to match actual definitions
- Migrate testing framework: nose → pytest (Python 3.12 compatible)
- Update requirements.txt with pytest 8.3.3 and pytest-cov 6.0.0
- Update Makefile to use pytest --doctest-modules

These fixes complete the Python 3.12 migration on top of PR idank#330.
All 12 tests now passing (100% success rate).

Test results:
- explainshell/algo/features.py: 1 passed
- explainshell/fixer.py: 1 passed
- explainshell/manpage.py: 3 passed
- explainshell/options.py: 3 passed
- explainshell/util.py: 3 passed
- explainshell/web/views.py: 1 passed

Total: 12 passed in 0.37s

Database integration verified with 72,349 documents.
Full functionality tested with ls, grep, and tar commands.
@tobiashochguertel
Copy link

tobiashochguertel commented Oct 26, 2025

Additional Python 2→3 Compatibility Fixes Needed

I tested PR #330 extensively and found it needs a few additional fixes to achieve 100% Python 3.12 compatibility. Here are the required changes:

Changes Needed (5 files, 20 insertions, 19 deletions)

  1. Iterator Protocol - explainshell/util.py

    • Change def next(self):def __next__(self): in Peekable class
    • Change it.next()next(it) in doctests
  2. Iterator Calls - explainshell/web/views.py

    • Change m = it.next()m = next(it) on line 218
    • Fix doctest function names to match actual definitions
  3. Map Iterator - explainshell/util.py

    • Change yield map(itemgetter(1), g)yield list(map(itemgetter(1), g))
    • Python 3's map() returns iterator, not list
  4. Dictionary Methods - explainshell/options.py

    • Change .iteritems().items() in all doctests
  5. Testing Framework - requirements.txt and Makefile

    • Replace nose==1.3.7 with pytest==8.3.3 and pytest-cov==6.0.0
    • Update Makefile: nosetestspytest --doctest-modules
    • Reason: nose is incompatible with Python 3.12 (requires removed imp module)

Test Results

With these fixes applied:

pytest --doctest-modules tests/ explainshell/
============================== 12 passed in 0.37s ==============================

Testing Done

✅ Full database integration (72,349 documents restored)
✅ Functional testing with ls -la, grep -r, tar -xzvf
✅ Web interface fully operational
✅ All security fixes maintained

The fixes are available in branch python3-fixes-clean at https://github.com/tobiashochguertel/explainshell if you'd like to review or cherry-pick them.

Happy to provide a patch file or PR to your fork if that would be helpful! 🙂

Related

Builds upon #330 by @mundanevision20

Summary

These additional Python 2→3 compatibility fixes are needed on top of PR #330 to achieve 100% test passing rate.

Changes

Only 5 files modified with 20 insertions and 19 deletions:

  • Fix iterator protocol: def next()def __next__() in Peekable class
  • Fix iterator calls: it.next()next(it) throughout codebase
  • Fix map() iterator: yield map()yield list(map()) in group_continuous
  • Fix dictionary methods: .iteritems().items() in doctests
  • Fix function names in doctests to match actual definitions
  • Migrate testing framework: nose → pytest (Python 3.12 compatible)

Why These Fixes Are Needed

  • nose is incompatible with Python 3.12 (requires removed imp module)
  • Iterator protocol requires __next__() in Python 3, not next()
  • map() returns iterators in Python 3, not lists
  • Doctests were failing due to Python 2 syntax

Testing

All 12 tests now passing (100% success rate):

pytest --doctest-modules tests/ explainshell/
============================== 12 passed in 0.37s ==============================

Tested with full database integration (72,349 documents) and verified with commands like ls -la, grep -r, tar -xzvf.

Files Changed

  • Makefile - Updated test command from nosetests to pytest
  • explainshell/options.py - Fixed .iteritems() → .items() in doctests
  • explainshell/util.py - Fixed iterator protocol and map() iterator
  • explainshell/web/views.py - Fixed iterator calls and function names
  • requirements.txt - Replaced nose with pytest"

tobiashochguertel added a commit to tobiashochguertel/explainshell that referenced this pull request Oct 26, 2025
tobiashochguertel added a commit to tobiashochguertel/explainshell that referenced this pull request Oct 26, 2025
- Fix iterator protocol: def next() → def __next__() in Peekable class
- Fix iterator calls: it.next() → next(it) throughout codebase
- Fix map() iterator: yield map() → yield list(map()) in group_continuous
- Fix dictionary methods: .iteritems() → .items() in doctests
- Fix function names in doctests to match actual definitions
- Migrate testing framework: nose → pytest (Python 3.12 compatible)
- Update requirements.txt with pytest 8.3.3 and pytest-cov 6.0.0
- Update Makefile to use pytest --doctest-modules

These fixes complete the Python 3.12 migration on top of PR idank#330.
All 12 tests now passing (100% success rate).

Test results:
- explainshell/algo/features.py: 1 passed
- explainshell/fixer.py: 1 passed
- explainshell/manpage.py: 3 passed
- explainshell/options.py: 3 passed
- explainshell/util.py: 3 passed
- explainshell/web/views.py: 1 passed

Total: 12 passed in 0.37s

Database integration verified with 72,349 documents.
Full functionality tested with ls, grep, and tar commands.
@tobiashochguertel
Copy link

Update: I've created a cleaner PR that combines PR #330 with the additional compatibility fixes. Please see the new PR which includes everything needed for 100% Python 3.12 compatibility with all tests passing.

The new PR shows the complete solution in one place, making it easier to review and merge. 🙂

@rugk
Copy link
Contributor

rugk commented Oct 28, 2025

You probably meant #345 (also IMHO it's best to disclose if you use AI for coding here, so people can be aware of that when reviewing it. The result may be fine, but just FYI.)

@wattry
Copy link

wattry commented Oct 31, 2025

Does this project even still work?

@tobiashochguertel
Copy link

You probably meant #345 (also IMHO it's best to disclose if you use AI for coding here, so people can be aware of that when reviewing it. The result may be fine, but just FYI.)

I agree. I'll work on showing that more clearly the next time. Furthermore, I will check the current PR #345 over the next day, of course, together with AI for coding to fix failed checks in the CI/CD workflows, and reply on the PR #345 with a commit that resolves the build issues.

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.

7 participants