Skip to content

Commit

Permalink
Remove Python 2.7 implementations and dependencies
Browse files Browse the repository at this point in the history
This is a big preparation step before releasing v3.0.0.
  • Loading branch information
bittner committed Mar 1, 2024
1 parent c1b2c37 commit 3dd6409
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 892 deletions.
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.0rc1'
59 changes: 5 additions & 54 deletions pyclean/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 @@ -35,23 +35,9 @@ def parse_arguments():
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 +75,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 +104,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 +129,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')
24 changes: 0 additions & 24 deletions pyclean/compat.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
"""
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)


class ExtendAction(AppendAction):
Expand Down
8 changes: 1 addition & 7 deletions pyclean/modern.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
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.')
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

0 comments on commit 3dd6409

Please sign in to comment.