From d344cd5fbcb243dc8c5556580533e8d0577d84d0 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: May 09 2020 01:13:14 +0000 Subject: Drop relative and shortened imports I've cooled on these lately. I prefer to be clear. Signed-off-by: Adam Williamson --- diff --git a/src/wikitcms/event.py b/src/wikitcms/event.py index 338fad7..9be5bcc 100644 --- a/src/wikitcms/event.py +++ b/src/wikitcms/event.py @@ -25,15 +25,15 @@ import abc import logging +from cached_property import cached_property import fedfind.helpers import fedfind.release import mwclient.errors -from cached_property import cached_property -from . import listing -from . import page -from . import helpers -from .exceptions import FedfindNotFoundError +from wikitcms.exceptions import FedfindNotFoundError +import wikitcms.helpers +import wikitcms.listing +import wikitcms.page logger = logging.getLogger(__name__) @@ -62,8 +62,8 @@ class ValidationEvent(): self.version = f"{self.release} {self.milestone} {self.compose}" # Sorting helpers. sortname is a string, sorttuple is a # 4-tuple. sorttuple is more reliable. See the function docs. - self.sortname = helpers.fedora_release_sort(self.version) - self.sorttuple = helpers.triplet_sort( + self.sortname = wikitcms.helpers.fedora_release_sort(self.version) + self.sorttuple = wikitcms.helpers.triplet_sort( self.release, self.milestone, self.compose) @abc.abstractproperty @@ -94,28 +94,28 @@ class ValidationEvent(): if self.modular: _dist = "Fedora Modular" pages = self.site.allresults(prefix=f"{_dist} {self.version} ") - return [p for p in pages if isinstance(p, page.ValidationPage)] + return [p for p in pages if isinstance(p, wikitcms.page.ValidationPage)] @property def download_page(self): """The DownloadPage for this event. Is a property because page instantiation requires a remote trip. """ - return page.DownloadPage(self.site, self, modular=self.modular) + return wikitcms.page.DownloadPage(self.site, self, modular=self.modular) @property def ami_page(self): """The AMIPage for this event. Is a property because page instantiation requires a remote trip. """ - return page.AMIPage(self.site, self, modular=self.modular) + return wikitcms.page.AMIPage(self.site, self, modular=self.modular) @property def parent_category_page(self): """The parent category page for this event. Is a property for the same reason as download_page. """ - return listing.ValidationCategory(self.site, self.release, modular=self.modular) + return wikitcms.listing.ValidationCategory(self.site, self.release, modular=self.modular) @property def valid_pages(self): @@ -138,7 +138,7 @@ class ValidationEvent(): page. Very simple property, but not set in __init__ as the summary page object does (slow) wiki roundtrips in __init__. """ - return page.SummaryPage(self.site, self, modular=self.modular) + return wikitcms.page.SummaryPage(self.site, self, modular=self.modular) @cached_property def ff_release(self): @@ -296,7 +296,7 @@ class ComposeEvent(ValidationEvent): """The category page for this event. Is a property because page instantiation requires a remote trip. """ - return listing.ValidationCategory( + return wikitcms.listing.ValidationCategory( self.site, self.release, self.milestone, modular=self.modular) @property @@ -310,7 +310,7 @@ class ComposeEvent(ValidationEvent): @property def _pagetype(self): """For a ComposeEvent, obviously, ComposePage.""" - return page.ComposePage + return wikitcms.page.ComposePage @cached_property def creation_date(self): @@ -373,7 +373,7 @@ class NightlyEvent(ValidationEvent): """The category page for this event. Is a property because page instantiation requires a remote trip. """ - return listing.ValidationCategory( + return wikitcms.listing.ValidationCategory( self.site, self.release, nightly=True, modular=self.modular) @property @@ -387,6 +387,6 @@ class NightlyEvent(ValidationEvent): @property def _pagetype(self): """For a NightlyEvent, obviously, NightlyPage.""" - return page.NightlyPage + return wikitcms.page.NightlyPage # vim: set textwidth=100 ts=8 et sw=4: diff --git a/src/wikitcms/listing.py b/src/wikitcms/listing.py index d8775c1..87fd3bf 100644 --- a/src/wikitcms/listing.py +++ b/src/wikitcms/listing.py @@ -26,9 +26,9 @@ otherwise. import re -from mwclient import listing as mwl +import mwclient.listing -from . import page as pg +import wikitcms.page # exceptions: the wikitcms getter raises these when it fails rather than # just returning None, so the generators can use try/except blocks to @@ -70,7 +70,7 @@ def _check_page(name, page): raise PageCheckWarning(page.checkname, name) -class TcmsGeneratorList(mwl.GeneratorList): +class TcmsGeneratorList(mwclient.listing.GeneratorList): """A GeneratorList which returns wikitcms page (and category etc.) instances when appropriate. _get_tcms is implemented as a separate function so TcmsPageList can use the discovery logic. @@ -120,7 +120,7 @@ class TcmsGeneratorList(mwl.GeneratorList): modular = False if match.group(1): modular = True - page = pg.NightlyPage( + page = wikitcms.page.NightlyPage( self.site, release=match.group(2), testtype=match.group(6), milestone=match.group(3), compose=match.group(4), info=info, modular=modular) @@ -139,7 +139,7 @@ class TcmsGeneratorList(mwl.GeneratorList): modular = False if match.group(1): modular = True - page = pg.ComposePage( + page = wikitcms.page.ComposePage( self.site, release=match.group(2), testtype=match.group(5), milestone=match.group(3), compose=match.group(4), info=info, modular=modular) @@ -196,8 +196,7 @@ class TcmsGeneratorList(mwl.GeneratorList): match = testday_patt.match(name) if match: - page = pg.TestDayPage(self.site, match.group(1), - match.group(2), info=info) + page = wikitcms.page.TestDayPage(self.site, match.group(1), match.group(2), info=info) return _check_page(name, page) # in case we matched nothing... @@ -218,7 +217,7 @@ class TcmsGeneratorList(mwl.GeneratorList): if isinstance(name, int): # we'll have to do a wiki roundtrip, as we need the text # name. - page = pg.Page(self.site, name) + page = wikitcms.page.Page(self.site, name) name = page.name name = name.replace('_', ' ') # quick non-RE checks to see if we'll ever match (and filter @@ -235,7 +234,7 @@ class TcmsGeneratorList(mwl.GeneratorList): raise NoPageWarning(name) -class TcmsPageList(mwl.PageList, TcmsGeneratorList): +class TcmsPageList(mwclient.listing.PageList, TcmsGeneratorList): """A version of PageList which returns wikitcms page (and category etc.) objects when appropriate. """ @@ -249,7 +248,7 @@ class TcmsPageList(mwl.PageList, TcmsGeneratorList): return super(TcmsPageList, self).get(name, info) -class TcmsCategory(pg.Page, TcmsGeneratorList): +class TcmsCategory(wikitcms.page.Page, TcmsGeneratorList): """A modified category class - just as mwclient's Category class inherits from both its Page class and its GeneratorList class, acting as both a page and a generator returning the members of diff --git a/src/wikitcms/page.py b/src/wikitcms/page.py index 5e7cc01..245dade 100644 --- a/src/wikitcms/page.py +++ b/src/wikitcms/page.py @@ -22,22 +22,22 @@ in, and attributes of pages like test results and test cases, are defined in this file. """ +from collections import OrderedDict import datetime import logging import re import time -from collections import OrderedDict +from cached_property import cached_property import fedfind.helpers import fedfind.release -from cached_property import cached_property from mwclient import errors as mwe from mwclient import page as mwp import pytz -from . import result as rs -from . import helpers -from .exceptions import NoPageError, NotFoundError, TooManyError +from wikitcms.exceptions import NoPageError, NotFoundError, TooManyError +import wikitcms.helpers +import wikitcms.result logger = logging.getLogger(__name__) @@ -189,9 +189,9 @@ class ValidationPage(Page): " No testing is required.") # Sorting helpers. sortname is a string, sorttuple is a # 4-tuple. sorttuple is more reliable. See the function docs. - self.sortname = helpers.fedora_release_sort( + self.sortname = wikitcms.helpers.fedora_release_sort( ' '.join((self.version, self.testtype))) - self.sorttuple = helpers.triplet_sort( + self.sorttuple = wikitcms.helpers.triplet_sort( self.release, self.milestone, self.compose) + (self.testtype,) @property @@ -239,8 +239,8 @@ class ValidationPage(Page): sectext = pagetext[sec['byteoffset']:] # strip comments sectext = comment.sub('', sectext) - newrows = rs.find_resultrows(sectext, section, secid, statuses, - transferred) + newrows = wikitcms.result.find_resultrows(sectext, section, secid, statuses, + transferred) rows.extend(newrows) return rows @@ -257,7 +257,7 @@ class ValidationPage(Page): raise NoPageError("Page does not exist or has no result rows.") # Find the right row - nrml = helpers.normalize + nrml = wikitcms.helpers.normalize rows = [r for r in rows if nrml(testcase) in nrml(r.testcase) or nrml(testcase) in nrml(r.name)] @@ -315,7 +315,7 @@ class ValidationPage(Page): resultsdict = OrderedDict(sorted(resultsdict.items(), key=lambda x: int(x[0].secid), reverse=True)) - nonetext = rs.Result().result_template + nonetext = wikitcms.result.Result().result_template dupes = list() # this tracks rows that we don't wind up touching, so they # can be left out of the summary text @@ -714,8 +714,8 @@ class TestDayPage(Page): """Returns a list of bug IDs referenced in the results section (as strings). Will find bugs in {{result}} and {{bz}} templates.""" - bugs = helpers.find_bugs(self.results_wikitext) - for res in rs.find_results_by_row(self.results_wikitext): + bugs = wikitcms.helpers.find_bugs(self.results_wikitext) + for res in wikitcms.result.find_results_by_row(self.results_wikitext): bugs.update(res.bugs) return sorted(bugs) @@ -774,7 +774,7 @@ class TestDayPage(Page): text = text.replace(match.group(0), '' + match.group(1)) if found: - text = helpers.rreplace( + text = wikitcms.helpers.rreplace( text.strip(), '\n\n', '\n\n== Long comments ==\n\n\n', 1) return self.save(text, summary=u"Move long comments to a separate " diff --git a/src/wikitcms/release.py b/src/wikitcms/release.py index 436e424..46f59df 100644 --- a/src/wikitcms/release.py +++ b/src/wikitcms/release.py @@ -19,8 +19,8 @@ """Classes that describe distribution releases are defined here.""" -from . import page as pg -from . import listing as li +import wikitcms.page +import wikitcms.listing class Release(): """Class for a Fedora release. wiki is a wikitcms site object. @@ -39,7 +39,7 @@ class Release(): def testday_pages(self): """All Test Day pages for this release (as a list).""" cat = self.site.pages[f"Category:Fedora {self.release} Test Days"] - return [page for page in cat if isinstance(page, pg.TestDayPage)] + return [page for page in cat if isinstance(page, wikitcms.page.TestDayPage)] def milestone_pages(self, milestone=None): """If no milestone, will give all release validation pages for @@ -48,8 +48,9 @@ class Release(): works by category; you may get somewhat different results by using page name prefixes. """ - cat = li.ValidationCategory(self.site, self.release, milestone, modular=self.modular) + cat = wikitcms.listing.ValidationCategory(self.site, self.release, milestone, + modular=self.modular) pgs = self.site.walk_category(cat) - return (p for p in pgs if isinstance(p, pg.ValidationPage)) + return (p for p in pgs if isinstance(p, wikitcms.page.ValidationPage)) # vim: set textwidth=100 ts=8 et sw=4: diff --git a/src/wikitcms/result.py b/src/wikitcms/result.py index 2e3bb40..bb7e198 100644 --- a/src/wikitcms/result.py +++ b/src/wikitcms/result.py @@ -20,11 +20,10 @@ """This file defines various classes and helper functions for working with results.""" -import re - from collections import OrderedDict +import re -from wikitcms import helpers +import wikitcms.helpers # These are used by multiple functions, so let's share them. # Wiki table row separator @@ -207,7 +206,7 @@ class Result(): self.comment = comment self.bot = bot self.transferred = False - self.comment_bugs = helpers.find_bugs(self.comment) + self.comment_bugs = wikitcms.helpers.find_bugs(self.comment) self.origtext = origtext def __str__(self): diff --git a/src/wikitcms/wiki.py b/src/wikitcms/wiki.py index a2ed49f..d020c47 100644 --- a/src/wikitcms/wiki.py +++ b/src/wikitcms/wiki.py @@ -30,12 +30,12 @@ import fedfind.helpers import mwclient from productmd.composeinfo import get_date_type_respin -from . import page as pg -from . import event as ev -from . import helpers as hl -from . import listing as li -from . import result as rs -from .exceptions import NoPageError, NotFoundError, TooManyError +import wikitcms.event +from wikitcms.exceptions import NoPageError, NotFoundError, TooManyError +import wikitcms.helpers +import wikitcms.listing +import wikitcms.page +import wikitcms.result try: from openidc_client import OpenIDCClient @@ -112,7 +112,7 @@ class Wiki(mwclient.Site): super(Wiki, self).__init__(host, *args, **kwargs) # override the 'pages' property so it returns wikitcms Pages when # appropriate - self.pages = li.TcmsPageList(self) + self.pages = wikitcms.listing.TcmsPageList(self) @property def current_compose(self): @@ -288,8 +288,8 @@ class Wiki(mwclient.Site): appropriate. Note, if passing prefix, start or end, leave out the "Test Results:" part of the name. """ - gen = li.TcmsPageList(self, prefix=prefix, start=start, - namespace=116, redirects=redirects, end=end) + gen = wikitcms.listing.TcmsPageList(self, prefix=prefix, start=start, + namespace=116, redirects=redirects, end=end) return gen def alltestdays(self, prefix=None, start=None, redirects='all', end=None): @@ -299,8 +299,8 @@ class Wiki(mwclient.Site): appropriate. Note, if passing prefix, start or end, leave out the "Test Day:" part of the name. """ - gen = li.TcmsPageList(self, prefix=prefix, start=start, - namespace=114, redirects=redirects, end=end) + gen = wikitcms.listing.TcmsPageList(self, prefix=prefix, start=start, + namespace=114, redirects=redirects, end=end) return gen def get_validation_event(self, release='', milestone='', compose='', @@ -351,7 +351,7 @@ class Wiki(mwclient.Site): method with sufficient information to avoid guessing. """ if cid: - (dist, release, milestone, compose) = hl.cid_to_event(cid) + (dist, release, milestone, compose) = wikitcms.helpers.cid_to_event(cid) modular = bool(dist == 'Fedora-Modular') if not compose or not release: # Can't really make an educated guess without a compose @@ -376,8 +376,8 @@ class Wiki(mwclient.Site): if _check_compose(compose) == 'date': if milestone: - return ev.NightlyEvent(self, release=release, milestone=milestone, - compose=compose, modular=modular) + return wikitcms.event.NightlyEvent(self, release=release, milestone=milestone, + compose=compose, modular=modular) # we have a date and no milestone. Try both and return # whichever exists. We check whether the first result @@ -385,11 +385,11 @@ class Wiki(mwclient.Site): # creates the wrong event, we can clean up by blanking # the pages, rather than by getting an admin to # actually *delete* them. - rawev = ev.NightlyEvent(self, release, 'Rawhide', compose, modular=modular) + rawev = wikitcms.event.NightlyEvent(self, release, 'Rawhide', compose, modular=modular) pgs = rawev.result_pages if pgs and pgs[0].text(): return rawev - brev = ev.NightlyEvent(self, release, 'Branched', compose, modular=modular) + brev = wikitcms.event.NightlyEvent(self, release, 'Branched', compose, modular=modular) pgs = brev.result_pages if pgs and pgs[0].text(): return brev @@ -409,7 +409,8 @@ class Wiki(mwclient.Site): # be nice and convert it if int(release) > 23 and milestone.lower() == 'final': milestone = 'RC' - return ev.ComposeEvent(self, release, milestone, compose, modular=modular, cid=cid) + return wikitcms.event.ComposeEvent(self, release, milestone, compose, modular=modular, + cid=cid) # We should never get here, but just in case. raise ValueError("get_validation_event(): Something very strange happened.") @@ -463,7 +464,7 @@ class Wiki(mwclient.Site): method with sufficient information to avoid guessing. """ if cid: - (dist, release, milestone, compose) = hl.cid_to_event(cid) + (dist, release, milestone, compose) = wikitcms.helpers.cid_to_event(cid) modular = bool(dist == 'Fedora-Modular') if not compose or not release: # Can't really make an educated guess without a compose @@ -487,15 +488,16 @@ class Wiki(mwclient.Site): if _check_compose(compose) == 'date': if milestone: - return pg.NightlyPage(self, release, testtype, milestone, compose, modular=modular) + return wikitcms.page.NightlyPage(self, release, testtype, milestone, compose, + modular=modular) # date, but no milestone - rawpg = pg.NightlyPage( - self, release, testtype, 'Rawhide', compose, modular=modular) + rawpg = wikitcms.page.NightlyPage(self, release, testtype, 'Rawhide', compose, + modular=modular) if rawpg.exists: return rawpg - brpg = pg.NightlyPage( - self, release, testtype, 'Branched', compose, modular=modular) + brpg = wikitcms.page.NightlyPage(self, release, testtype, 'Branched', compose, + modular=modular) if brpg.exists: return brpg # Here, we failed to guess. Boohoo. @@ -513,8 +515,8 @@ class Wiki(mwclient.Site): # be nice and convert it if int(release) > 23 and milestone.lower() == 'final': milestone = 'RC' - return pg.ComposePage( - self, release, testtype, milestone, compose, modular=modular) + return wikitcms.page.ComposePage(self, release, testtype, milestone, compose, + modular=modular) # We should never get here, but just in case. raise ValueError( @@ -650,9 +652,8 @@ class Wiki(mwclient.Site): myrow = page.find_resultrow( restup.testcase, restup.section, restup.testname, restup.env) - myres = rs.Result( - restup.status, user, restup.bugs, - restup.comment, restup.bot) + myres = wikitcms.result.Result(restup.status, user, restup.bugs, restup.comment, + restup.bot) except (NoPageError, NotFoundError, TooManyError): # We couldn't find precisely one result row from the # provided information.