Code Monkey home page Code Monkey logo

nim-requirementstxt's Introduction

RequirementsTxt

  • Python requirements.txt generic iterator parser for Nim.
  • No Regex used in the making of this film!

Use

for it in requirements(readFile("requirements.txt")):
  echo it

for it in requirements(staticRead("requirements.txt")):
  echo it

for it in requirements(readFile("requirements.txt"), [("*", "0")]):  ## "1.*.*" becomes "1.0.0", uses multiReplace
  echo it

1 Input argument can be filename: string. Based from the official spec: https://pip.readthedocs.io/en/1.1/requirements.html

Output

Yields 1 tuple per parsed line:

  • line Current line being parsed (42, etc).
  • editable Boolean whether this requirement is "editable".
  • specifier String version specifier (For "flask>=1.5" is >=)
  • vcs Distributed version control system used ("git", "hg", etc).
  • protocol Network protocol for transports ("http", "https", "ssh", etc)
  • name Package name parsed ("pytest", etc).
  • version Package version string ("1.2.9", etc).
  • uri URL if this requirement of Uri type ("https://github.com/user/repo.git", etc).
  • extras Sequence of strings with a list of extras ("flask[extra1, extra2]" is @["extra1", "extra2"])
  • blanks Current count of comments, blank lines, empty lines, etc (42, etc).
  • private Current count of Private custom repositories (Not PYPI).
  • nested Current count of recursively Nested requirements.txt files (42, etc).

Example Output:

(line: 9, editable: false, specifier: true, vcs: "git", protocol: "https", version: "1.6.0", name: "numpy", url: "https://github.com/user/repo.git", blanks: 1, nested: 0, private: 0, extras: @["full", "pdf"])

If you need a seq of tuple use sequtils.toSeq. It uses Effects Tags ReadIOEffect, WriteIOEffect.

Install

nimble install requirementstxt

Test

$ nimble test

[Suite] Requirements.txt generic parser tests
  [OK] Big requirements.txt parsing
  [OK] Empty requirements.txt parsing
  [OK] Empty requirements.txt parsing 2
   Success: Execution finished
   Success: All tests passed

Test is using a big and complex requirements.txt.

Documentation

  • runnableExamples included.
nim doc requirementstxt.nim

Supported DVCS

  • git
  • git+https
  • git+ssh
  • git+git
  • hg+http
  • hg+https
  • hg+static-http
  • hg+ssh
  • svn
  • svn+svn
  • svn+http
  • svn+https
  • svn+ssh
  • bzr+http
  • bzr+https
  • bzr+ssh
  • bzr+sftp
  • bzr+ftp
  • bzr+lp
  • No DVCS

Requisites

  • None.

Dependencies

  • None.

Stars

Stars over time

FAQ

  • Why a generic iterator ?.

Generic so you can use string or StringStream or File.

iterator because requirements.txt are meant to have 1 dependency per line.

If you are familiar with Python, Nim iterator is like Python generator, Nim tuple is like Python NamedTuple.

⬆️ ⬆️ ⬆️ ⬆️

nim-requirementstxt's People

Contributors

juancarlospaco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jgarte

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.