These are chat archives for coala/coala-bears

12th
Sep 2016
Fabian Neuschmidt
@fneu
Sep 12 2016 12:20 UTC
@Adrianzatreanu @sils1297 can we talk about Requirements?
I guess cib uses them to install stuff, and coala uses them to check whether a bear can be run safely, right?
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:21 UTC
all i know is cib uses them to install the stuff or check if the stuff is installed or not
i dont know how coala uses them :D
Fabian Neuschmidt
@fneu
Sep 12 2016 12:22 UTC
they are pretty weird
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:22 UTC
what do you mean?
Fabian Neuschmidt
@fneu
Sep 12 2016 12:22 UTC
like they all subclass PackageRequirement
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:22 UTC
correct
Fabian Neuschmidt
@fneu
Sep 12 2016 12:22 UTC
but like DistributionRequirement.__init__() never calls super.__init__()
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:23 UTC
yeah thats the case only for distributionrequirement
i guess it shouldnt inherit from PackageRequirement
thats because we dont know the manager always for it
it can be apt, it can be dnf..
Fabian Neuschmidt
@fneu
Sep 12 2016 12:23 UTC
and PackageRequirement has a function __check__()
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:23 UTC
whereas the others are basically PackageRequirements with already set managers (pip will be pip everywhere)
Fabian Neuschmidt
@fneu
Sep 12 2016 12:23 UTC
which raises NotImplementedError
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:23 UTC
oh..
riiiiiiiight
i totally forgot about that
Fabian Neuschmidt
@fneu
Sep 12 2016 12:24 UTC
but all the other requirements have is_installed() :D
no problem
but here's the deal
shutil.which(executable) returns None if the executable is not available...
on all platforms afaik
that should totally be enough
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:26 UTC
im almost sure theres a very good reason why we're not using that
:D
but i cant recall which it is
Fabian Neuschmidt
@fneu
Sep 12 2016 12:26 UTC
so if a bear specified an executable, and optionally a version and a preferred package manager PACKAGE_MANAGER_TYPES = enum("SYSTEM", "PYTHON", "GO", "JAVASCRIPT", "RUBY") or something
coala only needs to check -> shutil?
and cib needs to figure out system package managers anyways
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 12:27 UTC
but
im not really sure i understand your approach
what is_installed() does is check whether the package is installed or not, not if the manager is or not
Fabian Neuschmidt
@fneu
Sep 12 2016 12:28 UTC
is_installed doesn't even need to be in the requirement
or could be implemented in PackageRequirement
where it could just call shutil.which(executable_name)
unless there is a good reason
not to
basically
I think a touple ('pip', 'coala_decorators', '0.1.0') would be better than all of the requirmenet stuff we have atm
although ok I kind of just figured out why that won't work :(
bears can depend on stuff like coala_decorators which doesn't offer an executable
Fabian Neuschmidt
@fneu
Sep 12 2016 12:37 UTC
@Adrianzatreanu ok so I wanna restructure some stuff
I think I can make cib work with distribution packages across all distributions and package managers

right now that's not the case.

in CPPCheckBear we have REQUIREMENTS = {DistributionRequirement(apt='cppcheck')}

which sucks because

a) it only works on distros with apt-get
b) even those distros could have a different package name

so I will change this (all bears, coala, cib :| ) in a way that those bears only specify an executable. The DistributionRequirement can then at least use shutil to check for that and cib will figure out what package manager is available and what package provides that executable
this will live on a branch for a while though
Lasse Schuirmann
@sils
Sep 12 2016 13:05 UTC

Fabian Neuschmidt @fneu 14:20
@Adrianzatreanu @sils1297 can we talk about Requirements?

I don't think coala uses the requirements classes yet but it should

Fabian Neuschmidt
@fneu
Sep 12 2016 13:06 UTC
for what?
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 13:06 UTC
@fneu it doesnt work with apt-get only, its just that i didnt put enough work into it
you can have
REQUIREMENTS = {DistributionRequirement(apt='cppcheck', dnf='cppcheckforfedora')}
and it will work on fedora too, if thats how its named in fedora
i have a dict in DistribRequirement that holds the most known package names and this is how you specify them
it is not ideal, indeed, if you want to do something better, feel free to, id love to see it, but i just felt like mentioning this :D
Fabian Neuschmidt
@fneu
Sep 12 2016 13:07 UTC
@sils1297 just checkint is_available or does coala need any installation functionality?
Lasse Schuirmann
@sils
Sep 12 2016 13:09 UTC
just is available
Fabian Neuschmidt
@fneu
Sep 12 2016 13:09 UTC
ok I figured as much
let's keep that, it makes sense
and is independend of the available packagemanagers
@Adrianzatreanu this is kind of what I've been doing this weekend
def package_name(self, package_executable):
        for path in misc.PATH:
            full_path = os.path.join(path, package_executable)

            retval, stdout, stderr = misc.run_command(["zypper",
                                                       "search",
                                                       "-f",
                                                       full_path])

            if retval == 0:
                output = stdout.decode("utf-8")

                # zypper also likes to update the repositories when they're out
                # of date. afterwards it prints a table like so:

                # bash-4.2# zypper search -f /bin/mksh
                # Loading repository data...
                # Reading installed packages...
                #
                # S | Name | Summary           | Type
                # --+------+-------------------+--------
                #   | mksh | MirBSD Korn Shell | package

                # We're splitting at "--------" and taking the value in the
                # next line between the '|' pipe characters

                line = output[output.find('--------'):].split('\n')[1]

                return line.split('|')[1].strip()

        return False
Fabian Neuschmidt
@fneu
Sep 12 2016 13:18 UTC
@Adrianzatreanu do you know if anything uses a CondaRequirement?
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 13:29 UTC
yes
nothing uses CondaRequirement yet
Fabian Neuschmidt
@fneu
Sep 12 2016 13:36 UTC
is it needed in the future? or should we just check for a python requirement in pip first and conda second if available?
Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 13:37 UTC
i dont know yet anything about it :/
Fabian Neuschmidt
@fneu
Sep 12 2016 13:37 UTC
ok we'll see
Fabian Neuschmidt
@fneu
Sep 12 2016 18:21 UTC

@Adrianzatreanu why is the PipRequirement using

result = [sys.executable, '-m', 'pip', 'install',
                  self.package + '==' + self.version if self.version
                  else self.package]

instead of just calling standalone pip?

Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 18:24 UTC
cuz some people dont have pip installed
i dont, for example
i only have pip3
this way, using python3 -m pip its calling pip3
Fabian Neuschmidt
@fneu
Sep 12 2016 18:25 UTC
but everybody has pip3 installed, right?
Mischa Krüger
@Makman2
Sep 12 2016 18:25 UTC
not windows^^
still pip, though it's version3^^
/ for python 3
Fabian Neuschmidt
@fneu
Sep 12 2016 18:25 UTC
but 'pip3' won't work?
Mischa Krüger
@Makman2
Sep 12 2016 18:25 UTC
windows doesn't even have the python3 executable, just python^^
nope^^
Fabian Neuschmidt
@fneu
Sep 12 2016 18:26 UTC
"cool"
...
ok
Fabian Neuschmidt
@fneu
Sep 12 2016 21:16 UTC

@Adrianzatreanu I'm making progress :D

http://pastebin.com/xJUTAnPi

Zatreanu Adrian-Gabriel
@Adrianzatreanu
Sep 12 2016 21:20 UTC
nice :D