question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove dependency on defining __file__

See original GitHub issue

Hi. I’m working on a custom pytest kernel for Jupyter Notebooks. It is simply a thin wrapper on the ipython3 kernel and uses your excellent package for all the heavy lifting.

My aim is to make using it transparent, meaning no extra code should be added by the user. I have used injection to achieve most of this goal with the sole exception of the __file__ variable. I have a very crude hack that works around this.

What I was wondering, however, was if it could be possible to remove the dependency on defining __file__ in the notebook.

In particular some way to leverage the fact that I have access to the code being passed in to do_execute() in the kernel so can essentially store all the code in a string if ipytest can digest that directly without having to parse the .ipynb file that it needs to be passed in using __file__.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
chmpcommented, Feb 24, 2019

I like option 1, too, for similar reasons you mentioned. I implemented it in develop, you can give it a try by installing ipytest==0.5.0b5. To make ipytest fallback on the temporary file, you need to enable the tempfile_fallback option. My current setup reads:

import ipytest
ipytest.config(rewrite_asserts=True, tempfile_fallback=True, magics=True)

It would be great, if you could give it a try and report back, whether this fix solves the issue for you.

0reactions
chmpcommented, Nov 19, 2019

@detly after running with the tempfile_fallback option for a while now, I have been convinved. Mostly for symmetry reasons, I do not want to enable it by default (*). However, I added a autoconfig function with more reasonable defaults (tempfile_fallback=True, magics=True, rewrite_asserts=True, addopts=['-q']). Hopefully, this makes the library a bit smoother to use for you.

For now the option is only available in the current beta release. You can test-drive it by installing it with pip install ipytest==0.8.0b1 and then use:

import ipytest
ipytest.autoconfig()

(*): Since magics cannot be turned off, they should be optional, but then some options are enabled per default, some are disabled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

To Remove File Dependencies
Right-click the dependent child file and select Unlink Dependency. When the Remove Dependent File Link dialog opens, click Yes. The file dependency is ......
Read more >
How to remove dependency definitions from a Make target?
Use a different name besides includes for one of the two targets. Make has no notion of 'subtracting' or 'removing' dependencies.
Read more >
Removing Dependencies: One Weird Trick for Increasing ...
Removing Dependencies : One Weird Trick for Increasing Happiness ... One definition of "not being used" is "no source file in the app...
Read more >
Removing dependencies (Microsoft Dataverse) - Power Platform
First, it's important to understand that dependencies only prevent operations that will delete a required component. The actions that can delete ...
Read more >
Remove a package from dependencies - Julia Discourse
Yeah, you could manually remove the dependency from Project.toml file, after all it's a simple text file. But I don't think thats a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found