Re: [gentoo-dev] [PATCH] pypi.eclass: A new eclass to aid creating PyPI SRC_URIs

2023-02-01 Thread Michał Górny
On Wed, 2023-02-01 at 23:20 +0100, Adrian Schollmeyer wrote:
> Hi,
> 
> Am Mittwoch, dem 01.02.2023 um 20:37 +0100 schrieb Michał Górny:
> > +   printf "https://files.pythonhosted.org/packages/source/%s; \
> > +   "${project::1}/${project}/${project}-${version}${suffix}"
> We have the mirror://pypi URI for PyPI sources. Is there a reason not
> to use this mirror URI in the eclass?
> 

The purpose of this eclass is to replace mirror://pypi/.

-- 
Best regards,
Michał Górny




Re: [gentoo-dev] [PATCH] pypi.eclass: A new eclass to aid creating PyPI SRC_URIs

2023-02-01 Thread Anna (cybertailor) Vyalkova
Much wanted eclass. Thanks!



Re: [gentoo-dev] [PATCH] pypi.eclass: A new eclass to aid creating PyPI SRC_URIs

2023-02-01 Thread Adrian Schollmeyer
Hi,

Am Mittwoch, dem 01.02.2023 um 20:37 +0100 schrieb Michał Górny:
> +   printf "https://files.pythonhosted.org/packages/source/%s; \
> +   "${project::1}/${project}/${project}-${version}${suffix}"
We have the mirror://pypi URI for PyPI sources. Is there a reason not
to use this mirror URI in the eclass?

Best regards
Adrian


signature.asc
Description: This is a digitally signed message part


[gentoo-dev] [PATCH] pypi.eclass: A new eclass to aid creating PyPI SRC_URIs

2023-02-01 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 eclass/pypi.eclass | 117 +
 1 file changed, 117 insertions(+)
 create mode 100644 eclass/pypi.eclass


Example use on: https://github.com/gentoo/gentoo/pull/29361


diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
new file mode 100644
index ..12ce5d4ace15
--- /dev/null
+++ b/eclass/pypi.eclass
@@ -0,0 +1,117 @@
+# Copyright 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: pypi.eclass
+# @MAINTAINER:
+# Michał Górny 
+# @AUTHOR:
+# Michał Górny 
+# @SUPPORTED_EAPIS: 8
+# @BLURB: A helper eclass to generate PyPI source URIs
+# @DESCRIPTION:
+# The pypi.eclass can be used to easily obtain URLs for artifacts
+# uploaded to PyPI.org.  When inherited, the eclass defaults SRC_URI
+# to fetch ${P}.tar.gz sdist.
+#
+# If necessary, SRC_URI can be overriden by the ebuild.  Two helper
+# functions, pypi_sdist_url and pypi_wheel_url are provided to generate
+# URLs to artifacts of specified type, with customizable project name.
+# Additionally, pypi_wheel_name can be used to generate wheel filename.
+#
+# @EXAMPLE:
+# @CODE@
+# inherit pypi
+#
+# SRC_URI="$(pypi_sdist_url "${PN^}" "${PV}")"
+# S=${WORKDIR}/${P^}
+# @CODE@
+
+case ${EAPI} in
+   8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ ! ${_PYPI_ECLASS} ]]; then
+_PYPI_ECLASS=1
+
+SRC_URI="
+   
https://files.pythonhosted.org/packages/source/${PN::1}/${PN}/${P}.tar.gz
+"
+
+# @FUNCTION: pypi_sdist_url
+# @USAGE:  [ []]
+# @DESCRIPTION:
+# Output the URL to PyPI sdist for specified project/version tuple.
+#
+# If  is unspecified, it defaults to ${PV}.
+#
+# If  is unspecified, it defaults to ".tar.gz".  Another valid
+# value is ".zip" (please remember to add a BDEPEND on app-arch/unzip).
+pypi_sdist_url() {
+   if ! has "${#}" {1..3}; then
+   die "Usage: ${FUNCNAME}  [ []]"
+   fi
+
+   local project=${1}
+   local version=${2-"${PV}"}
+   local suffix=${3-.tar.gz}
+   printf "https://files.pythonhosted.org/packages/source/%s; \
+   "${project::1}/${project}/${project}-${version}${suffix}"
+}
+
+# @FUNCTION: pypi_wheel_name
+# @USAGE:  [ [ []]]
+# @DESCRIPTION:
+# Output the wheel filename for the specified project/version tuple.
+#
+# If  is unspecified, it defaults to ${PV}.
+#
+# If  is unspecified, it defaults to "py3".  It can also be
+# "py2.py3", or a specific version in case of non-pure wheels.
+#
+# If  is unspecified, it defaults to "none-any".
+# You need to specify the correct value for non-pure wheels,
+# e.g. "abi3-linux_x86_64".
+pypi_wheel_name() {
+   if ! has "${#}" {1..4}; then
+   die "Usage: ${FUNCNAME}  [ [ 
[]]]"
+   fi
+
+   local project=${1}
+   local version=${2-"${PV}"}
+   local pytag=${3-py3}
+   local abitag=${4-none-any}
+   echo "${project}-${version}-${pytag}-${abitag}.whl"
+}
+
+# @FUNCTION: pypi_wheel_url
+# @USAGE:  [ [ []]]
+# @DESCRIPTION:
+# Output the URL to PyPI wheel for specified project/version tuple.
+#
+# If  is unspecified, it defaults to ${PV}.
+#
+# If  is unspecified, it defaults to "py3".  It can also be
+# "py2.py3", or a specific version in case of non-pure wheels.
+#
+# If  is unspecified, it defaults to "none-any".
+# You need to specify the correct value for non-pure wheels,
+# e.g. "abi3-linux_x86_64".
+#
+# Note that wheels are suffixed .whl by default and therefore are not
+# unpacked automatically.  If you need automatic unpacking, use "->"
+# operator to rename it or call unzip directly.  Remember to BDEPEND
+# on app-arch/unzip.
+pypi_wheel_url() {
+   if ! has "${#}" {1..4}; then
+   die "Usage: ${FUNCNAME}  [ [ 
[]]]"
+   fi
+
+   local project=${1}
+   local version=${2-"${PV}"}
+   local pytag=${3-py3}
+   printf "https://files.pythonhosted.org/packages/%s; \
+   "${pytag}/${project::1}/${project}/$(pypi_wheel_name "${@}")"
+}
+
+fi
-- 
2.39.1