<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function
import os, frappe, json, shutil, re, warnings
from os.path import exists as path_exists, join as join_path, abspath, isdir
from distutils.spawn import find_executable
from six import iteritems, text_type
from frappe.utils.minify import JavascriptMinify

"""
Build the `public` folders and setup languages
"""

app_paths = None
def setup():
	global app_paths
	pymodules = []
	for app in frappe.get_all_apps(True):
		try:
			pymodules.append(frappe.get_module(app))
		except ImportError: pass
	app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules]

def get_node_pacman():
	pacmans = ['yarn', 'npm']
	for exec_ in pacmans:
		exec_ = find_executable(exec_)
		if exec_:
			return exec_
	raise ValueError('No Node.js Package Manager found.')

def bundle(no_compress, app=None, make_copy=False, restore=False, verbose=False):
	"""concat / minify js files"""
	setup()
	make_asset_dirs(make_copy=make_copy, restore=restore)

	pacman = get_node_pacman()
	mode = 'build' if no_compress else 'production'
	command = '{pacman} run {mode}'.format(pacman=pacman, mode=mode)

	if app:
		command += ' --app {app}'.format(app=app)

	frappe_app_path = abspath(join_path(app_paths[0], '..'))
	check_yarn()
	frappe.commands.popen(command, cwd=frappe_app_path)

def watch(no_compress):
	"""watch and rebuild if necessary"""
	setup()

	pacman = get_node_pacman()

	frappe_app_path = abspath(join_path(app_paths[0], '..'))
	check_yarn()
	frappe_app_path = frappe.get_app_path('frappe', '..')
	frappe.commands.popen('{pacman} run watch'.format(pacman=pacman), cwd = frappe_app_path)

def check_yarn():
	from distutils.spawn import find_executable
	if not find_executable('yarn'):
		print('Please install yarn using below command and try again.')
		print('npm install -g yarn')
		return

def make_asset_dirs(make_copy=False, restore=False):
	# don't even think of making assets_path absolute - rm -rf ahead.
	assets_path = join_path(frappe.local.sites_path, "assets")
	for dir_path in [
			join_path(assets_path, 'js'),
			join_path(assets_path, 'css')]:

		if not path_exists(dir_path):
			os.makedirs(dir_path)

	for app_name in frappe.get_all_apps(True):
		pymodule = frappe.get_module(app_name)
		app_base_path = abspath(os.path.dirname(pymodule.__file__))

		symlinks = []
		app_public_path = join_path(app_base_path, 'public')
		# app/public > assets/app
		symlinks.append([app_public_path, join_path(assets_path, app_name)])
		# app/node_modules > assets/app/node_modules
		if path_exists(abspath(app_public_path)):
			symlinks.append([join_path(app_base_path, '..', 'node_modules'), join_path(assets_path, app_name, 'node_modules')])

		app_doc_path = None
		if isdir(join_path(app_base_path, 'docs')):
			app_doc_path = join_path(app_base_path, 'docs')

		elif isdir(join_path(app_base_path, 'www', 'docs')):
			app_doc_path = join_path(app_base_path, 'www', 'docs')

		if app_doc_path:
			symlinks.append([app_doc_path, join_path(assets_path, app_name + '_docs')])

		for source, target in symlinks:
			source = abspath(source)
			if path_exists(source):
				if restore:
					if path_exists(target):
						if os.path.islink(target):
							os.unlink(target)
						else:
							shutil.rmtree(target)
						shutil.copytree(source, target)
				elif make_copy:
					if path_exists(target):
						warnings.warn('Target {target} already exists.'.format(target = target))
					else:
						shutil.copytree(source, target)
				else:
					if path_exists(target):
						if os.path.islink(target):
							os.unlink(target)
						else:
							shutil.rmtree(target)
					try:
						os.symlink(source, target)
					except OSError:
						print('Cannot link {} to {}'.format(source, target))
			else:
				# warnings.warn('Source {source} does not exist.'.format(source = source))
				pass

def build(no_compress=False, verbose=False):
	assets_path = join_path(frappe.local.sites_path, "assets")
<commit_msg>fix: bench build "Cannot link {assets} to {site assets}"<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function
import os, frappe, json, shutil, re, warnings
from os.path import exists as path_exists, join as join_path, abspath, isdir
from distutils.spawn import find_executable
from six import iteritems, text_type
from frappe.utils.minify import JavascriptMinify

