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

Add support for parsing dependencies from *.cabal files #339

Closed
andrew opened this issue Jul 12, 2017 · 29 comments
Closed

Add support for parsing dependencies from *.cabal files #339

andrew opened this issue Jul 12, 2017 · 29 comments

Comments

@andrew
Copy link
Contributor

andrew commented Jul 12, 2017

Will very likely need to be parsed by a haskell programming or shelling out to $ cabal

Example: https://github.com/cakesolutions/the-pragmatic-haskeller/blob/master/01-json/pragmatic.cabal

Name:                pragmatic
Version:             0.1
Synopsis:            Project Synopsis Here
Description:         Project Description Here
License:             AllRightsReserved
Author:              Author
Maintainer:          [email protected]
Stability:           Experimental
Category:            Web
Build-type:          Simple
Cabal-version:       >=1.2

Executable pragmatic
  hs-source-dirs: src
  main-is: Main.hs

  Build-depends:
    aeson                     >= 0.6.0.1 && < 0.7,
    base                      >= 4       && < 5,
    bytestring                >= 0.9.1   && < 0.11,
    text                      >= 0.11    && < 0.12

Documentation of the file format: https://www.haskell.org/cabal/users-guide/developing-packages.html

Some of the documentation in hpack might be useful for better understanding it: https://github.com/sol/hpack

@alunduil
Copy link

I'd love to help out with this but as I saw noted in #175 the documentation on how to add a package manager parser isn't available. Is there a quick start or at least a list of methods with signatures? I can probably figure most of it out by reading the others but would like to read something definitive if it's available.

@andrew
Copy link
Contributor Author

andrew commented Dec 21, 2017

@alunduil awesome, thanks for offering! I don't think I'll get chance to complete the documentation before I break for christmas but in the meantime check out the collection of existing parsers: https://github.com/librariesio/bibliothecary/tree/master/lib/bibliothecary/parsers

For cabal support, unless you're thinking of using regexes, I'd guess we'll need a separate service for parsing cabel files, perhaps a haskell webservice?

@alunduil
Copy link

@andrew, now you're speaking my language. I'd love to avoid regexes if possible so a Haskell web service sounds great. Does any other parser use that pattern so I could see how you'd like it setup or should I design something that provides a list of packages with ranges and call it good? Also, where would you like that code to live?

@alunduil
Copy link

alunduil commented Jan 9, 2018

@andrew just a shameless bump on this one.

@andrew
Copy link
Contributor Author

andrew commented Jan 9, 2018

@alunduil ah yeah, forgot about this whilst I was on holiday over xmas.

https://github.com/librariesio/yarn-parser is an example one of these services, it accepts a post request with the body of file contents and returns json data that looks something like this:

[
  {
    "name": "foobar",
    "requirement": ">0.1",
    "type": "runtime"
  }
]

Where:

  • name is the package name on https://hackage.haskell.org/package/lens
  • requirement is the version range of the dependency, usually a semver range or exact version number
  • type is where the dependency is used, usually runtime, development or test but can be any specific strings for the given package manager functionality

n.b. Yarn-parser returns version instead of requirement due to legacy reasons

@alunduil
Copy link

@andrew awesome! I can whip something up for that. I'll start a new repository for cabal-parser and if it looks good you we can transfer ownership.

Can you provide an example of a requirement that's closed and not just a half-open one? What about wildcards, will those need to be translated?

Thanks for all of the guidance.

@andrew
Copy link
Contributor Author

andrew commented Jan 11, 2018

@alunduil I don't think you'll need to do any translation of the requirements, just pass them straight through as is, if it's blank then maybe default to *

Looking at the example in https://downloads.haskell.org/~ghc/7.0.2/docs/html/Cabal/authors.html#buildinfo

library
  build-depends:
    base >= 2,
    foo >= 1.2 && < 1.3,
    bar

would translate to

[
  {
    "name": "base",
    "requirement": ">= 2",
    "type": "build"
  },
  {
    "name": "foo",
    "requirement": ">= 1.2 && < 1.3",
    "type": "build"
  },
  {
    "name": "bar",
    "requirement": "*",
    "type": "build"
  },
]

