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

Remove Python 2.7 implementations and dependencies #81

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- format
- package
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install build tools
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install build tools
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- pypy-3.9
- pypy-3.10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install build tools
Expand Down
33 changes: 10 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,31 @@ Installation

$ pip install pyclean

or

.. code:: console

$ python -m pip install pyclean

Usage
=====

.. code:: console

$ pyclean --help

If you want to explicitly operate the Debian-specific implementation:
or

.. code:: console

$ py2clean --help
$ py3clean --help
$ pypyclean --help
$ python -m pyclean --help

Clean up all bytecode in the current directory tree, and explain verbosely:

.. code:: console

$ pyclean -v .

Clean up all bytecode for a Debian package: (may require root permissions)

.. code:: console

$ pyclean -p python3-keyring --legacy

Clean up debris
---------------

Expand Down Expand Up @@ -162,8 +160,8 @@ reason, the ``--erase`` option has a few artificial constraints:
- The above entails that you're responsible for the deletion order, i.e.
removal of a directory will only work if you asked to delete all files
inside first.
- You're prompted interactively to confirm deletion, unless you add the
``--yes`` option, in addition.
- You're prompted interactively to confirm deletion, unless you specify
the ``--yes`` option, in addition.

.. code:: console

Expand Down Expand Up @@ -201,14 +199,3 @@ Development
If you want to help out please see our `contribution guide`_.

.. _contribution guide: https://github.com/bittner/pyclean/blob/main/CONTRIBUTING.md

Roadmap (for v3.0.0)
--------------------

#. Replace original Debian scripts (current ``--legacy``) by a single,
pure Python, Python 3-only code base that serves all target platforms.
#. Reduce the package dependencies to an absolute minimum for maximum
portability.
#. Add additional CLI options to delete debris from builds, testing and
packaging (build/, .cache/, dist/, .pytest_cache/, .tox/ and
free-form targets).
2 changes: 1 addition & 1 deletion pyclean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Pure Python cross-platform pyclean. Clean up your Python bytecode.
"""

__version__ = '2.7.6'
__version__ = '3.0.0'
1 change: 1 addition & 0 deletions pyclean/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Main entry point for running pyclean as a module.
"""

from .cli import main

if __name__ == '__main__':
Expand Down
62 changes: 7 additions & 55 deletions pyclean/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Command line interface implementation for pyclean.
"""

import argparse
import logging
import sys
Expand All @@ -12,7 +13,7 @@

def parse_arguments():
"""
Parse and handle CLI arguments
Parse and handle CLI arguments.
"""
debris_default_topics = ['cache', 'coverage', 'package', 'pytest', 'ruff']
debris_optional_topics = ['jupyter', 'mypy', 'tox']
Expand All @@ -31,27 +32,13 @@ def parse_arguments():
description='Remove byte-compiled files for a package or project.',
)

if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # pragma: no-cover-gt-py37
parser.register('action', 'extend', compat.ExtendAction)

parser.add_argument('--version', action='version', version=__version__)
parser.add_argument(
'-V',
metavar='VERSION',
dest='version',
help='specify Python version to clean',
)
parser.add_argument(
'-p',
'--package',
metavar='PACKAGE',
action='append',
default=[],
help='Debian package to byte-compile (may be specified multiple times)',
)
parser.add_argument(
'directory',
nargs='*',
nargs='+',
help='directory tree to traverse for byte-code',
)
parser.add_argument(
Expand Down Expand Up @@ -89,11 +76,6 @@ def parse_arguments():
help='delete files or folders matching a globbing pattern (may be specified'
' multiple times); this will be interactive unless --yes is used.',
)
parser.add_argument(
'--legacy',
action='store_true',
help='use legacy Debian implementation (autodetect)',
)
parser.add_argument(
'-n',
'--dry-run',
Expand Down Expand Up @@ -123,10 +105,6 @@ def parse_arguments():
if args.yes and not args.erase:
parser.error('Specifying --yes only makes sense with --erase.')

if not (args.package or args.directory):
msg = 'A directory (or files) or a list of packages must be specified.'
parser.error(msg)

if 'debris' in args:
if 'all' in args.debris:
args.debris = debris_default_topics + debris_optional_topics
Expand All @@ -152,39 +130,13 @@ def init_logging(args):
logging.basicConfig(level=log_level, format=log_format)


def main(override=None):
def main():
"""
Entry point for all scripts
Entry point for CLI application.
"""
args = parse_arguments()
if override or args.legacy:
impl = compat.get_implementation(override=override)
pyclean_main = impl.main
else:
pyclean_main = modern.pyclean

try:
pyclean_main(args)
modern.pyclean(args)
except Exception as err:
raise SystemExit(err)


def py2clean():
"""
Forces the use of the implementation for Python 2
"""
main('CPython2')


def py3clean():
"""
Forces the use of the implementation for Python 3
"""
main('CPython3')


def pypyclean():
"""
Forces the use of the implementation for PyPy (2+3)
"""
main('PyPy2')
27 changes: 2 additions & 25 deletions pyclean/compat.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
"""
Cross-Python version compatibility.
"""
import platform
import sys
from argparse import _AppendAction as AppendAction
from importlib import import_module


def get_implementation(override=None):
"""
Detect the active Python version and return a reference to the
module serving the version-specific pyclean implementation.
"""
implementation = dict(
CPython2='pyclean.py2clean',
CPython3='pyclean.py3clean',
PyPy2='pyclean.pypyclean',
PyPy3='pyclean.pypyclean',
)

detected_version = '%s%s' % (
platform.python_implementation(),
sys.version_info.major,
)

module_name = implementation[override if override else detected_version]
return import_module(module_name)
from argparse import _AppendAction as AppendAction


class ExtendAction(AppendAction):
class ExtendAction(AppendAction): # pragma: no-cover-gt-py37
"""
Argparse "extend" action for Python < 3.8.
A simplified backport from the Python standard library.
Expand Down
9 changes: 2 additions & 7 deletions pyclean/modern.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"""
Modern, cross-platform, pure-Python pyclean implementation.
"""
import logging

try:
from pathlib import Path
except ImportError: # Python 2.7, PyPy2
from warnings import warn

warn('Python 3 required for modern implementation. Python 2 is obsolete.')
import logging
from pathlib import Path

BYTECODE_FILES = ['.pyc', '.pyo']
BYTECODE_DIRS = ['__pycache__']
Expand Down
86 changes: 0 additions & 86 deletions pyclean/py2clean.py

This file was deleted.

Loading