Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ref = os.path.join(output_path,
re.sub(r'\W+', '-', os.path.splitext(basename)[0]))
pagename = '%s.html' % ref
self.generated = generated
self.project_name = project_name
self.extension_name = extension_name
self.source_file = source_file
self.ast = ast
self.raw_contents = raw_contents
self.comment = comment
self.pre_sorted = pre_sorted
self.symbol_names = OrderedSet(symbol_names or [])
self.output_attrs = None
self.subpages = OrderedSet()
self.symbols = []
self.private_symbols = []
self.typed_symbols = OrderedDict()
self.by_parent_symbols = OrderedDict()
self.formatted_contents = None
self.detailed_description = None
self.build_path = None
self.cached_paths = OrderedSet()
if comment:
meta = comment.meta
elif meta:
meta = meta
else:
meta = {}
filename=sitemap.source_file,
lineno=position[0],
column=position[1])
ext = os.path.splitext(name)[1]
if ext == '.json':
self.project.add_subproject(name, source_file)
page = Page(
name, True, self.project.sanitized_name, 'core')
else:
page = self.parse_page(source_file, ext_name)
page.extension_name = extension.extension_name if extension else 'core'
self.__all_pages[name] = page
subpages = sitemap_pages.get(name, [])
page.subpages = OrderedSet(subpages) | page.subpages
if not page.meta.get('auto-sort', False):
page.pre_sorted = True
if ext_index:
self.add_unordered_subpages(extension, ext_index, ext_pages)
self.root = self.__all_pages[sitemap.index_file]
if self.sitemap_path is None:
error('invalid-config',
'No sitemap was provided')
self.include_paths = OrderedSet([])
index_file = config.get_index()
if index_file:
if not os.path.exists(index_file):
error('invalid-config',
'The provided index "%s" does not exist' %
index_file)
self.include_paths |= OrderedSet([os.path.dirname(index_file)])
self.include_paths |= OrderedSet(config.get_paths('include_paths'))
self.is_toplevel = toplevel
self.tree = Tree(self, self.app)
self.__create_extensions()
for extension in list(self.extensions.values()):
if toplevel:
extension.parse_toplevel_config(config)
extension.parse_config(config)
self.extra_asset_folders = OrderedSet(config.get_paths('extra_assets'))
"""Parses @config setting up @self state."""
self.sitemap_path = config.get_path('sitemap')
if self.sitemap_path is None:
error('invalid-config',
'No sitemap was provided')
self.include_paths = OrderedSet([])
index_file = config.get_index()
if index_file:
if not os.path.exists(index_file):
error('invalid-config',
'The provided index "%s" does not exist' %
index_file)
self.include_paths |= OrderedSet([os.path.dirname(index_file)])
self.include_paths |= OrderedSet(config.get_paths('include_paths'))
self.is_toplevel = toplevel
self.tree = Tree(self, self.app)
self.__create_extensions()
for extension in list(self.extensions.values()):
if toplevel:
extension.parse_toplevel_config(config)
extension.parse_config(config)
self.extra_asset_folders = OrderedSet(config.get_paths('extra_assets'))
def __resolve_patterns(self, source_patterns, from_conf):
if source_patterns is None:
return OrderedSet()
cache_key = self.__get_key(source_patterns, from_conf)
all_files = Config.__pattern_cache.get(cache_key, OrderedSet())
if all_files:
return all_files
for item in source_patterns:
item = self.__abspath(item, from_conf)
if item in all_files:
continue
if not os.path.exists(item):
all_files |= glob.glob(item)
else:
all_files.add(item)
Config.__pattern_cache[cache_key] = all_files
def prepare_page_attributes(self, page):
"""
Banana banana
"""
self._current_page = page
page.output_attrs['html']['scripts'] = OrderedSet()
page.output_attrs['html']['stylesheets'] = OrderedSet()
page.output_attrs['html']['extra_html'] = []
page.output_attrs['html']['edit_button'] = ''
page.output_attrs['html']['extra_footer_html'] = []
if Formatter.add_anchors:
page.output_attrs['html']['scripts'].add(
os.path.join(HERE, 'assets', 'css.escape.js'))
def __resolve_patterns(self, source_patterns, from_conf):
if source_patterns is None:
return OrderedSet()
cache_key = self.__get_key(source_patterns, from_conf)
all_files = Config.__pattern_cache.get(cache_key, OrderedSet())
if all_files:
return all_files
for item in source_patterns:
item = self.__abspath(item, from_conf)
if item in all_files:
continue
if not os.path.exists(item):
all_files |= glob.glob(item)
else:
all_files.add(item)
assert source_file
basename = os.path.basename(source_file)
name = os.path.splitext(basename)[0]
ref = os.path.join(output_path,
re.sub(r'\W+', '-', os.path.splitext(basename)[0]))
pagename = '%s.html' % ref
self.ast = ast
self.extension_name = None
self.source_file = source_file
self.raw_contents = raw_contents
self.comment = None
self.generated = False
self.pre_sorted = False
self.output_attrs = None
self.subpages = OrderedSet()
self.symbols = []
self.typed_symbols = OrderedDict()
self.by_parent_symbols = OrderedDict()
self.is_stale = True
self.formatted_contents = None
self.detailed_description = None
self.build_path = None
self.project_name = project_name
self.cached_paths = OrderedSet()
meta = meta or {}
try:
self.meta = Schema(Page.meta_schema).validate(meta)
except SchemaError as _:
warn('invalid-page-metadata',
Returns:
utils.utils.OrderedSet: The set of sources for the given
`prefix`.
"""
prefix = prefix.replace('-', '_')
prefixed = '%s_sources' % prefix
if prefixed in self.__cli:
sources = self.__cli.get(prefixed)
from_conf = False
else:
sources = self.__config.get(prefixed)
from_conf = True
if sources is None:
return OrderedSet()
sources = self.__resolve_patterns(sources, from_conf)
prefixed = '%s_source_filters' % prefix
if prefixed in self.__cli:
filters = self.__cli.get(prefixed)
from_conf = False
else:
filters = self.__config.get(prefixed)
from_conf = True
if filters is None:
return sources
sources -= self.__resolve_patterns(filters, from_conf)