public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Arthur Zamarin" <arthurzam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, ...
Date: Fri,  3 Feb 2023 13:03:52 +0000 (UTC)	[thread overview]
Message-ID: <1675429415.87226810dca088b8eec5d03639b3d830293c82aa.arthurzam@gentoo> (raw)

commit:     87226810dca088b8eec5d03639b3d830293c82aa
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 31 18:00:51 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Feb  3 13:03:35 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=87226810

PythonCheck: check for missing scm dep when needed

Resolves: https://github.com/pkgcore/pkgcheck/issues/537
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/python.py                      | 37 ++++++++++++++++++++--
 .../PythonMissingSCMDependency/expected.json       |  1 +
 .../PythonMissingSCMDependency/fix.patch           |  8 +++++
 .../PythonMissingSCMDependency-0.ebuild            | 13 ++++++++
 .../PythonMissingSCMDependency/metadata.xml        |  4 +++
 5 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py
index 2b20ee93..11ebc1e1 100644
--- a/src/pkgcheck/checks/python.py
+++ b/src/pkgcheck/checks/python.py
@@ -1,6 +1,7 @@
-from collections import defaultdict
 import itertools
 import re
+from collections import defaultdict
+from operator import attrgetter
 
 from pkgcore import fetch
 from pkgcore.ebuild.atom import atom
@@ -222,6 +223,20 @@ class PythonAnyMismatchedDepHasVersionCheck(results.VersionResult, results.Warni
         return f"{self.dep_category}: missing check for {self.dep_atom}[{use_flags}] in {self.location!r}"
 
 
+class PythonMissingSCMDependency(results.VersionResult, results.Warning):
+    """Package is missing BDEPEND on setuptools_scm or alike.
+
+    Packages which define ``SETUPTOOLS_SCM_PRETEND_VERSION`` should BDEPEND
+    on ``dev-python/setuptools_scm`` or a similar package [#]_.
+
+    .. [#] https://projects.gentoo.org/python/guide/distutils.html#setuptools-scm-flit-scm-hatch-vcs-and-snapshots
+    """
+
+    desc = (
+        "defines SETUPTOOLS_SCM_PRETEND_VERSION but is missing BDEPEND on setuptools_scm or alike"
+    )
+
+
 class PythonCheck(Check):
     """Python eclass checks.
 
@@ -242,6 +257,7 @@ class PythonCheck(Check):
             PythonHasVersionMissingPythonUseDep,
             PythonAnyMismatchedUseHasVersionCheck,
             PythonAnyMismatchedDepHasVersionCheck,
+            PythonMissingSCMDependency,
         ]
     )
 
@@ -263,6 +279,14 @@ class PythonCheck(Check):
         "python-r1": "python_gen_any_dep",
     }
 
+    setuptools_scm = frozenset(
+        {
+            "dev-python/setuptools_scm",
+            "dev-python/flit_scm",
+            "dev-python/hatch-vcs",
+        }
+    )
+
     def scan_tree_recursively(self, deptree, expected_cls):
         for x in deptree:
             if not isinstance(x, expected_cls):
@@ -319,6 +343,7 @@ class PythonCheck(Check):
         """
         has_distutils_optional = None
         has_distutils_deps = False
+        uses_setuptools_scm = False
         pep517_value = None
 
         for var_node, _ in bash.var_assign_query.captures(pkg.tree.root_node):
@@ -328,21 +353,29 @@ class PythonCheck(Check):
                 has_distutils_optional = True
             elif var_name == "DISTUTILS_USE_PEP517":
                 pep517_value = pkg.node_str(var_node.children[-1])
+            elif var_name == "SETUPTOOLS_SCM_PRETEND_VERSION":
+                uses_setuptools_scm = True
 
             if "DISTUTILS_DEPS" in pkg.node_str(var_node.parent):
                 # If they're referencing the eclass' dependency variable,
                 # there's nothing for us to do anyway.
                 has_distutils_deps = True
 
+        bdepends = frozenset(map(attrgetter("key"), iflatten_instance(pkg.bdepend, atom)))
+
         if pep517_value is None:
             yield DistutilsNonPEP517Build(pkg=pkg)
         elif has_distutils_optional and not has_distutils_deps and pep517_value != "no":
             # We always need BDEPEND for these if != no.
             # We are looking for USE-conditional on appropriate target
             # flag, with dep on dev-python/gpep517.
-            if "dev-python/gpep517" not in iflatten_instance(pkg.bdepend, atom):
+            if "dev-python/gpep517" not in bdepends:
                 yield PythonMissingDeps("BDEPEND", pkg=pkg, dep_value="DISTUTILS_DEPS")
 
+        if uses_setuptools_scm:
+            if not self.setuptools_scm.intersection(bdepends):
+                yield PythonMissingSCMDependency(pkg=pkg)
+
     @staticmethod
     def _prepare_deps(deps: str):
         try:

diff --git a/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json
new file mode 100644
index 00000000..9297a0d5
--- /dev/null
+++ b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/expected.json
@@ -0,0 +1 @@
+{"__class__": "PythonMissingSCMDependency", "category": "PythonCheck", "package": "PythonMissingSCMDependency", "version": "0"}

diff --git a/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch
new file mode 100644
index 00000000..94f8de26
--- /dev/null
+++ b/testdata/data/repos/python/PythonCheck/PythonMissingSCMDependency/fix.patch
@@ -0,0 +1,8 @@
+--- python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild
++++ fixed/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild
+@@ -10,4 +10,5 @@
+ LICENSE="BSD"
+ SLOT="0"
+
++BDEPEND="dev-python/hatch-vcs[${PYTHON_USEDEP}]"
+ export SETUPTOOLS_SCM_PRETEND_VERSION=${PV}

diff --git a/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild
new file mode 100644
index 00000000..79a8a8df
--- /dev/null
+++ b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/PythonMissingSCMDependency-0.ebuild
@@ -0,0 +1,13 @@
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_10 )
+
+inherit distutils-r1
+
+DESCRIPTION="Ebuild with missing dep on scm"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+LICENSE="BSD"
+SLOT="0"
+
+export SETUPTOOLS_SCM_PRETEND_VERSION=${PV}

diff --git a/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml
new file mode 100644
index 00000000..097975e3
--- /dev/null
+++ b/testdata/repos/python/PythonCheck/PythonMissingSCMDependency/metadata.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+</pkgmetadata>


             reply	other threads:[~2023-02-03 13:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 13:03 Arthur Zamarin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-11-22 21:35 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, Michał Górny
2024-08-01 19:41 Arthur Zamarin
2023-09-23 15:10 Arthur Zamarin
2023-04-24 16:43 Arthur Zamarin
2023-01-30 19:07 Arthur Zamarin
2023-01-18  5:19 Arthur Zamarin
2023-01-18  5:19 Arthur Zamarin
2023-01-14 20:29 Arthur Zamarin
2023-01-02 20:19 Arthur Zamarin
2022-10-30 18:04 Arthur Zamarin
2022-10-13 17:06 Arthur Zamarin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1675429415.87226810dca088b8eec5d03639b3d830293c82aa.arthurzam@gentoo \
    --to=arthurzam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox