Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more comprehensive auto-formatting tools for Python and C #384

Merged
merged 8 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis/fedora/Dockerfile.deps.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ FROM @IMAGE@
MAINTAINER Stephen Gallagher <sgallagh@redhat.com>

RUN dnf -y --setopt=install_weak_deps=False --setopt=tsflags='' install \
python3-black \
clang \
clang-analyzer \
clang-tools-extra \
createrepo_c \
"libmodulemd >= 2.3" \
curl \
Expand Down
2 changes: 1 addition & 1 deletion .travis/mageia/travis-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
set -x


COMMON_MESON_ARGS="-Dtest_dirty_git=${DIRTY_REPO_CHECK:-true}"
COMMON_MESON_ARGS="-Dtest_dirty_git=${DIRTY_REPO_CHECK:-true} -Ddeveloper_build=false"


pushd /builddir/
Expand Down
28 changes: 25 additions & 3 deletions .travis/travis-common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ MMD_OS=
MMD_RELEASE=
MMD_TARBALL_PATH=

BUILDAH_PATH=$(which buildah)

DOCKER_PATH=$(which docker)

if [ x$BUILDAH_PATH == x ]; then
if [ x$DOCKER_PATH == x ]; then
>&2 echo "error: Neither docker nor podman available"
exit 1
else
MMD_BUILDAH="sudo $DOCKER_PATH build"
fi
else
MMD_BUILDAH="$BUILDAH_PATH bud"
fi

PODMAN_PATH=$(which podman)
if [ x$PODMAN_PATH == x ]; then
MMD_OCI="sudo $DOCKER_PATH"
else
MMD_OCI="$PODMAN_PATH"
fi

