Show Names of Everything in a Package

Show names of everything in a package

ls("package:foreach", all.names=TRUE) only shows what's attached to the search path, which only includes the objects exported from the namespace. Use ls on the results of getNamespace instead:

ls(getNamespace("foreach"), all.names=TRUE)

Is there a standard way to list names of Python modules in a package?

Maybe this will do what you're looking for?

import imp
import os
MODULE_EXTENSIONS = ('.py', '.pyc', '.pyo')

def package_contents(package_name):
file, pathname, description = imp.find_module(package_name)
if file:
raise ImportError('Not a package: %r', package_name)
# Use a set because some may be both source and compiled.
return set([os.path.splitext(module)[0]
for module in os.listdir(pathname)
if module.endswith(MODULE_EXTENSIONS)])

Is there a command in R to view all the functions present in a package?

You can use lsf.str.

For instance:

lsf.str("package:dplyr")

To list all objects in the package use ls

ls("package:dplyr")

Note that the package must be attached.

To see the list of currently loaded packages use

search()

Alternatively calling the help would also do, even if the package is not attached:

help(package = dplyr)

Finally, you can use RStudio which provides an autocomplete function. So, for instance, typing dplyr:: in the console or while editing a file will result in a popup list of all dplyr functions/objects.

List all the files included in a python package (equivalent to 'git ls-files')

If you mean the distribution package archive — it depends on the archive type. A wheel (.whl extension) or an sdist with .zip extension are zip archives so use unzip -l dist-file.zip. For an sdist with .tar.gz extension use tar -tavf dist-file.tgz or tar -tzvf dist-file.tar.gz (option -a to auto-recognize archive type, -z to force gzip compression).

To list installed files — see the file site-packages/<package>-<version>.dist-info/RECORD. To find out where site-packages is run pip show package-name | grep -F Location:

To list all the files included in the package even before creating the whl or sdist run python setup.py bdist --dry-run. The command lists files that will be packaged without creating a real package. For example:

$ git clone https://github.com/mtchavez/python-package-boilerplate.git
Cloning into 'python-package-boilerplate'...
remote: Enumerating objects: 116, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 116 (delta 0), reused 0 (delta 0), pack-reused 112
Receiving objects: 100% (116/116), 14.03 KiB | 388.00 KiB/s, done.
Resolving deltas: 100% (41/41), done.

$ cd python-package-boilerplate/

$ python setup.py bdist -n
running bdist
running bdist_dumb
running build
running build_py
file packagename.py (for module packagename) not found
file packagename.py (for module packagename) not found
installing to build/bdist.linux-x86_64/dumb
running install
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

running install_egg_info
running egg_info
creating py_boilerplate.egg-info
writing py_boilerplate.egg-info/PKG-INFO
writing top-level names to py_boilerplate.egg-info/top_level.txt
writing dependency_links to py_boilerplate.egg-info/dependency_links.txt
writing manifest file 'py_boilerplate.egg-info/SOURCES.txt'
file packagename.py (for module packagename) not found
reading manifest file 'py_boilerplate.egg-info/SOURCES.txt'
writing manifest file 'py_boilerplate.egg-info/SOURCES.txt'
Copying py_boilerplate.egg-info to build/bdist.linux-x86_64/dumb/home/phd/.local/lib/python2.7/site-packages/py_boilerplate-1.0.0-py2.7.egg-info
running install_scripts
creating /home/phd/tmp/python-package-boilerplate/dist
Creating tar archive
removing 'build/bdist.linux-x86_64/dumb' (and everything under it)

PS. All commands are for Unix/Linux command line.

List of functions of a package

The closest thing I've been able to find for this is:

help(,"rjags")

The first parameter specifies the searched thing, second one specifies the package. By keeping only the second one, I hope to get all help pages that relate to that package. This is equivalent of

help(package = "rjags")

This might not work in general though, as in ?help the functionality of omitting the first parameter is described as

topic is not optional: if it is omitted R will give

  • If a package is specified, (text or, in interactive use only, HTML) information on the package, including hints/links to suitable help

    topics.

How to list all functions in a module?

Use the inspect module:

from inspect import getmembers, isfunction

from somemodule import foo
print(getmembers(foo, isfunction))

Also see the pydoc module, the help() function in the interactive interpreter and the pydoc command-line tool which generates the documentation you are after. You can just give them the class you wish to see the documentation of. They can also generate, for instance, HTML output and write it to disk.

Get a list of the all the names of the objects in the datasets R package?

There is a note on the ?data help page that states

Where the datasets have a different name from the argument that should be used to retrieve them the index will have an entry like beaver1 (beavers) which tells us that dataset beaver1 can be retrieved by the call data(beavers).

So the actual object name is the thing before the parentheses at the end. Since that value is returned as just a string, that's something you'll need to remove yourself unfortunately. But you can do that with a gsub

datanames <- data(package="datasets")$results[,"Item"]
objnames <- gsub("\\s+\\(.*\\)","", datanames)

for(ds in objnames) {
print(get(ds))
cat("\n\n")
}

How to list all classes and methods/functions in a package - with a full folder/file path?

Heres an example on how to do it:

import inspect
import TestModule


def recusive_module_search(module):
members = inspect.getmembers(module)

for name, member in members:
if inspect.ismodule(member):
# Dont go too deep :)
if member is module:
recusive_module_search(member)
elif inspect.isfunction(member):
file = inspect.getfile(member)
print(file, function_signature_string(member), "function")
elif inspect.isclass(member):
file = inspect.getfile(member)
print(file, function_signature_string(member), "class")
class_members = inspect.getmembers(member)
for name, class_member in class_members:
if inspect.isfunction(class_member):
member_args = inspect.signature(class_member)
print(file, member.__name__ + "." + function_signature_string(class_member), "method")

def function_signature_string(member):
parameters = inspect.signature(member).parameters
return member.__name__ + "(" + ', '.join(str(x) for x in parameters.values()) + ")"

recusive_module_search(TestModule)

output:

C:\Users\mclea\src\PydanticMongoEngine\TestModule\functions.py Test(x: int, y: float) class
C:\Users\mclea\src\PydanticMongoEngine\TestModule\functions.py Test.__init__(self, x: int, y: float) method
C:\Users\mclea\src\PydanticMongoEngine\TestModule\functions.py Test.print_x(self) method
C:\Users\mclea\src\PydanticMongoEngine\TestModule\functions.py hi(x: int) function
C:\Users\mclea\src\PydanticMongoEngine\TestModule\SubModule\test.py test_fn(hello: str) function

Continue as desired :)

How to get the package name of a function in R?

Perhaps even most convenient, if you are just after the package name:

environmentName(environment(select))

The advantage is that this produces a string rather than an environment object.



Related Topics



Leave a reply



Submit