<commit_before>const fse = require('fs-extra');
const path = require('path');
const get = require('lodash.get');
const set = require('lodash.set');
const values = require('lodash.values');
const rimraf = require('rimraf');


/**
 * link all the files in .serverless/requirements to the service directory root
 * @return {undefined}
 */
function linkRequirements() {
  const requirementsDir = path.join(this.servicePath, '.serverless/requirements');
  if (fse.existsSync('__pycache__'))
    rimraf.sync('__pycache__');
  if (!get(this.serverless.service, 'package.include'))
    set(this.serverless.service, ['package', 'include'], []);
  if (!this.options.zip && fse.existsSync(requirementsDir)) {
    this.serverless.cli.log('Linking required Python packages...');
    const noDeploy = new Set(this.options.noDeploy || []);
    fse.readdirSync(requirementsDir).map((file) => {
      if (noDeploy.has(file))
        return;
      if (this.serverless.service.package.individually) {
        // don't include python deps in non-python functions
        values(this.serverless.service.functions)
          .filter((f) => (f.runtime || this.serverless.service.provider.runtime).match(/^python.*/))
          .forEach((f) => {
            if (!get(f, 'package.include'))
              set(f, ['package', 'include'], []);
            f.package.include.push(file)
            f.package.include.push(`${file}/**`)
          });
      } else {
        this.serverless.service.package.include.push(file);
        this.serverless.service.package.include.push(`${file}/**`);
      }
      try {
        fse.symlinkSync(`${requirementsDir}/${file}`, `./${file}`);
      } catch (exception) {
        let linkDest = null;
        try {
          linkDest = fse.readlinkSync(`./${file}`);
        } catch (e) {
        }
        if (linkDest !== `${requirementsDir}/${file}`)
          throw exception;
      }
    });
  }
}

/**
 * unlink all the files in .serverless/requirements from the service directory root
 * @return {undefined}
 */
function unlinkRequirements() {
  const requirementsDir = path.join(this.servicePath, '.serverless/requirements');
  if (!this.options.zip && fse.existsSync(requirementsDir)) {
    this.serverless.cli.log('Unlinking required Python packages...');
    const noDeploy = new Set(this.options.noDeploy || []);
    fse.readdirSync(requirementsDir).map((file) => {
      if (noDeploy.has(file))
        return;
      fse.unlinkSync(file);
    });
  }
}

module.exports = {linkRequirements, unlinkRequirements};<commit_msg>win32 copy fallback! closes #118<commit_after>const fse = require('fs-extra');
const path = require('path');
const get = require('lodash.get');
const set = require('lodash.set');
const values = require('lodash.values');
const rimraf = require('rimraf');


/**
 * link all the files in .serverless/requirements to the service directory root
 * @return {undefined}
 */
function linkRequirements() {
  const requirementsDir = path.join(this.servicePath, '.serverless/requirements');
  if (fse.existsSync('__pycache__'))
    rimraf.sync('__pycache__');
  if (!get(this.serverless.service, 'package.include'))
    set(this.serverless.service, ['package', 'include'], []);
  if (!this.options.zip && fse.existsSync(requirementsDir)) {
    this.serverless.cli.log('Linking required Python packages...');
    const noDeploy = new Set(this.options.noDeploy || []);
    fse.readdirSync(requirementsDir).map((file) => {
      if (noDeploy.has(file))
        return;
      if (this.serverless.service.package.individually) {
        // don't include python deps in non-python functions
        values(this.serverless.service.functions)
          .filter((f) => (f.runtime || this.serverless.service.provider.runtime).match(/^python.*/))
          .forEach((f) => {
            if (!get(f, 'package.include'))
              set(f, ['package', 'include'], []);
            f.package.include.push(file)
            f.package.include.push(`${file}/**`)
          });
      } else {
        this.serverless.service.package.include.push(file);
        this.serverless.service.package.include.push(`${file}/**`);
      }
      try {
        fse.symlinkSync(`${requirementsDir}/${file}`, `./${file}`);
      } catch (exception) {
        if (e.code === 'EPERM' && process.platform !== 'win32') {
          fse.copySync(`${requirementsDir}/${file}`, `./${file}`);
        } else {
          let linkDest = null;
          try {
            linkDest = fse.readlinkSync(`./${file}`);
          } catch (e) {
          }
          if (linkDest !== `${requirementsDir}/${file}`)
            throw exception;
        }
      }
    });
  }
}

/**
 * unlink all the files in .serverless/requirements from the service directory root
 * @return {undefined}
 */
function unlinkRequirements() {
  const requirementsDir = path.join(this.servicePath, '.serverless/requirements');
  if (!this.options.zip && fse.existsSync(requirementsDir)) {
    this.serverless.cli.log('Unlinking required Python packages...');
    const noDeploy = new Set(this.options.noDeploy || []);
    fse.readdirSync(requirementsDir).map((file) => {
      if (noDeploy.has(file))
        return;
      fse.unlinkSync(file);
    });
  }
}

module.exports = {linkRequirements, unlinkRequirements};
{'fraction_non_alphanumeric': 0.1714989577411408, 'fraction_numerical': 0.0013265112753458404, 'mean_word_length': 2.9924357034795763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3651325', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1613, 'n_words': 295}