Giter VIP home page Giter VIP logo

starboard-python's Introduction

starboard-python's People

Contributors

gzuidhof avatar stefnotch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

starboard-python's Issues

Test filesystem

Ideally we'd also have some test cases for the filesystem code.

For reference, here is mine

const backingStore = new Map<string, string | null>();
const fs: NotebookFilesystem = {
  async get({ path }) {
    const file = backingStore.get(path);
    if (file === undefined) {
      return { ok: false, status: 1, error: new Error("File not found " + path) };
    } else {
      return { ok: true, data: file };
    }
  },
  async put({ path, value }) {
    backingStore.set(path, value);
    return { ok: true, data: undefined };
  },
  async delete({ path }) {
    backingStore.delete(path);
    return { ok: true, data: undefined };
  },
  async move({ path, newPath }) {
    // TODO: Implement directory moving
    const getFileResult = await fs.get({ path });
    if (!getFileResult.ok) return getFileResult;
    const deleteFileResult = await fs.delete({ path });
    if (!deleteFileResult.ok) return deleteFileResult;
    const putFileResult = await fs.put({ path: newPath, value: getFileResult.data });
    if (!putFileResult.ok) return putFileResult;
    return { ok: true, data: undefined };
  },
  async listDirectory({ path }) {
    if (!path.endsWith("/")) path += "/";

    const filePaths = [...backingStore.keys()]
      .filter((k) => k.startsWith(path) && k !== path)
      .map((v) => v.slice(path.length).split("/")[0]);
    return { ok: true, data: [...new Set(filePaths)] };
  },
};
rt.internal.fs = fs;
(rt.internal.fs as any).backingStore = backingStore;
# %% [python]
import os
print(os.path.dirname(os.path.realpath('__file__')))


f = open("demofile.txt", "a")
f.write("File content ๐Ÿ•!")
f.close()

#open and read the file after the appending:
f = open("demofile.txt", "r")
print(f.read())  # Should print out "File content ๐Ÿ•!"

os.mkdir("cat")
f = open("./cat/demofile2.txt", "a")
f.write("Also a file")
f.close()

f = open("cat/demofile2.txt", "r")
print(f.read())  # Should print out "Also a file"

# %% [python]
f = open("cat/demofile4.txt", "r") # Should cause an error
print(f.read())

# %% [python]
import os

# Should print all files and directories
for currentpath, folders, files in os.walk('/mnt'):
    for folder in folders:
        print(os.path.join(currentpath, folder))
    for file in files:
        print(os.path.join(currentpath, file))

# %% [python]
import glob

# Should print all files and directories in /mnt/shared
for filename in glob.iglob('**/**', recursive=True):
     print(filename)

# %% [python]
import os
print(os.listdir(path='.')) # Should show ['demofile.txt', 'cat'] 
os.rename('demofile.txt', 'catapprovedfile.txt')
print(os.listdir(path='.')) # Should show ['cat', 'catapprovedfile.txt'] 
os.rename('catapprovedfile.txt', './cat/myfile.txt')
print(os.listdir(path='cat')) # Should show ['demofile2.txt', 'myfile.txt'] 

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.