<commit_before>from PyBake import *
from PyBake.logger import *
from importlib import import_module

def upload_generator(pastry_file, ingredients):
  # First, send the pastry file.
  yield ("pastry", pastry_file,)

  # Then, iterate all ingredients, sending them one after another.
  for ingredient in ingredients:
    path = Path(ingredient["path"])
    yield (path.as_posix(), path.open("rb"),)

def run(*, pastry_path, config, **kwargs):
  import requests, json

  # Import the config script.
  log.debug("Importing config script '{}'".format(config))
  config = import_module(config)

  # Make sure the path exists.
  pastry_path = pastry_path.resolve()
  log.debug("Pastry path: {}".format(pastry_path.as_posix()))
  if pastry_path.is_dir():
    log.error("Expected given pastry to be a file, but is a directory!")
    return

  with ChangeDir(pastry_path.parent):
    log.dev("Loading pastry from '{}'...".format(pastry_path.as_posix()))
    with pastry_path.open("r") as pastry_file:
      pastry = json.load(pastry_file)
      data = { "name" : pastry["name"], "version" : pastry["version"] }
      files = upload_generator(pastry_file, pastry["ingredients"])
      log.dev("Communicating with {}...".format(config.server))
      response = requests.post("{}/get_crumble".format(config.server), data=data, files=files)

  with LogBlock("Response"):
    log.dev("Status Code: {}".format(response.status_code))
    log.dev(response.json())<commit_msg>'depot' successfully sends the patry files to the server!<commit_after>from PyBake import *
from PyBake.logger import *
from importlib import import_module

def upload_generator(pastry_name, pastry_file, ingredients):
  # First, send the pastry file.
  yield (pastry_name, pastry_file,)

  # Then, iterate all ingredients, sending them one after another.
  for ingredient in ingredients:
    path = Path(ingredient["path"]).resolve().relative_to(Path.cwd())
    log.info("Uploading {}...".format(path.as_posix()))
    yield (path.as_posix(), path.open("rb"),)

def run(*, pastry_path, config, **kwargs):
  import requests, json

  # Import the config script.
  log.debug("Importing config script '{}'".format(config))
  config = import_module(config)

  # Make sure the path exists.
  pastry_path = pastry_path.resolve()
  log.debug("Pastry path: {}".format(pastry_path.as_posix()))
  log.debug("Pastry name: {}".format(pastry_path.name))
  if pastry_path.is_dir():
    log.error("Expected given pastry to be a file, but is a directory!")
    return

  with ChangeDir(pastry_path.parent):
    log.dev("Loading pastry from '{}'...".format(pastry_path.as_posix()))
    with pastry_path.open("r") as pastry_file:
      pastry = json.load(pastry_file)
      data = { "name"    : pastry["name"],
               "version" : pastry["version"],
               "pastry_file_name"  : pastry_path.name, }
      files = upload_generator(pastry_path.name, pastry_file, pastry["ingredients"])
      postUrl = "{}/upload_crumble".format(config.server)
      log.info("Posting to {}...".format(postUrl))
      response = requests.post(postUrl, data=data, files=files)
      if response.status_code == requests.codes.ok:
        log.success("Successful deposit.")

  with LogBlock("Response"):
    log.dev("Status Code: {}".format(response.status_code))
    log.dev(response.json())
{'fraction_non_alphanumeric': 0.14595245260306952, 'fraction_numerical': 0.0, 'mean_word_length': 4.210031347962382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7016930', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1030, 'n_words': 251}