Skip to content

Commit

Permalink
Drop support for Python 2
Browse files Browse the repository at this point in the history
Remove related stuff from the spec file.
Remove Python 2 only code, disable epel-7 packit.
Remove irrelevant adjust rule from unit tests.
Get rid of other `unicode` related leftovers.
Use default encoding for running commands.
Explicitly mention the `utf-8` encoding in the docs.
Remove unnecessary `object` from class definitions.
  • Loading branch information
psss committed Nov 8, 2021
1 parent 0dd2c38 commit 75169c7
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 257 deletions.
2 changes: 0 additions & 2 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
targets:
- fedora-all
- epel-8
- epel-7

- job: copr_build
trigger: commit
Expand All @@ -27,7 +26,6 @@ jobs:
targets:
- fedora-all
- epel-8
- epel-7
list_on_homepage: True
preserve_project: True
owner: psss
Expand Down
3 changes: 2 additions & 1 deletion docs/concept.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ files on the filesystem:
* main.fmf

Special file name ``main.fmf`` works similarly as ``index.html``.
It can be used to define the top level data for the directory.
It can be used to define the top level data for the directory. All
metadata files are expected to be using the ``utf-8`` encoding.


Attributes
Expand Down
89 changes: 1 addition & 88 deletions fmf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,8 @@ BuildArch: noarch
URL: https://github.com/psss/fmf
Source0: https://github.com/psss/fmf/releases/download/%{version}/fmf-%{version}.tar.gz

# Depending on the distro, we set some defaults.
# Note that the bcond macros are named for the CLI option they create.
# "%%bcond_without" means "ENABLE by default and create a --without option"

# Fedora or RHEL 8+
%if 0%{?fedora} || 0%{?rhel} > 7
%bcond_with python2
%bcond_with oldreqs
%bcond_with englocale
# RHEL 7
%else
%bcond_without python2
# The automatic runtime dependency generator doesn't exist yet
%bcond_without oldreqs
# The C.UTF-8 locale doesn't exist, Python defaults to C (ASCII)
%bcond_without englocale
%endif

# Main tmt package requires the Python module
%if %{with python2}
Requires: python2-%{name} == %{version}-%{release}
%else
# Main fmf package requires the Python module
Requires: python%{python3_pkgversion}-%{name} == %{version}-%{release}
%endif

%description
The fmf Python module and command line tool implement a flexible
Expand All @@ -45,34 +23,6 @@ This package contains the command line tool.
%?python_enable_dependency_generator


# Python 2
%if %{with python2}
%package -n python2-%{name}
Summary: %{summary}
BuildRequires: python2-devel
BuildRequires: python2-setuptools
BuildRequires: pytest
BuildRequires: PyYAML
BuildRequires: python2-filelock
BuildRequires: python2-six
BuildRequires: git-core
%{?python_provide:%python_provide python2-%{name}}
Requires: PyYAML
Requires: python2-filelock
Requires: python2-six
Requires: git-core

%description -n python2-%{name}
The fmf Python module and command line tool implement a flexible
format for defining metadata in plain text files which can be
stored close to the source code. Thanks to hierarchical structure
with support for inheritance and elasticity it provides an
efficient way to organize data into well-sized text documents.
This package contains the Python 2 module.
%else


# Python 3
%package -n python%{python3_pkgversion}-%{name}
Summary: %{summary}
BuildRequires: python%{python3_pkgversion}-devel
Expand All @@ -83,10 +33,6 @@ BuildRequires: python%{python3_pkgversion}-filelock
BuildRequires: git-core
%{?python_provide:%python_provide python%{python3_pkgversion}-%{name}}
Requires: git-core
%if %{with oldreqs}
Requires: python%{python3_pkgversion}-PyYAML
Requires: python%{python3_pkgversion}-filelock
%endif

%description -n python%{python3_pkgversion}-%{name}
The fmf Python module and command line tool implement a flexible
Expand All @@ -95,50 +41,24 @@ stored close to the source code. Thanks to hierarchical structure
with support for inheritance and elasticity it provides an
efficient way to organize data into well-sized text documents.
This package contains the Python 3 module.
%endif


%prep
%autosetup


%build
%if %{with englocale}
export LANG=en_US.utf-8
%endif

%if %{with python2}
%py2_build
%else
%py3_build
%endif


%install
%if %{with englocale}
export LANG=en_US.utf-8
%endif

%if %{with python2}
%py2_install
%else
%py3_install
%endif

