Skip to content

Commit

Permalink
Merge branch 'main' into py37-plus-pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
fangchenli committed Nov 2, 2022
2 parents 59aa8ef + 0031046 commit db3cfbd
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 735 deletions.
9 changes: 0 additions & 9 deletions .coveragerc

This file was deleted.

9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
os: [Ubuntu, Windows, macOS]
python_version:
["3.7", "3.8", "3.9", "3.10", "pypy3.7", "pypy3.8", "pypy3.9"]
["3.7", "3.8", "3.9", "3.10", "3.11-dev", "pypy3.7", "pypy3.8", "pypy3.9"]

steps:
- uses: actions/checkout@v3
Expand All @@ -35,4 +35,9 @@ jobs:
cache: "pip"

- name: Run nox
run: pipx run nox --error-on-missing-interpreters -s tests-${{ matrix.python_version }}
run: |
# Need to remove "-dev" suffix
INTERPRETER=${{ matrix.python_version }}
INTERPRETER=${INTERPRETER/-dev/}
pipx run nox --error-on-missing-interpreters -s tests-${INTERPRETER}
shell: bash
23 changes: 20 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ Changelog
*unreleased*
~~~~~~~~~~~~

* Explicitly declare support for Python 3.11 (:issue:`587`)
* Remove support for Python 3.6 (:issue:`500`)
* Remove ``LegacySpecifier`` and ``LegacyVersion`` (:issue:`407`)
* Add ``__hash__`` and ``__eq__`` to ``Requirement`` (:issue:`499`)
* Add a ``cpNNN-none-any`` tag (:issue:`541`)
* Adhere to :pep:`685` when evaluating markers with extras (:issue:`545`)
* Allow accepting locally installed prereleases with ``SpecifierSet`` (:issue:`515`)
* Allow pre-release versions in marker evaluation (:issue:`523`)
* Correctly parse ELF for musllinux on Big Endian (:issue:`538`)
* Document ``packaging.utils.NormalizedName`` (:issue:`565`)
* Document exceptions raised by functions in ``packaging.utils`` (:issue:`544`)
* Fix compatible version specifier incorrectly strip trailing ``0`` (:issue:`493`)
* Fix macOS platform tags with old macOS SDK (:issue:`513`)
* Forbid prefix version matching on pre-release/post-release segments (:issue:`563`)
* Normalize specifier version for prefix matching (:issue:`561`)
* Improve documentation for ``packaging.specifiers`` and ``packaging.version``. (:issue:`572`)
* ``Marker.evaluate`` will now assume evaluation environment with empty ``extra``.
Evaluating markers like ``"extra == 'xyz'"`` without passing any extra in the
``environment`` will no longer raise an exception.
* Remove dependency on ``pyparsing``, by replacing it with a hand-written parser. This package now has no runtime dependencies (:issue:`468`)
``environment`` will no longer raise an exception (:issue:`550`)
* Remove dependency on ``pyparsing``, by replacing it with a hand-written parser.
This package now has no runtime dependencies (:issue:`468`)
* Update return type hint for ``Specifier.filter`` and ``SpecifierSet.filter``
to use ``Iterator`` instead of ``Iterable``
to use ``Iterator`` instead of ``Iterable`` (:issue:`584`)

21.3 - 2021-11-17
~~~~~~~~~~~~~~~~~
Expand Down
23 changes: 0 additions & 23 deletions MANIFEST.in

This file was deleted.

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ You can install packaging with ``pip``:
markers
requirements
tags
metadata
utils

.. toctree::
Expand Down
14 changes: 0 additions & 14 deletions docs/metadata.rst

This file was deleted.

3 changes: 3 additions & 0 deletions docs/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ items that applications should need to reference, in order to parse and check ta

:param bool warn: Whether warnings should be logged. Defaults to ``False``.

.. versionchanged:: 21.3
Added the `pp3-none-any` tag (:issue:`311`).


Low Level Interface
'''''''''''''''''''
Expand Down
7 changes: 4 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
nox.options.reuse_existing_virtualenvs = True


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7", "pypy3.8", "pypy3.9"])
@nox.session(
python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8", "pypy3.9"]
)
def tests(session):
def coverage(*args):
session.run("python", "-m", "coverage", *args)

# Once coverage 5 is used then `.coverage` can move into `pyproject.toml`.
session.install("coverage<5.0.0", "pretend", "pytest>=6.2.0", "pip>=9.0.2")
session.install("coverage[toml]>=5.0.0", "pretend", "pytest>=6.2.0", "pip>=9.0.2")
session.install(".")

if "pypy" not in session.python:
Expand Down
108 changes: 108 additions & 0 deletions packaging/_elffile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""
ELF file parser.
This provides a class ``ELFFile`` that parses an ELF executable in a similar
interface to ``ZipFile``. Only the read interface is implemented.
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
"""

import enum
import os
import struct
from typing import IO, Optional, Tuple


class ELFInvalid(ValueError):
pass


class EIClass(enum.IntEnum):
C32 = 1
C64 = 2


class EIData(enum.IntEnum):
Lsb = 1
Msb = 2


class EMachine(enum.IntEnum):
I386 = 3
S390 = 22
Arm = 40
X8664 = 62
AArc64 = 183


class ELFFile:
"""
Representation of an ELF executable.
"""

def __init__(self, f: IO[bytes]) -> None:
self._f = f

try:
ident = self._read("16B")
except struct.error:
raise ELFInvalid("unable to parse identification")
magic = bytes(ident[:4])
if magic != b"\x7fELF":
raise ELFInvalid(f"invalid magic: {magic!r}")

self.capacity = ident[4] # Format for program header (bitness).
self.encoding = ident[5] # Data structure encoding (endianess).

try:
# e_fmt: Format for program header.
# p_fmt: Format for section header.
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
e_fmt, self._p_fmt, self._p_idx = {
(1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
(1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
(2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
(2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
}[(self.capacity, self.encoding)]
except KeyError:
raise ELFInvalid(
f"unrecognized capacity ({self.capacity}) or "
f"encoding ({self.encoding})"
)

try:
(
_,
self.machine, # Architecture type.
_,
_,
self._e_phoff, # Offset of program header.
_,
self.flags, # Processor-specific flags.
_,
self._e_phentsize, # Size of section.
self._e_phnum, # Number of sections.
) = self._read(e_fmt)
except struct.error as e:
raise ELFInvalid("unable to parse machine and section information") from e

def _read(self, fmt: str) -> Tuple[int, ...]:
return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))

@property
def interpreter(self) -> Optional[str]:
"""
The path recorded in the ``PT_INTERP`` section header.
"""
for index in range(self._e_phnum):
self._f.seek(self._e_phoff + self._e_phentsize * index)
try:
data = self._read(self._p_fmt)
except struct.error:
continue
if data[self._p_idx[0]] != 3: # Not PT_INTERP.
continue
self._f.seek(data[self._p_idx[1]])
return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
return None

0 comments on commit db3cfbd

Please sign in to comment.