Skip to content

Commit

Permalink
Added a test running check-manifest, if installed (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro authored Apr 30, 2023
1 parent e363f67 commit f4ef699
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Changelog
only implemented so that I can add a test using check-manifest and
skip it when run from the zest.releaser hook.

- If you also have check-manifest installed, pyroma will run that as a test.
No longer do you need to call it separately! However, if Pyroma is invoked
from zest.releaser, it will not be run, because check-manifest has a separate
hook for zest.releaser, so that would run it twice.


4.2 (2023-02-25)
----------------
Expand Down
2 changes: 1 addition & 1 deletion pyroma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def zester(data):
from zest.releaser.utils import ask

if ask("Run pyroma on the package before tagging?"):
rating = run("directory", os.path.abspath(data["workingdir"]))
rating = run("directory", os.path.abspath(data["workingdir"]), skip_tests="CheckManifest")
if rating < 8:
if not ask("Continue?"):
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pyroma/distributiondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_data(path):
raise ValueError("Unknown file type: " + ext)

projectpath = os.path.join(tempdir, basename)
data = projectdata.get_data(projectpath)
data = projectdata._get_data(projectpath)
finally:
shutil.rmtree(tempdir, ignore_errors=True)

Expand Down
6 changes: 6 additions & 0 deletions pyroma/projectdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def get_setupcfg_data(path):


def get_data(path):
data = _get_data(path)
data["_path"] = path
return data


def _get_data(path):
try:
return get_build_data(path)
except build.BuildException as e:
Expand Down
33 changes: 33 additions & 0 deletions pyroma/ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# False for fail and None for not applicable (meaning it will
# not be counted).
import io
import os
import re
from collections import defaultdict

Expand Down Expand Up @@ -507,6 +508,38 @@ def message(self):
StoneAgeSetupPy(),
]

try:
import check_manifest

class CheckManifest(BaseTest):
weight = 0

def test(self, data):
if "_path" not in data:
return None

if not os.path.exists(data["_path"]):
import pdb

pdb.set_trace()
self.weight = 200
try:
return check_manifest.check_manifest(data["_path"])
except check_manifest.Failure:
# Most likely this means check-manifest didn't find any
# package configuration, which is the same failure as
# MissingBuildSystem, so this is double errors, but
# it does mean your setup is completely broken, so...
return False

def message(self):
return "Check-manifest returned errors"

ALL_TESTS.append(CheckManifest())

except ImportError:
pass


def rate(data, skip_tests=None):
if not data:
Expand Down
1 change: 1 addition & 0 deletions pyroma/testdata/minimal/randomfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This should cause an error with check-manifest
11 changes: 8 additions & 3 deletions pyroma/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_only_config(self):
self.assertEqual(
rating,
(
7,
6,
[
(
"You should specify what Python versions you support with "
Expand All @@ -137,12 +137,15 @@ def test_only_config(self):
' build-backend = "setuptools.build_meta"\n\n'
"In the future this will become a hard failure and your package will be "
'rated as "not cheese".',
"Check-manifest returned errors",
],
),
)

def test_skip_tests(self):
rating = self._get_file_rating("only_config", skip_tests=["PythonRequiresVersion", "MissingBuildSystem"])
rating = self._get_file_rating(
"only_config", skip_tests=["PythonRequiresVersion", "MissingBuildSystem", "CheckManifest"]
)

self.assertEqual(
rating,
Expand Down Expand Up @@ -193,6 +196,7 @@ def test_minimal(self):
"Your package does neither have a license field nor any license classifiers.",
"Specifying a development status in the classifiers gives users "
"a hint of how stable your software is.",
"Check-manifest returned errors",
],
),
)
Expand Down Expand Up @@ -233,7 +237,7 @@ def test_custom_test(self):
self.assertEqual(
rating,
(
2,
3,
[
"The package's description should be longer than 10 characters.",
"The package's long_description is quite short.",
Expand Down Expand Up @@ -325,6 +329,7 @@ def test_complete(self):
directory = resource_filename(__name__, os.path.join("testdata", "complete"))

data = projectdata.get_data(directory)
del data["_path"] # This changes, so I just ignore it
self.assertEqual(data, COMPLETE)


Expand Down

0 comments on commit f4ef699

Please sign in to comment.