citelang package

Submodules

citelang.defaults module

citelang.logger module

class citelang.logger.ColorizingStreamHandler(nocolor=False, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, use_threads=False)[source]

Bases: StreamHandler

BLACK = 0
BLUE = 4
BOLD_SEQ = '\x1b[1m'
COLOR_SEQ = '\x1b[%dm'
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
RESET_SEQ = '\x1b[0m'
WHITE = 7
YELLOW = 3
can_color_tty()[source]
colors = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'WARNING': 3}
decorate(record)[source]
emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

property is_tty
class citelang.logger.Logger[source]

Bases: object

cleanup()[source]
debug(msg)[source]
error(msg)[source]
exit(msg, return_code=1)[source]
handler(msg)[source]
info(msg)[source]
location(msg)[source]
progress(done=None, total=None)[source]
set_level(level)[source]
set_stream_handler(stream_handler)[source]
shellcmd(msg)[source]
text_handler(msg)[source]

The default snakemake log handler. Prints the output to the console. Args:

msg (dict): the log message dictionary

warning(msg)[source]
citelang.logger.setup_logger(quiet=False, printshellcmds=False, nocolor=False, stdout=False, debug=False, use_threads=False, wms_monitor=None)[source]
citelang.logger.spinner()[source]

Simple function to yield a spinner character

citelang.main module

citelang.main.base module

class citelang.main.base.BaseClient(quiet=False, **kwargs)[source]

Bases: object

A baseclient controls interactions with endpoints and the cache.

badge(template='static', *args, **kwargs)[source]

Generate a badge for a package

check_manager(name, use_cache=True)[source]

Check if a package manager is supported

credit(*args, **kwargs)[source]

Get the credit root node, then do additional graph parsing.

dependencies(manager, name, use_cache=True)[source]

Get dependencies for a package. If no version, use latest.

graph(fmt=None, *args, **kwargs)[source]

Generate a graph for a package.

credit_split is how to split credit between some package and its dependents. E.g., 0.5 means 50/50. 0.8 means the main package gets 80%, and dependencies split 20%. We go up until the min credit 0.05 at which case we stop adding.

package(manager, name, use_cache=True)[source]

Lookup a package in a specific package manager

package_managers(use_cache=True)[source]

Get a listing of package managers supported on libraries.io

citelang.main.client module

citelang.main.client.get_parser(filename=None, *args, **kwargs)[source]

Get a parser based on a filename. A GraphClient is required.

citelang.main.endpoints module

class citelang.main.endpoints.Dependencies(require_params=False, *args, **kwargs)[source]

Bases: Endpoint

dont_truncate = ['project_name']
emoji = 'arrow'
format_url = ['manager', 'package_name', 'version']
name = 'dependencies'
path = '/api/{manager}/{package_name}/{version}/dependencies'
skips = ['normalized_licenses']
table_data(data)[source]

A custom data parser, optionally if an endpoint needs to parse data further.

class citelang.main.endpoints.Endpoint(require_params=False, *args, **kwargs)[source]

Bases: object

dont_truncate = ['url']
emoji = 'sparkles'
format_params(**params)[source]
order(data)[source]
require_params(**kwargs)[source]
property skip_list
table_data(data)[source]

A custom data parser, optionally if an endpoint needs to parse data further.

property title
property truncate_list
property url
class citelang.main.endpoints.Package(require_params=False, *args, **kwargs)[source]

Bases: Endpoint

emoji = 'box'
format_url = ['manager', 'package_name']
name = 'package'
order(data)[source]

Order versions by published at

path = '/api/{manager}/{package_name}'
skips = ['repository_sources', 'spdx_expression', 'researched_at', 'original_license']
table_data(data)[source]

A custom data parser, optionally if an endpoint needs to parse data further.

property title
class citelang.main.endpoints.PackageManagers(require_params=False, *args, **kwargs)[source]

Bases: Endpoint

emoji = 'box'
name = 'package_managers'
path = '/api/platforms'
skips = ['color']
table_data(data)[source]

Ensure we don’t include any repeats and sort by name

citelang.main.endpoints.endpoint

alias of Dependencies

citelang.main.endpoints.get_endpoint(name, data=None, **kwargs)[source]

Get a named endpoint, optionally, using the cache (default)

citelang.main.package module

class citelang.main.package.CustomPackage(manager, name, version=None, data=None, use_cache=True, manager_kwargs=None)[source]

Bases: PackageBase

A wrapper for a custom package (provided by citelang)

