Skip to content

Commit

Permalink
feat: drop support for Python 2
Browse files Browse the repository at this point in the history
- Removed Python 2 references and infrastructure
- Automatically applied [ruff fixes for Python 2 deprecations](https://docs.astral.sh/ruff/rules/#pyupgrade-up):
  - UP004 - useless-object-inheritance - Class {name} inherits from object
  - UP008 - super-call-with-parameters - Use super() instead of super(__class__, self)
  - UP009 - utf8-encoding-declaration - UTF-8 encoding declaration is unnecessary
  - UP020 - open-alias - Use builtin open
  - UP025 - unicode-kind-prefix - Remove unicode literals from strings
  - UP030 - format-literals - Use implicit references for positional format fields
- Manually resolved `UP036` deprecations (outdated-version-block)
- Dropped deprecated `MAINTAINER` property from `Dockerfile`
  • Loading branch information
kieran-ryan committed Dec 23, 2024
1 parent 3fb4eb8 commit 6673255
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 337 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ language: python
os: linux
dist: xenial
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "pypy3.5"
install:
- pip install .
- pip install -r test_requirements.txt
- pip install --requirement test_requirements.txt
script:
- make tests
- make cov
Expand Down
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
FROM alpine:edge
MAINTAINER rubik
LABEL maintainer="rubik"

WORKDIR /usr/src/app
COPY . /usr/src/app

RUN apk --update add \
python2 python3 py2-pip && \
pip2 install --upgrade pip && \
pip2 install --requirement requirements.txt && \
pip2 install . && \
mv /usr/bin/radon /usr/bin/radon2 && \
python3 py3-pip && \
pip3 install --requirement requirements.txt && \
pip3 install . && \
mv /usr/bin/radon /usr/bin/radon3 && \
Expand Down
9 changes: 3 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ Radon can compute:
Requirements
------------

Radon will run from **Python 2.7** to **Python 3.13** (except Python versions
from 3.0 to 3.3) with a single code base and without the need of tools like
2to3 or six. It can also run on **PyPy** without any problems (currently PyPy
3.5 v7.3.1 is used in tests).
Radon will run with **Python versions 3.3 to 3.13**; and through
**PyPy** (currently PyPy 3.5 v7.3.1 is used in tests).

Radon depends on as few packages as possible. Currently only `mando` is
strictly required (for the CLI interface). `colorama` is also listed as a
dependency but if Radon cannot import it, the output simply will not be
colored.

**Note**:
**Python 2.6** was supported until version 1.5.0. Starting from version 2.0, it
is not supported anymore.
**Python2.7** support was dropped in v6.0.0.

Installation
------------
Expand Down
6 changes: 2 additions & 4 deletions codeclimate-radon
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ if os.path.exists("/config.json"):

if config["config"].get("python_version"):
version = config["config"].get("python_version")
if version == "2" or version == 2:
binstub = "radon2"
elif version != "3" and version != 3:
sys.exit("Invalid python_version; must be either 2 or 3")
if version != "3" and version != 3:
sys.exit("Invalid python_version; must be version 3")
if config["config"].get("encoding"):
encoding = config["config"].get("encoding")
os.environ["RADONFILESENCODING"] = encoding
Expand Down
18 changes: 8 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Radon documentation build configuration file, created by
# sphinx-quickstart on Thu Oct 11 16:08:21 2012.
#
Expand Down Expand Up @@ -46,9 +44,9 @@
master_doc = 'index'

# General information about the project.
project = u'Radon'
project = 'Radon'
build_date = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
copyright = u'{0}, Michele Lacchia'.format('-'.join(map(str,
copyright = '{0}, Michele Lacchia'.format('-'.join(map(str,
range(2012,
build_date.year + 1))))

Expand Down Expand Up @@ -193,8 +191,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'Radon.tex', u'Radon Documentation',
u'Michele Lacchia', 'manual'),
('index', 'Radon.tex', 'Radon Documentation',
'Michele Lacchia', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -223,8 +221,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'radon', u'Radon Documentation',
[u'Michele Lacchia'], 1)
('index', 'radon', 'Radon Documentation',
['Michele Lacchia'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -237,8 +235,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Radon', u'Radon Documentation',
u'Michele Lacchia', 'Radon', 'One line description of project.',
('index', 'Radon', 'Radon Documentation',
'Michele Lacchia', 'Radon', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ colorama = [
[tool.poetry.group.dev.dependencies]
coverage = "*"
coveralls = "*"
pytest = [
{version = ">=2.7", markers = "python_version < \"3.0\""},
{version = ">5.0", markers = "python_version >= \"3.0\""}
]
pytest = ">5.0"
pytest-mock = "*"
argparse = "*"
nbformat = "*"
Expand Down
20 changes: 6 additions & 14 deletions radon/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'''In this module the CLI interface is created.'''

import configparser
import inspect
import os
import sys
Expand Down Expand Up @@ -27,16 +28,11 @@
RawHarvester,
)

if sys.version_info[0] == 2:
import ConfigParser as configparser
else:
import configparser


CONFIG_SECTION_NAME = 'radon'


class FileConfig(object):
class FileConfig:
'''
Yield default options by reading local configuration files.
'''
Expand Down Expand Up @@ -319,7 +315,7 @@ def hal(
log_result(harvester, json=json, xml=False, md=False, stream=stream)


class Config(object):
class Config:
'''An object holding config values.'''

def __init__(self, **kwargs):
Expand Down Expand Up @@ -347,12 +343,8 @@ def __eq__(self, other):
@classmethod
def from_function(cls, func):
'''Construct a Config object from a function's defaults.'''
kwonlydefaults = {}
try:
argspec = inspect.getfullargspec(func)
kwonlydefaults = argspec.kwonlydefaults or {}
except AttributeError: # pragma: no cover
argspec = inspect.getargspec(func)
argspec = inspect.getfullargspec(func)
kwonlydefaults = argspec.kwonlydefaults or {}
args, _, _, defaults = argspec[:4]
values = dict(zip(reversed(args), reversed(defaults or [])))
values.update(kwonlydefaults)
Expand Down Expand Up @@ -420,7 +412,7 @@ def log_list(lst, *args, **kwargs):

def log_error(msg, *args, **kwargs):
'''Log an error message. Arguments are the same as log().'''
log('{0}{1}ERROR{2}: {3}'.format(BRIGHT, RED, RESET, msg), *args, **kwargs)
log('{}{}ERROR{}: {}'.format(BRIGHT, RED, RESET, msg), *args, **kwargs)


@contextmanager
Expand Down
18 changes: 6 additions & 12 deletions radon/cli/harvest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'''This module holds the base Harvester class and all its subclassess.'''

import collections
import io
import json
import sys
from builtins import super

from radon.cli.colors import MI_RANKS, RANKS_COLORS, RESET
from radon.cli.tools import (
Expand All @@ -26,11 +25,6 @@
from radon.metrics import h_visit, mi_rank, mi_visit
from radon.raw import analyze

if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO

try:
import nbformat

Expand All @@ -39,7 +33,7 @@
SUPPORTS_IPYNB = False


class Harvester(object):
class Harvester:
'''Base class defining the interface of a Harvester object.
A Harvester has the following lifecycle:
Expand Down Expand Up @@ -108,17 +102,17 @@ def run(self):
doc = "\n".join(cells)
yield (
name,
self.gobble(StringIO(strip_ipython(doc))),
self.gobble(io.StringIO(strip_ipython(doc))),
)

if self.config.ipynb_cells:
# Individual cells
cellid = 0
for source in cells:
yield (
"{0}:[{1}]".format(name, cellid),
"{}:[{}]".format(name, cellid),
self.gobble(
StringIO(strip_ipython(source))
io.StringIO(strip_ipython(source))
),
)
cellid += 1
Expand Down Expand Up @@ -374,7 +368,7 @@ def to_terminal(self):
color = MI_RANKS[rank]
to_show = ''
if self.config.show:
to_show = ' ({0:.2f})'.format(mi['mi'])
to_show = ' ({:.2f})'.format(mi['mi'])
yield '{0} - {1}{2}{3}{4}', (name, color, rank, to_show, RESET), {}


Expand Down
Loading

0 comments on commit 6673255

Please sign in to comment.