mkdir -p %{buildroot}%{_mandir}/man1
install -pm 644 fmf.1* %{buildroot}%{_mandir}/man1


%check
%if %{with englocale}
export LANG=en_US.utf-8
%endif

%if %{with python2}
%{__python2} -m pytest -vv -c tests/unit/pytest.ini -m 'not web'
%else
%{__python3} -m pytest -vv -c tests/unit/pytest.ini -m 'not web'
%endif


%{!?_licensedir:%global license %%doc}
Expand All @@ -149,17 +69,10 @@ export LANG=en_US.utf-8
%doc README.rst examples
%license LICENSE

%if %{with python2}
%files -n python2-%{name}
%{python2_sitelib}/%{name}/
%{python2_sitelib}/%{name}-*.egg-info
%license LICENSE
%else
%files -n python%{python3_pkgversion}-%{name}
%{python3_sitelib}/%{name}/
%{python3_sitelib}/%{name}-*.egg-info
%license LICENSE
%endif


%changelog
Expand Down
2 changes: 0 additions & 2 deletions fmf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" Flexible Metadata Format """

from __future__ import absolute_import, unicode_literals

from fmf.base import Tree
from fmf.utils import filter

Expand Down
10 changes: 3 additions & 7 deletions fmf/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# coding: utf-8

""" Base Metadata Classes """

from __future__ import absolute_import, unicode_literals

import copy
import os
import re
Expand Down Expand Up @@ -70,7 +66,7 @@ def unique_key_constructor(loader, node, deep=False):
# Metadata
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class Tree(object):
class Tree:
""" Metadata Tree """

def __init__(self, data, name=None, parent=None):
Expand Down Expand Up @@ -151,9 +147,9 @@ def commit(self):
self._commit = False
return self._commit

def __unicode__(self):
def __str__(self):
""" Use tree name as identifier """
return self.name # pragma: no cover
return self.name

def _initialize(self, path):
""" Find metadata tree root, detect format version """
Expand Down
30 changes: 7 additions & 23 deletions fmf/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

"""
This is command line interface for the Flexible Metadata Format.
Expand All @@ -18,8 +16,6 @@
of available options.
"""

from __future__ import absolute_import, print_function, unicode_literals

import argparse
import os
import os.path
Expand All @@ -34,7 +30,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


class Parser(object):
class Parser:
""" Command line options parser """

def __init__(self, arguments=None, path=None):
Expand All @@ -43,20 +39,11 @@ def __init__(self, arguments=None, path=None):
if path is not None:
os.chdir(path)
# Split command line if given as a string (used for testing)
if isinstance(arguments, type("")): # pragma: no cover
try:
# This is necessary for Python 2.6
self.arguments = [
arg.decode('utf8') for arg in shlex.split(
arguments.encode('utf8'))]
except AttributeError:
self.arguments = shlex.split(arguments)
# Otherwise use sys.argv (plus decode unicode for Python 2)
if arguments is None: # pragma: no cover
try:
self.arguments = [arg.decode("utf-8") for arg in sys.argv]
except AttributeError:
self.arguments = sys.argv
if isinstance(arguments, str):
self.arguments = shlex.split(arguments)
# Otherwise use sys.argv
if arguments is None:
self.arguments = sys.argv
# Enable debugging output if requested
if "--debug" in self.arguments:
utils.log.setLevel(utils.LOG_DEBUG)
Expand Down Expand Up @@ -182,10 +169,7 @@ def show(self, brief=False):
joined = "".join(output)
else:
joined = "\n".join(output)
try: # pragma: no cover
print(joined, end="")
except UnicodeEncodeError: # pragma: no cover
print(joined.encode('utf-8'), end="")
print(joined, end="")
if self.options.verbose:
utils.info("Found {0}.".format(
utils.listed(len(output), "object")))
Expand Down
5 changes: 2 additions & 3 deletions fmf/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
"""
All you need to decide if Context matches
Expand Down Expand Up @@ -32,7 +31,7 @@ class InvalidContext(Exception):
pass


class ContextValue(object):
class ContextValue:
""" Value for dimension """

def __init__(self, origin):
Expand Down Expand Up @@ -182,7 +181,7 @@ def __hash__(self):
return hash(self._to_compare)


class Context(object):
class Context:
""" Represents https://fmf.readthedocs.io/en/latest/context.html """
# Operators' definitions

Expand Down
Loading

0 comments on commit 75169c7

Please sign in to comment.