dependencies(return_data=False)[source]

Retrieve custom package dependencies

property homepage
info()[source]

Get info for a custom package

class citelang.main.package.Package(manager, name, version=None, data=None, use_cache=True, manager_kwargs=None)[source]

Bases: PackageBase

A basic wrapper for package parsing functions (libraries.io)

dependencies(return_data=False)[source]

Retrieve libraries.io dependencies

info()[source]

Get info for a libraries.io package

class citelang.main.package.PackageBase(manager, name, version=None, data=None, use_cache=True, manager_kwargs=None)[source]

Bases: object

property cache_name
dependencies(return_data=False)[source]
property homepage
info()[source]
parse(name)[source]

Parse a manager and name into the package

citelang.main.package.get_package(manager, name, version=None, data=None, use_cache=True, manager_kwargs=None)[source]

Return a package handle for a custom package (defined in citelang) or libraries.io

citelang.main.result module

class citelang.main.result.Badge(result)[source]

Bases: Tree

This is an static badge that uses plotly.

print_result()[source]

Print a tree result (todo redo with color and rich)

save(outfile)[source]

Save to output file

class citelang.main.result.Graph(root)[source]

Bases: Result

A graph result can generate text for a graph

graph(fmt=None)[source]

Generate a graph of dependencies

class citelang.main.result.InteractiveBadge(result)[source]

Bases: Tree

A badge uses tree data with d3 for an interactive visualization

print_result()[source]

Print a tree result (todo redo with color and rich)

save(outfile)[source]

Save to output file

class citelang.main.result.Result(data, endpoint=None)[source]

Bases: object

A result holds the request result and can parse or return in different formats.

print_json()[source]
save(outfile)[source]

Save to output file

to_dict()[source]
class citelang.main.result.Table(data, endpoint=None)[source]

Bases: Result

A table is a result formatted as a table for the client.

available_width(columns)[source]

Calculate available width based on fields we cannot truncate (urls)

ensure_complete()[source]

If any data missing fields, ensure they are included

ensure_complete_list()[source]

Given a list result, check the fields.

table(limit=25)[source]

Pretty print a table of results.

table_columns()[source]

Shared function to return consistent table columns

table_rows(columns, limit=25)[source]

Shared function to yield rows as a list

class citelang.main.result.Tree(result)[source]

Bases: Result

parse_data()[source]

Parse result into data. The size is for d3, and makes each node relative to its siblings.

print_result()[source]

Print a tree result (todo redo with color and rich)

class citelang.main.result.Treemap(result)[source]

Bases: Tree

A treemap is an interactive tree.

print_result()[source]

Print a tree result (todo redo with color and rich)

save(outfile)[source]

Save to output file

citelang.main.schemas module

citelang.main.settings module

class citelang.main.settings.Settings(settings_file, validate=True)[source]

Bases: SettingsBase

The settings class is a wrapper for easily parsing a settings.yml file.

We parse into a query-able class. It also gives us control to update settings, meaning we change the values and then write them to file. It’s basically a dictionary-like class with extra functions.

class citelang.main.settings.SettingsBase(settings_file=None, validate=True)[source]

Bases: object

add(key, value)[source]

Add a value to a list parameter

change_validate(key, value)[source]

A courtesy function to validate a new config addition.

delete(key)[source]
edit()[source]

Interactively edit a config file.

get(key, default=None)[source]

Get a settings value, doing appropriate substitution and expansion.

get_settings_file(settings_file=None)[source]

Get the preferred user settings file, set user settings if exists.

inituser()[source]

Create a user specific config in user’s home.

load(settings_file=None)[source]

Load the settings file into the settings object

parse_boolean(value)[source]

If the value is True/False, ensure we return a boolean

parse_null(value)[source]

Given a null or none from the command line, ensure parsed as None type

remove(key, value)[source]

Remove a value from a list parameter

save(filename=None)[source]

Save settings, but do not change order of anything.

set(key, value)[source]

Set a setting based on key and value. If the key has :, it’s nested

update_param(command, param)[source]

Given a parameter, update the configuration on the fly if it’s in set/add/remove

update_params(params)[source]

Update a configuration on the fly (no save) only for set/add/remove. Unlike the traditional set/get/add functions, this function expects each entry in the params list to start with the action, e.g.:

set:name:value add:name:value rm:name:value

validate()[source]

Validate the loaded settings with jsonschema

citelang.main.settings.init_settings(validate=True)[source]

citelang.main.graph module

citelang.main.graph.base module

