Skip to content

Commit

Permalink
Merge pull request #99 from release-engineering/py312
Browse files Browse the repository at this point in the history
Support Python 3.12
  • Loading branch information
mikebonnet authored Dec 5, 2023
2 parents 484a15f + 0f49e35 commit 13e94d2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
.eggs
*.egg-info
.tox
.coverage*
htmldocs
doc/topics.rst
3 changes: 1 addition & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cloud_sptheme
nose
fedmsg
fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop
mako
63 changes: 35 additions & 28 deletions fedmsg_meta_umb/doc_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
This code:
- Uses :mod:`nose` to find all the fedmsg.meta unittests.
- Uses :mod:`unittest` to find all the fedmsg.meta unittests.
- Extracts all the metadata and docstrings from those tests.
- Uses all that to generate a giant .rst document of all the fedmsg
topics and what they are about with example messages.
"""

import nose
import unittest
import pprint
import textwrap
import uuid
Expand Down Expand Up @@ -103,10 +103,20 @@ def datagrepper_link(topic):


def load_classes(module):
testdir = os.path.dirname(os.path.abspath(__file__)) + '/tests'
suitelist = map(list, nose.loader.defaultTestLoader().loadTestsFromDir(testdir))
clslist = [cls for suite in suitelist for cls in suite]
return clslist
suite = unittest.defaultTestLoader.discover(
os.path.dirname(module.__file__),
top_level_dir=os.path.dirname(__file__),
)

def _classes(s):
if isinstance(s, unittest.TestCase):
yield s.__class__
else:
for t in s:
yield from _classes(t)

return set(_classes(suite))


def make_topics_doc(output_dir):

Expand All @@ -117,21 +127,21 @@ def make_topics_doc(output_dir):
test_classes = load_classes(source_module)

# Strip out the conglomerator tests which are more complicated.
test_classes = [cls for cls in test_classes if hasattr(cls.context, 'msg')]
test_classes = [cls for cls in test_classes if hasattr(cls, 'msg')]

write(fname, header)

for cls in test_classes:
if cls.context.msg is not Unspecified:
cls.__topic = cls.context.msg['topic'].split('.', 1)[-1]
if cls.msg is not Unspecified:
cls.__topic = cls.msg['topic'].split('.', 1)[-1]
else:
cls.__topic = None

test_classes = sorted(test_classes, key=lambda x: x.__topic or '')

seen = []
for cls in test_classes:
if cls.context.msg is not Unspecified:
if cls.msg is not Unspecified:
topic = cls.__topic

# You can also exclude a test from the docs with nodoc = True
Expand All @@ -149,39 +159,36 @@ def make_topics_doc(output_dir):
write(fname, "~" * len(topic))
write(fname)

# I would use __doc__ here, but something that nose is doing is
# stripping the __doc__ from my original unit tests. Instead,
# we'll use our own 'doc' attribute which is a little clumsy.
if getattr(cls.context, 'doc', None):
write(fname, textwrap.dedent(" " + cls.context.doc.strip()))
if cls.__doc__:
write(fname, textwrap.dedent(" " + cls.__doc__.strip()))
write(fname)

write(fname, datagrepper_link(cls.context.msg['topic']))
write(fname, datagrepper_link(cls.msg['topic']))
write(fname)

write(fname, ".. code-block:: python")
write(fname, '\n ' + pprint.pformat(cls.context.msg, indent=2)
write(fname, '\n ' + pprint.pformat(cls.msg, indent=2)
.replace('\n', '\n '))
write(fname)

# This is a unique id per entry so we don't collide image tags
uid = str(uuid.uuid4())
icon_inline = Unspecified
secondary_icon_inline = Unspecified
if cls.context.expected_icon is not Unspecified:
if cls.expected_icon is not Unspecified:
icon_inline = "|%s-icon|" % uid
if cls.context.expected_secondary_icon is not Unspecified:
if cls.expected_secondary_icon is not Unspecified:
secondary_icon_inline = "|%s-secondary_icon|" % uid

# A bunch of data for the template.
kwargs = dict(
link=cls.context.expected_link,
title=cls.context.expected_title,
subtitle=cls.context.expected_subti,
usernames=cls.context.expected_usernames,
agent=cls.context.expected_agent,
packages=cls.context.expected_packages,
objects=cls.context.expected_objects,
link=cls.expected_link,
title=cls.expected_title,
subtitle=cls.expected_subti,
usernames=cls.expected_usernames,
agent=cls.expected_agent,
packages=cls.expected_packages,
objects=cls.expected_objects,
icon_inline=icon_inline,
secondary_icon_inline=secondary_icon_inline,
)
Expand All @@ -194,8 +201,8 @@ def length(value):
longest = max([length(value) for value in kwargs.values()])

write(fname, metadata_template.render(
icon=cls.context.expected_icon,
secondary_icon=cls.context.expected_secondary_icon,
icon=cls.expected_icon,
secondary_icon=cls.expected_secondary_icon,
Unspecified=Unspecified,
longest=longest,
**kwargs
Expand Down
1 change: 0 additions & 1 deletion python-fedmsg-meta-umb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Source0: %{srcname}-%{version}.tar.xz

BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3-nose
BuildRequires: python3-fedmsg
BuildRequires: python3-mako
BuildRequires: python3-cloud-sptheme
Expand Down
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@
long_description = long_description.split('split here', 1)[1]
f.close()

setup_requires = [
]
install_requires = [
'fedmsg',
]
tests_require = [
'nose',
'fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop',
]

entry_points = {
Expand Down Expand Up @@ -74,10 +69,7 @@
author_email='[email protected]',
url='https://github.com/release-engineering/fedmsg_meta_umb/',
license='LGPLv2+',
setup_requires=setup_requires,
install_requires=install_requires,
tests_require=tests_require,
test_suite='nose.collector',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
Expand Down
20 changes: 12 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
[tox]
envlist = flake8,py{38,39},docs
envlist = flake8,py312,docs
downloadcache = {toxworkdir}/_download/

[testenv]
deps =
fedmsg
nose
coverage
commands =
nosetests {posargs}
coverage run -m unittest {posargs}
coverage report

[coverage:run]
branch = true

[coverage:report]
show_missing = true
skip_empty = true

[testenv:flake8]
skip_install = true
deps=
flake8
commands=
Expand All @@ -19,9 +26,6 @@ commands=

[testenv:docs]
deps =
cloud_sptheme
nose
fedmsg
mako
-r doc/requirements.txt
commands =
sphinx-build doc/ htmldocs/

0 comments on commit 13e94d2

Please sign in to comment.