function common_finalize {
# If any specific test launcher needs to do its own cleanup as well,
# it should set the EXIT trap and make sure to also call this functino
Expand Down Expand Up @@ -55,16 +77,16 @@ function mmd_run_docker_tests {
$SCRIPT_DIR/$MMD_OS/Dockerfile.deps.tmpl > $SCRIPT_DIR/$MMD_OS/Dockerfile.deps.$MMD_RELEASE
sed -e "s/@RELEASE@/$MMD_OS:$MMD_RELEASE/" $SCRIPT_DIR/$MMD_OS/Dockerfile.tmpl > $SCRIPT_DIR/$MMD_OS/Dockerfile-$MMD_RELEASE

sudo docker build \
$MMD_BUILDAH \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on travis failure, is sudo still needed here and below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sudo is needed for docker but not podman. I'll fix that up. Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though that failure is actually different; I was relying on /dev/zero not having the executable flag, but apparently on Ubuntu (where the tests are kicked off), it does... 🤦‍♂️

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that was wrong. I was just missing a variable. I think I will still try to find a less "clever" way of doing this, though.

-f $SCRIPT_DIR/$MMD_OS/Dockerfile.deps.$MMD_RELEASE \
-t fedora-modularity/libmodulemd-deps-$MMD_OS:$MMD_RELEASE .

sudo docker build \
$MMD_BUILDAH \
-f $SCRIPT_DIR/$MMD_OS/Dockerfile-$MMD_RELEASE \
-t fedora-modularity/libmodulemd-$MMD_OS:$MMD_RELEASE \
--build-arg TARBALL=${TARBALL} .

docker run --rm fedora-modularity/libmodulemd-$MMD_OS:$MMD_RELEASE
$MMD_OCI run --rm fedora-modularity/libmodulemd-$MMD_OS:$MMD_RELEASE

popd

Expand Down
58 changes: 25 additions & 33 deletions bindings/python/gi/overrides/Modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@

import datetime

Modulemd = get_introspection_module('Modulemd')
Modulemd = get_introspection_module("Modulemd")


__all__ = []


class ModulemdUtil(object):

@staticmethod
def variant_str(s):
""" Converts a string to a GLib.Variant
"""
if not isinstance(s, str):
raise TypeError('Only strings are supported for scalars')
raise TypeError("Only strings are supported for scalars")

return GLib.Variant.new_string(s)

Expand All @@ -55,7 +54,7 @@ def variant_bool(b):
""" Converts a boolean to a GLib.Varant
"""
if not isinstance(b, bool):
raise TypeError('Only booleans are supported')
raise TypeError("Only booleans are supported")

return GLib.Variant.new_boolean(b)

Expand All @@ -65,14 +64,14 @@ def variant_list(l):
"""

# If this is a zero-length array, handle it specially
if (len(l) == 0):
return GLib.Variant.new_array(GLib.VariantType('v'))
if len(l) == 0:
return GLib.Variant.new_array(GLib.VariantType("v"))

# Build the array from each entry
builder = GLib.VariantBuilder(GLib.VariantType('a*'))
builder = GLib.VariantBuilder(GLib.VariantType("a*"))
for item in l:
if item is None:
item = ''
item = ""
builder.add_value(ModulemdUtil.python_to_variant(item))

return builder.end()
Expand All @@ -82,13 +81,13 @@ def variant_dict(d):
""" Converts a dictionary to a dictionary of GLib.Variant
"""
if not isinstance(d, dict):
raise TypeError('Only dictionaries are supported for mappings')
raise TypeError("Only dictionaries are supported for mappings")

vdict = GLib.VariantDict()

for k, v in d.items():
if v is None:
v = ''
v = ""
vdict.insert_value(k, ModulemdUtil.python_to_variant(v))

return vdict.end()
Expand All @@ -100,7 +99,7 @@ def python_to_variant(obj):
return ModulemdUtil.variant_str(obj)

elif isinstance(obj, text_type):
return ModulemdUtil.variant_str(obj.encode('utf-8'))
return ModulemdUtil.variant_str(obj.encode("utf-8"))

elif isinstance(obj, bool):
return ModulemdUtil.variant_bool(obj)
Expand All @@ -112,17 +111,16 @@ def python_to_variant(obj):
return ModulemdUtil.variant_dict(obj)

else:
raise TypeError('Cannot convert unknown type')
raise TypeError("Cannot convert unknown type")


if float(Modulemd._version) >= 2:

class ModuleStreamV2(Modulemd.ModuleStreamV2):

def set_xmd(self, xmd):
super(
ModuleStreamV2, self).set_xmd(
ModulemdUtil.python_to_variant(xmd))
super(ModuleStreamV2, self).set_xmd(
ModulemdUtil.python_to_variant(xmd)
)

def get_xmd(self):
variant_xmd = super(ModuleStreamV2, self).get_xmd()
Expand All @@ -134,11 +132,10 @@ def get_xmd(self):
__all__.append(ModuleStreamV2)

class ModuleStreamV1(Modulemd.ModuleStreamV1):

def set_xmd(self, xmd):
super(
ModuleStreamV1, self).set_xmd(
ModulemdUtil.python_to_variant(xmd))
super(ModuleStreamV1, self).set_xmd(
ModulemdUtil.python_to_variant(xmd)
)

def get_xmd(self):
variant_xmd = super(ModuleStreamV1, self).get_xmd()
Expand All @@ -150,29 +147,24 @@ def get_xmd(self):
__all__.append(ModuleStreamV1)

class ServiceLevel(Modulemd.ServiceLevel):

def set_eol(self, eol):
if (isinstance(eol, datetime.date)):
return super(
ServiceLevel,
self).set_eol_ymd(
eol.year,
eol.month,
eol.day)
if isinstance(eol, datetime.date):
return super(ServiceLevel, self).set_eol_ymd(
eol.year, eol.month, eol.day
)

raise TypeError(
"Expected datetime.date, but got %s." % (
type(eol).__name__))
"Expected datetime.date, but got %s." % (type(eol).__name__)
)

def get_eol(self):
eol = super(ServiceLevel, self).get_eol()
if eol is None:
return None

return datetime.date(
eol.get_year(),
eol.get_month(),
eol.get_day())
eol.get_year(), eol.get_month(), eol.get_day()
)

ServiceLevel = override(ServiceLevel)
__all__.append(ServiceLevel)
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test_cflags = [
'-Werror=return-type',
'-Werror=array-bounds',
'-Werror=write-strings',
'-D_POSIX_SOURCE',
'-D_GNU_SOURCE',
'-DG_LOG_USE_STRUCTURED',
'-DG_LOG_DOMAIN="libmodulemd"',
]
Expand Down
4 changes: 4 additions & 0 deletions modulemd/clang_simple_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/sh

$1 --version | awk '/LLVM version/ {print $NF}' -

2 changes: 1 addition & 1 deletion modulemd/include/modulemd-2.0/modulemd-component-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib-object.h>
#include "modulemd-component.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
2 changes: 1 addition & 1 deletion modulemd/include/modulemd-2.0/modulemd-component-rpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib-object.h>
#include "modulemd-component.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
2 changes: 1 addition & 1 deletion modulemd/include/modulemd-2.0/modulemd-defaults-v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib-object.h>
#include "modulemd-defaults.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib-object.h>
#include "modulemd-module-index.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
4 changes: 2 additions & 2 deletions modulemd/include/modulemd-2.0/modulemd-module-index.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

#pragma once

#include <glib-object.h>
#include "modulemd-module.h"
#include "modulemd-translation.h"
#include "modulemd-subdocument-info.h"
#include "modulemd-translation.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
4 changes: 2 additions & 2 deletions modulemd/include/modulemd-2.0/modulemd-module-stream-v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

#pragma once

#include <glib-object.h>
#include "modulemd-buildopts.h"
#include "modulemd-component.h"
#include "modulemd-component-module.h"
#include "modulemd-component-rpm.h"
#include "modulemd-component.h"
#include "modulemd-deprecated.h"
#include "modulemd-module-stream.h"
#include "modulemd-profile.h"
#include "modulemd-service-level.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
4 changes: 2 additions & 2 deletions modulemd/include/modulemd-2.0/modulemd-module-stream-v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

#pragma once

#include <glib-object.h>
#include "modulemd-buildopts.h"
#include "modulemd-component.h"
#include "modulemd-component-module.h"
#include "modulemd-component-rpm.h"
#include "modulemd-component.h"
#include "modulemd-dependencies.h"
#include "modulemd-module-stream.h"
#include "modulemd-profile.h"
#include "modulemd-rpm-map-entry.h"
#include "modulemd-service-level.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down
2 changes: 1 addition & 1 deletion modulemd/include/modulemd-2.0/modulemd-module-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib.h>
#include <glib-object.h>
#include <glib.h>
#include <glib/gstdio.h>

#include "modulemd-deprecated.h"
Expand Down
10 changes: 5 additions & 5 deletions modulemd/include/modulemd-2.0/modulemd-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

#pragma once

#include <glib-object.h>
#include "modulemd-defaults.h"
#include "modulemd-deprecated.h"
#include "modulemd-module-stream.h"
#include "modulemd-translation.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down Expand Up @@ -131,7 +131,7 @@ MMD_DEPRECATED_FOR (modulemd_module_get_stream_by_NSVCA)
ModulemdModuleStream *
modulemd_module_get_stream_by_NSVC (ModulemdModule *self,
const gchar *stream_name,
const guint64 version,
guint64 version,
const gchar *context);


Expand All @@ -158,7 +158,7 @@ modulemd_module_get_stream_by_NSVC (ModulemdModule *self,
GPtrArray *
modulemd_module_search_streams (ModulemdModule *self,
const gchar *stream_name,
const guint64 version,
guint64 version,
const gchar *context,
const gchar *arch);

Expand All @@ -185,7 +185,7 @@ modulemd_module_search_streams (ModulemdModule *self,
ModulemdModuleStream *
modulemd_module_get_stream_by_NSVCA (ModulemdModule *self,
const gchar *stream_name,
const guint64 version,
guint64 version,
const gchar *context,
const gchar *arch,
GError **error);
Expand All @@ -210,7 +210,7 @@ modulemd_module_get_stream_by_NSVCA (ModulemdModule *self,
void
modulemd_module_remove_streams_by_NSVCA (ModulemdModule *self,
const gchar *stream_name,
const guint64 version,
guint64 version,
const gchar *context,
const gchar *arch);

Expand Down
2 changes: 1 addition & 1 deletion modulemd/include/modulemd-2.0/modulemd-translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#pragma once

#include <glib-object.h>
#include "modulemd-translation-entry.h"
#include <glib-object.h>

G_BEGIN_DECLS

Expand Down