class citelang.main.graph.base.GraphBase(data, outfile=None)[source]

Bases: object

generate_placeholder()[source]

Generate a unique placeholder name for a node.

iter_nodes()[source]

Iterate nodes, yielding node, weight, and indentation

property outfile
parse()[source]

Create a flattened list of dependency names, and generate placeholder names

citelang.main.graph.cypher module

class citelang.main.graph.cypher.Cypher(data, outfile=None)[source]

Bases: GraphBase

generate()[source]

citelang.main.graph.dot module

class citelang.main.graph.dot.Dot(data, outfile=None)[source]

Bases: GraphBase

The dot format is for graphviz

generate(graphname=None, fontname='Arial')[source]

citelang.main.graph.gexf module

class citelang.main.graph.gexf.Gexf(data, outfile=None)[source]

Bases: GraphBase

generate()[source]

citelang.main.graph.text module

class citelang.main.graph.text.Console(data, outfile=None)[source]

Bases: GraphBase

generate()[source]

citelang.main.graph.tree module

citelang.main.graph.tree.generate_tree(next_node, icon, tree=None) None[source]

Recursively build a Tree with a dependency result

citelang.main.graph.tree.print_tree(root)[source]

citelang.main.packages module

citelang.main.packages.spack module

class citelang.main.packages.spack.SpackManager(*args, **kwargs)[source]

Bases: PackageManager

Packages from spack.

apiroot = 'https://packages.spack.io/data'
color = '#0f3a80'
default_language = None
default_versions = []
dependencies(name)[source]

Get dependencies for a spack package

Some package managers have separate endpoints for this, but we use the same package endpoint and return that data.

homepage = 'https://spack.github.io/packages'
name = 'spack'
package(name, **kwargs)[source]

Get metadata for a spack package. Try to format like libraries.io

property project_count

citelang.main.packages.github module

class citelang.main.packages.github.GitHubManager(*args, **kwargs)[source]

Bases: PackageManager

Packages from GitHub, either release, or branch.

apiroot = 'https://api.github.com'
clone(name)[source]

Clone a repository and sniff for dependency files.

color = '#000000'
default_language = None
default_versions = ['main', 'master', 'develop']
homepage = 'https://github.com'
name = 'github'
package(name, **kwargs)[source]
project_count = None
citelang.main.packages.github.find_dependencies(repo)[source]

Given a repository root, look for dependency files. We could use the GraphQL library, but this REQUIRES a GitHub token, which is kind of annoying. For now we are trying to scrape them :)

citelang.utils module

citelang.utils.fileio module

citelang.utils.fileio.get_tmpdir(tmpdir=None, prefix='', create=True)[source]

Get a temporary directory for an operation.

citelang.utils.fileio.get_tmpfile(tmpdir=None, prefix='')[source]

Get a temporary file with an optional prefix.

citelang.utils.fileio.mkdir_p(path)[source]

mkdir_p attempts to get the same functionality as mkdir -p :param path: the path to create.

citelang.utils.fileio.print_json(json_obj)[source]

Print json pretty

citelang.utils.fileio.read_file(filename, mode='r')[source]

Read a file.

citelang.utils.fileio.read_json(filename, mode='r')[source]

Read a json file to a dictionary.

citelang.utils.fileio.read_yaml(filename)[source]

Read yaml from file using the safe loader.

citelang.utils.fileio.workdir(dirname)[source]

Do something in the context of a directory, and then change back

citelang.utils.fileio.write_file(content, filename, mode='w', exec=False)[source]

Write content to a filename

citelang.utils.fileio.write_json(json_obj, filename, mode='w')[source]

Write json to a filename

citelang.utils.terminal module

citelang.utils.terminal.clone(name)[source]

Clone a repository by name

citelang.utils.terminal.confirm_action(question, force=False)[source]

confirm if the user wants to perform a certain action

Parameters

question: the question that will be asked force: if the user wants to skip the prompt

citelang.utils.terminal.confirm_uninstall(filename, force=False)[source]

confirm if the user wants to uninstall a module

Parameters

filename: the file that will be removed force: if the user wants to skip the prompt

citelang.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

citelang.utils.terminal.get_time_now()[source]

Get a timestring for the datetime now.

citelang.utils.terminal.run_command(cmd, sudo=False, stream=False)[source]

run_command uses subprocess to send a command to the terminal.

Parameters

cmd: the command to send, should be a list for subprocess error_message: the error message to give to user if fails, if none specified, will alert that command failed.

citelang.version module