Import Upstream version 0.4

This commit is contained in:
luoyaoming 2024-05-08 09:35:43 +08:00
parent 0574c164b9
commit 1f0bcc225b
18 changed files with 106 additions and 156 deletions

25
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install . pytest
- name: Run tests
run: pytest

View File

@ -1,10 +0,0 @@
language: python
python:
- "3.6"
- "3.5"
- "3.4"
- "2.7"
install:
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install configparser; fi
# command to run tests
script: py.test

View File

@ -1,3 +1,7 @@
**This package is in maintenance-only mode.** New code should use the
`importlib.metadata module <https://docs.python.org/3/library/importlib.metadata.html>`_
in the Python standard library to find and load entry points.
Entry points are a way for Python packages to advertise objects with some
common interface. The most common examples are ``console_scripts`` entry points,
which define shell commands by identifying a Python function to run.
@ -11,4 +15,23 @@ You can install it from PyPI with ``pip install entrypoints``.
To advertise entry points when distributing a package, see
`entry_points in the Python Packaging User Guide
<https://packaging.python.org/en/latest/distributing.html#entry-points>`_.
<https://packaging.python.org/guides/distributing-packages-using-setuptools/#entry-points>`_.
The ``pkg_resources`` module distributed with ``setuptools`` provides a way to
discover entrypoints as well, but it contains other functionality unrelated to
entrypoint discovery, and it does a lot of work at import time. Merely
*importing* ``pkg_resources`` causes it to scan the files of all installed
packages. Thus, in environments where a large number of packages are installed,
importing ``pkg_resources`` can be very slow (several seconds).
By contrast, ``entrypoints`` is focused solely on entrypoint discovery and it
is faster. Importing ``entrypoints`` does not scan anything, and getting a
given entrypoint group performs a more focused scan.
When there are multiple versions of the same distribution in different
directories on ``sys.path``, ``entrypoints`` follows the rule that the first
one wins. In most cases, this follows the logic of imports. Similarly,
Entrypoints relies on ``pip`` to ensure that only one ``.dist-info`` or
``.egg-info`` directory exists for each installed package. There is no reliable
way to pick which of several `.dist-info` folders accurately relates to the
importable modules.

5
debian/changelog vendored
View File

@ -1,5 +0,0 @@
entrypoints (0.3-ok1) yangtze; urgency=medium
* Build for openKylin.
-- openKylinBot <openKylinBot@openkylin.com> Mon, 25 Apr 2022 22:03:04 +0800

33
debian/control vendored
View File

@ -1,33 +0,0 @@
Source: entrypoints
Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Uploaders: Julien Puydt <jpuydt@debian.org>
Section: python
Priority: optional
Standards-Version: 4.5.0
Homepage: https://github.com/takluyver/entrypoints
Build-Depends: debhelper-compat (= 12),
dh-python,
python-all,
python-configparser,
python3
Vcs-Git: https://salsa.debian.org/python-team/modules/entrypoints.git
Vcs-Browser: https://salsa.debian.org/python-team/modules/entrypoints
Testsuite: autopkgtest-pkg-python
Package: python-entrypoints
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, python-configparser
Description: Discover and load entry points from installed packages (Python 2)
This module contains functions to find and load entry points
in installed packages.
.
This package installs the library for Python 2.
Package: python3-entrypoints
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}
Description: Discover and load entry points from installed packages (Python 3)
This module contains functions to find and load entry points
in installed packages.
.
This package installs the library for Python 3.

29
debian/copyright vendored
View File

@ -1,29 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: entrypoints
Files: *
Copyright: 2015 Thomas Kluyver <thomas@kluyver.me.uk> and contributors
License: Expat
Files: debian/*
Copyright: 2015-2018 Julien Puydt <jpuydt@debian.org>
License: Expat
License: Expat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,7 +0,0 @@
Metadata-Version: 1.1
Name: entrypoints
Version: @VERSION@
Summary: Discover and load entry points from installed packages
Author: Thomas Kluyver
Author-email: thomas@kluyver.me.uk
Classifier: License :: OSI Approved :: MIT License

18
debian/rules vendored
View File

@ -1,18 +0,0 @@
#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk
#export DH_VERBOSE=1
export PYBUILD_NAME=entrypoints
# Debian doesn't have flit:
export PYBUILD_SYSTEM=custom
export PYBUILD_CLEAN_ARGS=rm -rf {build_dir}/python{version}/dist-packages
export PYBUILD_CONFIGURE_ARGS=true
export PYBUILD_BUILD_ARGS=true
export PYBUILD_INSTALL_ARGS=mkdir -p {destdir}/usr/lib/python{version}/dist-packages && cp entrypoints.py {destdir}/usr/lib/python{version}/dist-packages && sed -e s/@VERSION@/$(DEB_VERSION_UPSTREAM)/g debian/entrypoints.egg-info.in > {destdir}/usr/lib/python{version}/dist-packages/entrypoints.egg-info
export PYBUILD_TEST_ARGS_python2 = true
export PYBUILD_TEST_ARGS_python3 = true
%:
dh $@ --with python2,python3 --buildsystem=pybuild

View File

@ -1 +0,0 @@
3.0 (native)

View File

@ -1,5 +0,0 @@
Tests: upstreamtestsuite2
Depends: python-entrypoints, python-pytest
Tests: upstreamtestsuite3
Depends: python3-entrypoints, python3-pytest

View File

@ -1,3 +0,0 @@
#!/bin/sh
set -e
pytest tests 2>1

View File

@ -1,3 +0,0 @@
#!/bin/sh
set -e
pytest-3 tests 2>1

View File

@ -1,3 +0,0 @@
Bug-Database: https://github.com/takluyver/entrypoints/issues
Repository: https://github.com/takluyver/entrypoints.git
Repository-Browse: https://github.com/takluyver/entrypoints

3
debian/watch vendored
View File

@ -1,3 +0,0 @@
version=4
opts=uversionmangle=s/(rc|a|b|c)/~$1/ \
https://github.com/takluyver/entrypoints/releases .*/archive/(.*)\.tar\.gz

