import grp
import pwd


def get_groups_for_user(username):
	"""
	Get the groups that a user is a member of.

	:param str username: The user to lookup group membership for.
	:rtype: set
	:return: The names of the groups that the user is a member of.
	"""
	groups = set(g.gr_name for g in grp.getgrall() if username in g.gr_mem)
	groups.add(grp.getgrgid(pwd.getpwnam(username).pw_gid).gr_name)
	return groups