Skip to content

Commit

Permalink
feat: drop Python 2 (#363)
Browse files Browse the repository at this point in the history
* feat: drop Python 2 and 3.5

* fix: more Python 2 removed

* fix: even more Python 2 removed

* fix: even more, more Python 2 removed

* fix: recent removals

* fix: also force findall
  • Loading branch information
henryiii authored Dec 15, 2021
1 parent 7d436e6 commit 809df41
Show file tree
Hide file tree
Showing 62 changed files with 69 additions and 209 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["2.7", "3.5", "3.6", "3.8", "3.9", "3.10"]
python-version: ["3.6", "3.8", "3.9", "3.10"]
include:
- {os: macos-latest, python-version: '2.7'}
- {os: macos-latest, python-version: '3.9'}
- {os: macos-latest, python-version: '3.6'}
- {os: macos-latest, python-version: '3.10'}
- {os: windows-latest, python-version: '3.7'}
- {os: windows-latest, python-version: '3.9'}
exclude:
- {os: ubuntu-latest, python-version: '3.7'}

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repos:
- id: requirements-txt-fixer
- id: debug-statements
- id: end-of-file-fixer
- id: fix-encoding-pragma

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
Expand All @@ -31,12 +30,12 @@ repos:
rev: v1.20.0
hooks:
- id: setup-cfg-fmt
args: [--max-py-version=3.10, --min-py3-version=3.5]

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.47"
Expand All @@ -55,7 +54,7 @@ repos:
hooks:
- id: mypy
files: src
additional_dependencies: [attrs==19.3.0, types-deprecated]
additional_dependencies: [attrs==21.2.0, types-deprecated]

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
Expand Down
1 change: 0 additions & 1 deletion admin/dump_pdgid_to_lhcb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from pathlib import Path

import nox
Expand Down
22 changes: 9 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ classifiers =
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Expand All @@ -42,11 +40,9 @@ install_requires =
attrs>=19.2
deprecated
hepunits>=2.0.0
enum34>=1.1;python_version<"3.4"
importlib-resources>=2.0;python_version<"3.9"
typing>=3.7;python_version<"3.5"
typing-extensions;python_version<"3.8"
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
python_requires = >=3.6
include_package_data = True
package_dir =
=src
Expand All @@ -57,22 +53,22 @@ where = src
[options.extras_require]
all =
check-manifest>=0.42
pytest
pandas
pytest>=6
pytest-benchmark
tabulate
pandas;python_version>"3.4"
dev =
check-manifest>=0.42
pytest
pandas
pytest>=6
pytest-benchmark
tabulate
pandas;python_version>"3.4"
test =
pytest
pandas
pytest>=6
pytest-benchmark
pytest-cov
tabulate
pandas;python_version>"3.4"

[options.package_data]
* = *.csv, *.fwf, *.mcd, *.py.typed
Expand All @@ -90,5 +86,5 @@ filterwarnings =

[flake8]
max-complexity = 24
ignore = E203, E231, E501, E722, W503, B950, E402, B904
ignore = E203, E231, E501, E722, W503, B950, E402
select = C,E,F,W,B,B9
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
2 changes: 0 additions & 2 deletions src/particle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

import sys
from typing import Tuple
Expand Down
4 changes: 1 addition & 3 deletions src/particle/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import, print_function

import argparse
import sys
Expand All @@ -25,7 +23,7 @@ def main():
parser.add_argument(
"--version",
action="version",
version="%(prog)s {version}".format(version=__version__),
version=f"%(prog)s {__version__}",
)

subparsers = parser.add_subparsers(help="Subcommands")
Expand Down
2 changes: 0 additions & 2 deletions src/particle/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from typing import Tuple

Expand Down
12 changes: 2 additions & 10 deletions src/particle/converters/bimap.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

try:
# for Python 3
from collections.abc import Mapping
except ImportError:
# for Python 2.7
from collections import Mapping

import csv
from collections.abc import Mapping
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -88,7 +80,7 @@ def __init__(self, class_A, class_B, converters=(int, int), filename=None):
name_B = self.class_B.__name__.upper()

if filename is None:
filename = "{a}_to_{b}.csv".format(a=name_A.lower(), b=name_B.lower())
filename = f"{name_A.lower()}_to_{name_B.lower()}.csv"
file_object = data.basepath.joinpath(filename).open()
elif isinstance(filename, HasRead):
file_object = filename
Expand Down
2 changes: 0 additions & 2 deletions src/particle/converters/evtgen.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from .. import data
from ..pdgid import PDGID
Expand Down
2 changes: 0 additions & 2 deletions src/particle/converters/geant.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from ..geant import Geant3ID
from ..pdgid import PDGID
Expand Down
2 changes: 0 additions & 2 deletions src/particle/converters/pythia.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from ..pdgid import PDGID
from ..pythia import PythiaID
Expand Down
1 change: 0 additions & 1 deletion src/particle/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
1 change: 0 additions & 1 deletion src/particle/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
2 changes: 0 additions & 2 deletions src/particle/geant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from typing import Tuple

Expand Down
8 changes: 2 additions & 6 deletions src/particle/geant/geant3id.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand All @@ -13,7 +12,6 @@
follows the PDG rules, hence uses the standard PDG IDs.
"""

from __future__ import absolute_import

import csv

Expand Down Expand Up @@ -55,17 +53,15 @@ def from_pdgid(cls, pdgid):
for k, v in _bimap.items():
if v == pdgid:
return cls(k)
raise MatchingIDNotFound(
"Non-existent Geant3ID for input PDGID {} !".format(pdgid)
)
raise MatchingIDNotFound(f"Non-existent Geant3ID for input PDGID {pdgid} !")

def to_pdgid(self):
# type: () -> PDGID
return PDGID(_bimap[self])

def __repr__(self):
# type: () -> str
return "<Geant3ID: {:d}>".format(int(self))
return f"<Geant3ID: {int(self):d}>"

def __str__(self):
# type: () -> str
Expand Down
2 changes: 0 additions & 2 deletions src/particle/lhcb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from typing import Tuple

Expand Down
2 changes: 0 additions & 2 deletions src/particle/lhcb/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from typing import Tuple

Expand Down
2 changes: 0 additions & 2 deletions src/particle/lhcb/converters/lhcb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from ...converters.bimap import BiMap
from ...pdgid import PDGID
Expand Down
1 change: 0 additions & 1 deletion src/particle/lhcb/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
2 changes: 0 additions & 2 deletions src/particle/lhcb/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from ..particle import Particle
from .converters import LHCbName2PDGIDBiMap

Expand Down
2 changes: 0 additions & 2 deletions src/particle/particle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.

from __future__ import absolute_import

from typing import Tuple

Expand Down
14 changes: 3 additions & 11 deletions src/particle/particle/convert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down Expand Up @@ -53,6 +52,7 @@

import os
from datetime import date
from io import StringIO
from typing import (
Any,
Callable,
Expand All @@ -68,14 +68,6 @@
import numpy as np
import pandas as pd

try:
from io import StringIO
except ImportError: # Python2 workaround, could also use six
try:
from cStringIO import StringIO # type: ignore
except ImportError:
from StringIO import StringIO # type: ignore

from .. import data
from ..pdgid import PDGID, is_baryon
from .enums import (
Expand Down Expand Up @@ -346,11 +338,11 @@ def get_from_pdg_mcd(filename):
print("DUPLICATES:\n", nar[duplicated_ids])
assert (
nar[duplicated_ids].shape[0] == 0
), "Duplicate entries found in {} !".format(filename)
), f"Duplicate entries found in {filename} !"

ds_list = []
for i in range(4):
name = "ID{}".format(i + 1)
name = f"ID{i + 1}"
d = nar[~pd.isna(nar[name])].copy()
d["ID"] = d[name].astype(int)
nc = d.NameCharge.str.split(expand=True)
Expand Down
1 change: 0 additions & 1 deletion src/particle/particle/enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
Expand Down
Loading

0 comments on commit 809df41

Please sign in to comment.