Giter VIP home page Giter VIP logo

Comments (6)

jayqi avatar jayqi commented on August 22, 2024

Hi @CagtayFabry, thanks for your interest in reprexlite!

Can you explain a little bit more about why you want to use reprexlite for doctest outputs? One of the core design ideas behind reprexlite is to be an alternative to doctest. Even if this weren't the case, it's also not clear to me that something like reprexlite is the right tool for this. You could simply open a Python REPL from the command line and copy-paste from there.

from reprexlite.

CagtayFabry avatar CagtayFabry commented on August 22, 2024

thanks for getting back here @jayqi

basically I currently use reprexlite for a convenient way to produce examples/bug reports etc. for GH. I usually generate those from a jupyter environment. Some of my projects rely on doctest for docstrings and testing.
The main benefits I could see in using reprexlite for creating doctest-like output over running code in an iPython shell are:

  • better handling of multiline scripts with multiple outputs at the correct line (without adding print etc.)
  • ability to black-format the input
  • stick to a notebook environment to generate both (GH format + doctest)

I do agree on your assessment of the drawbacks when using doctest format but I need the sphinx/pytest integration etc.

from reprexlite.

jayqi avatar jayqi commented on August 22, 2024

I guess that makes sense.

I think rather than a --venue=doctest, it probably makes more sense to implement it through different parameters, since you might want doctest-style output in any of the venues. Discussion of two possible approaches to implementation:

  1. Have some kind of switch --style=reprex or --style=doctest.
    • This might not be the right abstraction since the --comment option doesn't make as much sense in this context.
  2. Add prompt parameter(s) that you can set to >>> (and maybe also ... for multiline). Figure out how to set --comment to empty string.
    • This seems like it would be the most general approach, and would be able to support doctest as well as whatever other styles that someone cooks up.

Another angle to your use case is maybe open issue #16. I'm not sure how sphinx or pytest handle doctests so I don't know much on top of that it would take to support sphinx or pytest.

from reprexlite.

jayqi avatar jayqi commented on August 22, 2024

I did poke around at this and made some progress. It does involve a bunch of refactoring as it doesn't quite line up with some of my abstractions. 😅

One annoying thing still to solve is that libcst, which I use to parse the code, attaches whitespace lines to code statements following them, which ends up misformatting the code after empty lines. That will involve some finagling.

>>> from itertools import product
>>> 
... grid = list(product([1, 2, 3], [8, 16]))
>>> grid
[(1, 8), (1, 16), (2, 8), (2, 16), (3, 8), (3, 16)]
>>> for var in list(zip(*grid)):
...     print(var)
(1, 1, 2, 2, 3, 3)
(8, 16, 8, 16, 8, 16)

from reprexlite.

jayqi avatar jayqi commented on August 22, 2024

Hi @CagtayFabry,

I know it's been a while, but I did a major overhaul of reprexlite's internals and this has been merged to the main branch. It's not released yet, but if you want to start using it, you can install from source.

reprex --prompt=">>>" --continuation="..." --comment=""
>>> from itertools import product
>>> 
>>> grid = list(product([1, 2, 3], [8, 16]))
>>> grid
[(1, 8), (1, 16), (2, 8), (2, 16), (3, 8), (3, 16)]
>>> list(zip(*grid))
[(1, 1, 2, 2, 3, 3), (8, 16, 8, 16, 8, 16)]

Created at 2023-02-22 19:55:25 EST by reprexlite v1.0.0

from reprexlite.

CagtayFabry avatar CagtayFabry commented on August 22, 2024

awesome! 🚀
these configuration options look great! thank you for the ping @jayqi

from reprexlite.

Related Issues (20)

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.