Coder Social home page Coder Social logo

figsoda / pep-508 Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 1.0 31 KB

Rust implementation of Python dependency parser for PEP 508

Home Page: https://docs.rs/pep-508

License: Mozilla Public License 2.0

Rust 100.00%
pep508 python requirements rust chumsky parser

pep-508's Introduction

pep-508

Rust implementation of Python dependency parser for PEP 508

version deps license ci

Documentation

Usage

let dep = "requests[security, socks] <= 2.28.1, == 2.28.*; python_version > '3.7' and extra == 'http'";
let parsed = parse(dep).unwrap();
let expected = Dependency {
    name: "requests",
    extras: vec!["security", "socks"],
    spec: Some(Spec::Version(vec![
        VersionSpec {
            comparator: Comparator::Le,
            version: "2.28.1",
        },
        VersionSpec {
            comparator: Comparator::Eq,
            version: "2.28.*",
        },
    ])),
    marker: Some(Marker::And(
        Box::new(Marker::Operator(
            Variable::PythonVersion,
            Operator::Comparator(Comparator::Gt),
            Variable::String("3.7"),
        )),
        Box::new(Marker::Operator(
            Variable::Extra,
            Operator::Comparator(Comparator::Eq),
            Variable::String("http"),
        )),
    )),
};
assert_eq!(parsed, expected);

Changelog

See CHANGELOG.md

pep-508's People

Contributors

dependabot[bot] avatar figsoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aswinnnn

pep-508's Issues

Fails to parse any string with a comparator [version 0.3.0]

Here's a sample code I tried running:

use pep_508;

fn main() {
    let s = pep_508::parse("vyper <= '1.0.1'");
    println!("{:?}", s)
}

Here's the error I get:

Err([found end of input at 9..10])

Parser works perfectly fine on just the dependency names but anything with a comparator throws me that error. I have tried various ways to make the string but still no use.

Fails to parse `--hash=` values embedded in requirements.txt

The contents of requirements.txt used for parsing: https://github.com/anotherbridge/pdfalyzer/blob/master/requirements.txt

Within the following code: extractor.rs

Here's the Err values:

[
    found ''\\'' at 68..69,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 68..69,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 71..72,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 72..73,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 70..71,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 68..69,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 75..76,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 81..82,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 66..67,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 65..66,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 79..80,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 67..68,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 72..73,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found ''\\'' at 70..71,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..1,
]
[
    found end of input at 0..0,
]
Ok(Dependency { name: "lxml", extras: [], spec: None, marker: None })

I added lxml at the end of the file to see if it was a file quirk, and unfortunately not. Is this because it's unsupported in pep-508 crate for now? Wouldn't parsing the text before ; would be a feasible workaround?

Your crate is one of the core ones I use [issue originally mentioned at aswinnnn/pyscan#16] and would appreciate it if you could look into it. Thanks.

Compiling pep-508 fails [Rust `v1.70`]

Using pep-508 v0.3.0

Error:

error[E0599]: no method named `slice` found for struct `Then` in the current scope
   --> pep-508-0.3.0\src\url.rs:142:6
    |
125 | /     choice((
126 | |         group((
127 | |             any().filter(char::is_ascii_alphabetic),
128 | |             set!('A' ..= 'Z' | 'a' ..= 'z' | '0' ..= '9' | '+' | '-' | '.').repeated(),
...   |
141 | |     .then(frags)
142 | |     .slice()
    | |     -^^^^^ method not found in `Then<Choice<(Ignored<Group<(..., ..., ..., ...)>, ...>, ..., ...)>, ..., ..., ..., ...>` 
    | |_____|
    | 
    |

This started happening out of nowhere. Do you know why?

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.