Skip to content

Commit

Permalink
pylint multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
lmilbaum authored and Zlopez committed Jun 20, 2023
1 parent 159602e commit b4d82a4
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
from alembic import op

# revision identifiers, used by Alembic.
revision = "136d119ab015"
down_revision = "92a2e9eba0a7"
revision = "136d119ab015" # pylint: disable=C0103
down_revision = "92a2e9eba0a7" # pylint: disable=C0103


def upgrade():
"""Upgrade"""
with op.batch_alter_table("projects") as batch_op:
batch_op.alter_column(
"latest_known_cursor", new_column_name="latest_version_cursor"
)


def downgrade():
"""Downgrade"""
with op.batch_alter_table("projects") as batch_op:
batch_op.alter_column(
"latest_version_cursor", new_column_name="latest_known_cursor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@


def upgrade():
"""Upgrade"""
op.add_column(
"projects_versions",
sa.Column("commit_url", sa.String(length=200), nullable=True),
)


def downgrade():
"""Downgrade"""
with op.batch_alter_table("projects_versions") as batch_op:
batch_op.drop_column("commit_url")
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
down_revision = "feeaa70ead67"


class GUID(TypeDecorator):
class GUID(TypeDecorator): # pylint: disable=W0223
"""
Platform-independent GUID type.
Expand Down Expand Up @@ -79,10 +79,10 @@ def process_bind_param(self, value, dialect):
return str(value)
else:
if not isinstance(value, uuid.UUID):
return "%.32x" % uuid.UUID(value).int
return f"{uuid.UUID(value).int:032x}"
else:
# hexstring
return "%.32x" % value.int
return f"{value.int:032x}"

def process_result_value(self, value, dialect):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def upgrade():
"""Upgrade"""
op.add_column(
"projects", sa.Column("ecosystem_name", sa.String(length=200), nullable=True)
)
Expand All @@ -33,6 +34,7 @@ def upgrade():


def downgrade():
"""Downgrade"""
op.drop_constraint("FK_ECOSYSTEM_FOR_PROJECT", "projects", type_="foreignkey")
op.drop_constraint("UNIQ_PROJECT_NAME_PER_ECOSYSTEM", "projects", type_="unique")
op.drop_column("projects", "ecosystem_name")
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@


def upgrade():
"""Upgrade"""
op.add_column(
"projects",
sa.Column("latest_known_cursor", sa.String(length=200), nullable=True),
)


def downgrade():
"""Downgrade"""
with op.batch_alter_table("projects") as batch_op:
batch_op.drop_column("latest_known_cursor")
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


def upgrade():
"""Upgrade"""
# We use a subquery instead of an UPDATE FROM with a table join
# due to the fact that SQLite doesn't allow joins in update statements
op.execute(
Expand All @@ -32,6 +33,7 @@ def upgrade():


def downgrade():
"""Downgrade"""
# Do nothing on downgrade - column removal will be handled by previous
# revision
pass
6 changes: 3 additions & 3 deletions anitya/db/migrations/versions/a52d2fe99d4f_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
down_revision = "8040ef9a9dda"


class GUID(TypeDecorator):
class GUID(TypeDecorator): # pylint: disable=W0223
"""
Platform-independent GUID type.
Expand Down Expand Up @@ -62,10 +62,10 @@ def process_bind_param(self, value, dialect):
return str(value)
else:
if not isinstance(value, uuid.UUID):
return "%.32x" % uuid.UUID(value).int
return f"{uuid.UUID(value).int:032x}"
else:
# hexstring
return "%.32x" % value.int
return f"{value.int:032x}"

def process_result_value(self, value, dialect):
"""
Expand Down
2 changes: 2 additions & 0 deletions anitya/db/migrations/versions/ac10bf3f974c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@


def upgrade():
"""Upgrade"""
pass


def downgrade():
"""Downgrade"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def downgrade():
# We have to populate the backends table before we can add the ecosystems
# table with its foreign key constraint.
for backend in plugins.BACKEND_PLUGINS.get_plugins():
op.execute("INSERT INTO backends (name) VALUES ('{}');".format(backend.name))
op.execute(f"INSERT INTO backends (name) VALUES ('{backend.name}');")

op.create_table(
"ecosystems",
Expand All @@ -65,11 +65,9 @@ def downgrade():
)
for ecosystem in plugins.ECOSYSTEM_PLUGINS.get_plugins():
op.execute(
"""
f"""
INSERT INTO ecosystems (name, default_backend_name)
VALUES ('{name}', '{default}');""".format(
name=ecosystem.name, default=ecosystem.default_backend
)
VALUES ('{ecosystem.name}', '{ecosystem.default_backend}');"""
)

op.create_foreign_key(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
down_revision = "a52d2fe99d4f"


class GUID(TypeDecorator):
class GUID(TypeDecorator): # pylint: disable=W0223
"""
Platform-independent GUID type.
Expand Down Expand Up @@ -80,10 +80,10 @@ def process_bind_param(self, value, dialect):
return str(value)
else:
if not isinstance(value, uuid.UUID):
return "%.32x" % uuid.UUID(value).int
return f"{uuid.UUID(value).int:032x}"
else:
# hexstring
return "%.32x" % value.int
return f"{value.int:032x}"

def process_result_value(self, value, dialect):
"""
Expand Down
12 changes: 6 additions & 6 deletions anitya/lib/backends/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_version_url(cls, project):
Returns:
str: url used for version checking
"""
url = "https://metacpan.org/release/%(name)s/" % {"name": project.name}
url = f"https://metacpan.org/release/{project.name}/"

return url

Expand Down Expand Up @@ -80,19 +80,19 @@ def check_feed(cls):

try:
response = cls.call_url(url)
except Exception: # pragma: no cover
raise AnityaPluginException("Could not contact %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"Could not contact {url}") from exc

try:
root = ET.fromstring(response.text)
except ET.ParseError:
raise AnityaPluginException("No XML returned by %s" % url)
except ET.ParseError as exc:
raise AnityaPluginException(f"No XML returned by {url}") from exc

for item in root.iter(tag="{http://purl.org/rss/1.0/}item"):
title = item.find("{http://purl.org/rss/1.0/}title")
try:
name, version = title.text.rsplit("-", 1)
except ValueError:
_log.info("Unable to parse CPAN package %s into a name and version")
homepage = "https://metacpan.org/release/%s/" % name
homepage = f"https://metacpan.org/release/{name}/"
yield name, homepage, cls.name, version
26 changes: 23 additions & 3 deletions anitya/lib/backends/drupal6.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def get_version_url(cls, project):
if "-" in project.name:
name = project.name.replace("-", "_")

url_template = "https://updates.drupal.org/release-history/" "%(name)s/6.x"

url = url_template % {"name": name}
url = f"https://updates.drupal.org/release-history/{name}/6.x"

return url

Expand Down Expand Up @@ -84,3 +82,25 @@ def get_versions(cls, project):
raise err

return versions

@classmethod
def check_feed(cls): # pragma: no cover
"""Method called to retrieve the latest uploads to a given backend,
via, for example, RSS or an API.
Not all backends may support this. It can be used to look for updates
much more quickly than scanning all known projects.
Returns:
:obj:`list`: A list of 4-tuples, containing the project name, homepage, the
backend, and the version.
Raises:
AnityaPluginException: A
:obj:`anitya.lib.exceptions.AnityaPluginException` exception
when the versions cannot be retrieved correctly
NotImplementedError: If backend does not
support batch updates.
"""
raise NotImplementedError()
34 changes: 28 additions & 6 deletions anitya/lib/backends/packagist.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ def get_versions(cls, project):
url = cls.get_version_url(project)
if not url:
raise AnityaPluginException(
"Project {} is not correctly set up.".format(project.name)
f"Project {project.name} is not correctly set up."
)

last_change = project.get_time_last_created_version()
try:
req = cls.call_url(url, last_change=last_change)
except Exception: # pragma: no cover
raise AnityaPluginException("Could not contact %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"Could not contact {url}") from exc

# Not modified
if req.status_code == 304:
return []

try:
data = req.json()
except Exception: # pragma: no cover
raise AnityaPluginException("No JSON returned by %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"No JSON returned by {url}") from exc

if "package" in data and "versions" in data["package"]:
# Filter retrieved versions
Expand All @@ -94,4 +94,26 @@ def get_versions(cls, project):
elif "status" in data and data["status"] == "error" and "message" in data:
raise AnityaPluginException(data["message"])
else:
raise AnityaPluginException("Invalid JSON returned by %s" % url)
raise AnityaPluginException(f"Invalid JSON returned by {url}")

@classmethod
def check_feed(cls): # pragma: no cover
"""Method called to retrieve the latest uploads to a given backend,
via, for example, RSS or an API.
Not all backends may support this. It can be used to look for updates
much more quickly than scanning all known projects.
Returns:
:obj:`list`: A list of 4-tuples, containing the project name, homepage, the
backend, and the version.
Raises:
AnityaPluginException: A
:obj:`anitya.lib.exceptions.AnityaPluginException` exception
when the versions cannot be retrieved correctly
NotImplementedError: If backend does not
support batch updates.
"""
raise NotImplementedError()
18 changes: 8 additions & 10 deletions anitya/lib/backends/pecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def _get_versions(url):
"""Retrieve the versions for the provided url."""
try:
req = PeclBackend.call_url(url)
except Exception: # pragma: no cover
raise AnityaPluginException("Could not contact %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"Could not contact {url}") from exc

data = req.text
versions = []
Expand Down Expand Up @@ -101,9 +101,7 @@ def get_versions(cls, project):
versions = _get_versions(url)

if not versions:
raise AnityaPluginException(
"No versions found for %s" % project.name.lower()
)
raise AnityaPluginException(f"No versions found for {project.name.lower()}")

# Filter retrieved versions
filtered_versions = BaseBackend.filter_versions(
Expand All @@ -122,18 +120,18 @@ def check_feed(cls):

try:
response = cls.call_url(url)
except Exception: # pragma: no cover
raise AnityaPluginException("Could not contact %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"Could not contact {url}") from exc

try:
parser = xml2dict.XML2Dict()
data = parser.fromstring(response.text)
except Exception: # pragma: no cover
raise AnityaPluginException("No XML returned by %s" % url)
except Exception as exc: # pragma: no cover
raise AnityaPluginException(f"No XML returned by {url}") from exc

items = data["RDF"]["item"]
for entry in items:
title = entry["title"]["value"]
name, version = title.rsplit(None, 1)
homepage = "https://pecl.php.net/package/%s" % name
homepage = f"https://pecl.php.net/package/{name}"
yield name, homepage, cls.name, version
22 changes: 22 additions & 0 deletions anitya/lib/backends/sourceforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ def get_versions(cls, project):
regex = REGEX % {"name": project.name.replace("+", r"\+")}

return get_versions_by_regex(url, regex, project)

@classmethod
def check_feed(cls): # pragma: no cover
"""Method called to retrieve the latest uploads to a given backend,
via, for example, RSS or an API.
Not all backends may support this. It can be used to look for updates
much more quickly than scanning all known projects.
Returns:
:obj:`list`: A list of 4-tuples, containing the project name, homepage, the
backend, and the version.
Raises:
AnityaPluginException: A
:obj:`anitya.lib.exceptions.AnityaPluginException` exception
when the versions cannot be retrieved correctly
NotImplementedError: If backend does not
support batch updates.
"""
raise NotImplementedError()
2 changes: 1 addition & 1 deletion anitya/tests/lib/backends/test_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FolderBackendtests(DatabaseTestCase):

def setUp(self):
"""Set up the environnment, ran before every tests."""
super(FolderBackendtests, self).setUp()
super().setUp()

create_distro(self.session)

Expand Down
Loading

0 comments on commit b4d82a4

Please sign in to comment.