"""
Build the `public` folders and setup languages
"""

app_paths = None
def setup():
	global app_paths
	pymodules = []
	for app in frappe.get_all_apps(True):
		try:
			pymodules.append(frappe.get_module(app))
		except ImportError: pass
	app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules]

def get_node_pacman():
	pacmans = ['yarn', 'npm']
	for exec_ in pacmans:
		exec_ = find_executable(exec_)
		if exec_:
			return exec_
	raise ValueError('No Node.js Package Manager found.')

def bundle(no_compress, app=None, make_copy=False, restore=False, verbose=False):
	"""concat / minify js files"""
	setup()
	make_asset_dirs(make_copy=make_copy, restore=restore)

	pacman = get_node_pacman()
	mode = 'build' if no_compress else 'production'
	command = '{pacman} run {mode}'.format(pacman=pacman, mode=mode)

	if app:
		command += ' --app {app}'.format(app=app)

	frappe_app_path = abspath(join_path(app_paths[0], '..'))
	check_yarn()
	frappe.commands.popen(command, cwd=frappe_app_path)

def watch(no_compress):
	"""watch and rebuild if necessary"""
	setup()

	pacman = get_node_pacman()

	frappe_app_path = abspath(join_path(app_paths[0], '..'))
	check_yarn()
	frappe_app_path = frappe.get_app_path('frappe', '..')
	frappe.commands.popen('{pacman} run watch'.format(pacman=pacman), cwd = frappe_app_path)

def check_yarn():
	from distutils.spawn import find_executable
	if not find_executable('yarn'):
		print('Please install yarn using below command and try again.')
		print('npm install -g yarn')
		return

def make_asset_dirs(make_copy=False, restore=False):
	# don't even think of making assets_path absolute - rm -rf ahead.
	assets_path = join_path(frappe.local.sites_path, "assets")
	for dir_path in [
			join_path(assets_path, 'js'),
			join_path(assets_path, 'css')]:

		if not path_exists(dir_path):
			os.makedirs(dir_path)

	for app_name in frappe.get_all_apps(True):
		pymodule = frappe.get_module(app_name)
		app_base_path = abspath(os.path.dirname(pymodule.__file__))

		symlinks = []
		app_public_path = join_path(app_base_path, 'public')
		# app/public > assets/app
		symlinks.append([app_public_path, join_path(assets_path, app_name)])
		# app/node_modules > assets/app/node_modules
		if path_exists(abspath(app_public_path)):
			symlinks.append([join_path(app_base_path, '..', 'node_modules'), join_path(assets_path, app_name, 'node_modules')])

		app_doc_path = None
		if isdir(join_path(app_base_path, 'docs')):
			app_doc_path = join_path(app_base_path, 'docs')

		elif isdir(join_path(app_base_path, 'www', 'docs')):
			app_doc_path = join_path(app_base_path, 'www', 'docs')

		if app_doc_path:
			symlinks.append([app_doc_path, join_path(assets_path, app_name + '_docs')])

		for source, target in symlinks:
			source = abspath(source)
			if path_exists(source):
				if restore:
					if path_exists(target):
						if os.path.islink(target):
							os.unlink(target)
						else:
							shutil.rmtree(target)
						shutil.copytree(source, target)
				elif make_copy:
					if path_exists(target):
						warnings.warn('Target {target} already exists.'.format(target = target))
					else:
						shutil.copytree(source, target)
				else:
					if path_exists(target):
						if os.path.islink(target):
							os.unlink(target)
						else:
							shutil.rmtree(target)
					try:
						os.unlink(target)
						os.symlink(source, target)
					except OSError:
						print('Cannot link {} to {}'.format(source, target))
			else:
				# warnings.warn('Source {source} does not exist.'.format(source = source))
				pass

def build(no_compress=False, verbose=False):
	assets_path = join_path(frappe.local.sites_path, "assets")

{'fraction_non_alphanumeric': 0.12364345811486405, 'fraction_numerical': 0.0014632361907084503, 'mean_word_length': 4.739678096571029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4774762', 'n_tokens_mistral': 3303, 'n_tokens_neox': 2941, 'n_words': 646}