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

Put all code that we reuse across weeks in an importable library #274

Open
dniku opened this issue Aug 30, 2019 · 1 comment
Open

Put all code that we reuse across weeks in an importable library #274

dniku opened this issue Aug 30, 2019 · 1 comment

Comments

@dniku
Copy link
Collaborator

dniku commented Aug 30, 2019

Currently, our directory structure is basically a bunch of week* folders at the top level. However, some code is consistently reused across weeks, the most prominent example being launching xvfb. I propose to put all reusable code into a top-level directory called practical_rl.

In this case, all notebooks will have to start with

import sys
sys.path.append('..')

import practical_rl
practical_rl.create_display_if_missing()

rather that the current (rather diverse) set of preambles.

Alternatively, we could maybe setup a custom PYTHONPATH, although that solution is brittle.

Here is an example of what can be put in practical_rl/__init__.py:

import logging
import os
import subprocess


def create_display_if_missing():
    display = os.environ.get('DISPLAY')
    if not isinstance(display, str) or len(display) == 0:
        logging.warning('No display detected (DISPLAY={}). Launching xvfb...'.format(display))
        subprocess.check_call(['../xvfb', 'start'])
        os.environ['DISPLAY'] = ':1'
@dniku
Copy link
Collaborator Author

dniku commented Aug 30, 2019

Thinking a little more about this, there is a problem which must be addressed: in the current state, our notebooks are mostly standalone and can be run via Colab. The inclusion of a library will change that.

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

1 participant