View File

@ -28,7 +28,7 @@ file_in_zip_pattern = re.compile(r"""
[/\\]entry_points.txt$
""", re.VERBOSE)
__version__ = '0.3'
__version__ = '0.4'
class BadEntryPoint(Exception):
"""Raised when an entry point can't be parsed.
@ -107,6 +107,18 @@ class Distribution(object):
self.name = name
self.version = version
@classmethod
def from_name_version(cls, name):
"""Parse a distribution from a "name-version" string
:param str name: The name-version string (entrypoints-0.3)
Returns an :class:`Distribution` object
"""
version = None
if '-' in name:
name, version = name.split('-', 1)
return cls(name, version)
def __repr__(self):
return "Distribution(%r, %r)" % (self.name, self.version)
@ -125,15 +137,12 @@ def iter_files_distros(path=None, repeated_distro='first'):
if folder.rstrip('/\\').endswith('.egg'):
# Gah, eggs
egg_name = osp.basename(folder)
if '-' in egg_name:
distro = Distribution(*egg_name.split('-')[:2])
distro = Distribution.from_name_version(egg_name.split(".egg")[0])
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
else:
distro = None
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
if osp.isdir(folder):
ep_path = osp.join(folder, 'EGG-INFO', 'entry_points.txt')
@ -151,8 +160,8 @@ def iter_files_distros(path=None, repeated_distro='first'):
cp = CaseSensitiveConfigParser(delimiters=('=',))
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu,
source=osp.join(folder, 'EGG-INFO', 'entry_points.txt'))
cp.read_file(fu, source=osp.join(
folder, 'EGG-INFO', 'entry_points.txt'))
yield cp, distro
# zip imports, not egg
@ -164,15 +173,12 @@ def iter_files_distros(path=None, repeated_distro='first'):
continue
distro_name_version = m.group('dist_version')
if '-' in distro_name_version:
distro = Distribution(*distro_name_version.split('-', 1))
distro = Distribution.from_name_version(distro_name_version)
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
else:
distro = None
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
cp = CaseSensitiveConfigParser(delimiters=('=',))
with zf.open(info) as f:
@ -182,19 +188,17 @@ def iter_files_distros(path=None, repeated_distro='first'):
# Regular file imports (not egg, not zip file)
for path in itertools.chain(
glob.iglob(osp.join(folder, '*.dist-info', 'entry_points.txt')),
glob.iglob(osp.join(folder, '*.egg-info', 'entry_points.txt'))
glob.iglob(osp.join(glob.escape(folder), '*.dist-info', 'entry_points.txt')),
glob.iglob(osp.join(glob.escape(folder), '*.egg-info', 'entry_points.txt'))
):
distro_name_version = osp.splitext(osp.basename(osp.dirname(path)))[0]
if '-' in distro_name_version:
distro = Distribution(*distro_name_version.split('-', 1))
distro = Distribution.from_name_version(distro_name_version)
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
else:
distro = None
cp = CaseSensitiveConfigParser(delimiters=('=',))
cp.read([path])
yield cp, distro

View File

@ -1,6 +1,6 @@
[build-system]
requires = ["flit"]
build-backend = "flit.buildapi"
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "entrypoints"
@ -10,11 +10,9 @@ home-page = "https://github.com/takluyver/entrypoints"
description-file = "README.rst"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3"
]
requires-python = ">=2.7"
requires = ["configparser (>=3.5); python_version == '2.7'"]
requires-python = ">=3.6"
[tool.flit.metadata.urls]
Documentation = "https://entrypoints.readthedocs.io/en/latest/"

View File

@ -0,0 +1,3 @@
[entrypoints.test1]
def = dev:def

View File

@ -17,11 +17,28 @@ sample_path = [
osp.join(samples_dir, 'packages2', 'qux-0.4.egg'),
]
def test_iter_files_distros():
result = entrypoints.iter_files_distros(path=sample_path)
# the sample_path has 4 unique items so iter_files_distros returns 4 tuples
assert len(list(result)) == 4
# testing a development, egg aka installed with pip install -e .
# these don't have version info in the .egg-info directory name
# (eg dev-0.0.1.egg-info)
path_with_dev = [osp.join(samples_dir, 'packages4')]
result = entrypoints.iter_files_distros(path=path_with_dev)
assert len(list(result)) == 1
# duplicate dev versions should still return one result
path_with_dev_duplicates = path_with_dev * 2
result = entrypoints.iter_files_distros(path=path_with_dev_duplicates)
assert len(list(result)) == 1
def test_get_group_all():
group = entrypoints.get_group_all('entrypoints.test1', sample_path)
print(group)
assert len(group) == 5
assert set(ep.name for ep in group) == {'abc', 'rew', 'opo', 'njn'}
assert {ep.name for ep in group} == {'abc', 'rew', 'opo', 'njn'}
def test_get_group_named():
group = entrypoints.get_group_named('entrypoints.test1', sample_path)