@alunduil
Copy link

@andrew Awesome! I've almost got the basic structure of the web service put together. Hopefully by this weekend I can have it functioning and ready for review.

@andrew
Copy link
Contributor Author

andrew commented Jan 11, 2018

@alunduil sweet, looking forward to it, thanks for contributing!

@alunduil
Copy link

@andrew I've got a working version. I passed through all versions to requirements unmodified except the missing or any version. I changed any version to "*" as you suggested.

Take a look at https://github.com/alunduil/librariesio-cabal-parser and let me know what you think. I've run it against a couple of my projects and it appears to work as intended but I've got a couple of tests to add more checks later.

If this looks good, let me know if you want to bring it into librariesio and I'll start working on the bibliothecary side of the project as well.

@alunduil alunduil mentioned this issue Jan 14, 2018
5 tasks
@andrew
Copy link
Contributor Author

andrew commented Jan 15, 2018

Just attempting to set this up locally and learn me some haskell, looking good though 👍

@andrew
Copy link
Contributor Author

andrew commented Jan 15, 2018

I got it running locally and working with bibliothecary 🎉

I had to made a few changes to docker-compose.yml to get it exposing the internal port to localhost on my laptop:

version: '3'

services:
  app:
    build: ./
    ports:
      - 5000:5000

One thing that would be nice to add to the parsing service would be some logging to make it a little easier to keep track of the internal state of the application, just to STDOUT would be fine.

@alunduil
Copy link

@andrew what kind of logging are you looking for? Just apache style logs or something nicer like APM data?

@andrew
Copy link
Contributor Author

andrew commented Jan 16, 2018

@alunduil apache style logs are fine, mainly to see frequency and response time of the endpoint being hit

@alunduil
Copy link

@andrew Sounds good. I'll add that in today and let you know.

@alunduil
Copy link

@andrew I've added basic Apache logging but it doesn't include response time unless I add custom logic. Let me know if what's on master is acceptable, otherwise I'll see about adding response time as well.

@alunduil
Copy link

@andrew just a friendly bump in case this has been forgotten. Let me know if any more changes would be nice to have or what next steps would be.

@andrew
Copy link
Contributor Author

andrew commented Jan 19, 2018

@alunduil sorry for the delay, I'll be deploying your parsing service soon and then merging the bibliothecary pr, should be ready to go on Monday

@alunduil
Copy link

@andrew sweet! Let me know if I can do anything else before then. Do you have an interest in moving the cabal-parser repository into the libraries.io organization?

@alunduil
Copy link

@andrew just checking in to see how the deployment is going. Let me know if I can help with anything.

@andrew
Copy link
Contributor Author

andrew commented Jan 31, 2018

@alunduil sorry, not got round to it yet, FOSDEM is this weekend and has kind of destroyed all my productivity!

@alunduil
Copy link

@andrew no worries. I was afraid that might interfere with things. I'll ping you again mid to late next week if I don't hear anything. Enjoy FOSDEM!

@andrew
Copy link
Contributor Author

andrew commented Feb 2, 2018

Deployed 🚢 thanks for contributing!

@andrew andrew closed this as completed Feb 2, 2018
@alunduil
Copy link

alunduil commented Feb 3, 2018

@andrew, awesome! Thanks for everything!

@andrew
Copy link
Contributor Author

andrew commented Feb 4, 2018

Just enqueued about 50,000 jobs to parse all the cabal dependencies every haskell repo on github. Example from https://libraries.io/github/egison/egison

screen shot 2018-02-04 at 12 43 38

@alunduil
Copy link

alunduil commented Feb 5, 2018

@andrew That's awesome! I'm excited to see my repositories and packages fill in as well. Any estimate on how long that run will take?

@andrew
Copy link
Contributor Author

andrew commented Feb 5, 2018

Looks like it's mostly finished now

@alunduil
Copy link

alunduil commented Feb 5, 2018

@andrew seems like my repositories are stuck in syncing. Want me to open another issue for that? Also, when I force a private repo to sync on libraries.io it doesn't pick up the cabal dependencies.

@andrew
Copy link
Contributor Author

andrew commented Feb 6, 2018

Yeah a second issue for that would be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants