Reference

nodeps

NoDeps Helpers and Utils Module.

nodeps.getstdout(func, *args, ansi=False, new=True, **kwargs)[source]

Redirect stdout for func output and remove ansi and/or new line.

Parameters:
  • func (Callable) – callable.

  • *args (Any) – args to callable.

  • ansi (bool) – strip ansi.

  • new (bool) – strip new line.

  • **kwargs (Any) – kwargs to callable.

Return type:

str | Iterable[str, str]

nodeps.strip(obj, ansi=False, new=True)[source]

Strips \n And/Or Ansi from string or Iterable.

Parameters:
  • obj (str | Iterable[str]) – object or None for redirect stdout

  • ansi (bool) – ansi (default: False)

  • new (bool) – newline (default: True)

Returns:

Same type with NEWLINE removed.

Return type:

str | Iterable[str]

nodeps.ic(*a)[source]

Include Context.

nodeps.icc(*a)[source]

Include Context.

nodeps.black(msg='', bold=False, underline=False, blink=False, err=False)[source]

black.

nodeps.red(msg='', bold=False, underline=False, blink=False, err=True)[source]

red.

nodeps.green(msg='', bold=False, underline=False, blink=False, err=False)[source]

green.

nodeps.yellow(msg='', bold=False, underline=False, blink=False, err=False)[source]

yellow.

nodeps.blue(msg='', bold=False, underline=False, blink=False, err=False)[source]

blue.

nodeps.magenta(msg='', bold=False, underline=False, blink=False, err=False)[source]

magenta.

nodeps.cyan(msg='', bold=False, underline=False, blink=False, err=False)[source]

cyan.

nodeps.white(msg='', bold=False, underline=False, blink=False, err=False)[source]

white.

nodeps.bblack(msg='', bold=False, underline=False, blink=False, err=False)[source]

bblack.

nodeps.bred(msg='', bold=False, underline=False, blink=False, err=False)[source]

bred.

nodeps.bgreen(msg='', bold=False, underline=False, blink=False, err=False)[source]

bgreen.

nodeps.byellow(msg='', bold=False, underline=False, blink=False, err=False)[source]

byellow.

nodeps.bblue(msg='', bold=False, underline=False, blink=False, err=False)[source]

bblue.

nodeps.bmagenta(msg='', bold=False, underline=False, blink=False, err=False)[source]

bmagenta.

nodeps.bcyan(msg='', bold=False, underline=False, blink=False, err=False)[source]

bcyan.

nodeps.bwhite(msg='', bold=False, underline=False, blink=False, err=False)[source]

bwhite.

nodeps.reset(msg='', bold=False, underline=False, blink=False, err=False)[source]

reset.

class nodeps.EnumLower(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

EnumLower class.

class nodeps.Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: _Color

click.secho() and click.style() foreground color wrapper class.

BLACK = 'black'

might be a gray

BLUE = 'blue'
CYAN = 'cyan'
GREEN = 'green'
MAGENTA = 'magenta'
RED = 'red'
WHITE = 'white'

might be an grey

YELLOW = 'yellow'

might be an orange

BRIGHT_BLACK = 'bright_black'
BRIGHT_BLUE = 'bright_blue'
BRIGHT_CYAN = 'bright_cyan'
BRIGHT_GREEN = 'bright_green'
BRIGHT_MAGENTA = 'bright_magenta'
BRIGHT_RED = 'bright_red'
BRIGHT_WHITE = 'bright_white'
BRIGHT_YELLOW = 'bright_yellow'
RESET = 'reset'

bold, underline, etc.

Type:

reset the color only, not styles

style(text, bg=None, bold=None, dim=None, underline=None, overline=None, italic=None, blink=None, reverse=None, strikethrough=None, reset=True)[source]

Wrapper for click.style() getting the fg color from the enum.

Styles a text with ANSI styles and returns the new string.

By default, the styling is self-contained which means that at the end of the string a

reset code is issued (this can be prevented by passing reset=False.

If the terminal supports it, color may also be specified as:

  • An integer in the interval [0, 255]. The terminal must support 8-bit/256-color mode.

  • An RGB tuple of three integers in [0, 255]. The terminal must support 24-bit/true-color mode

See click.style for more information.

Parameters:
  • text (Any) – Text to apply style

  • bg (str | int | tuple[int, int, int] | None) – Background color (default: None)

  • bold (bool | None) – Bold text (default: None)

  • dim (bool | None) – Dim (default: None)

  • underline (bool | None) – Underline (default: None)

  • overline (bool | None) – Overline (default: None)

  • italic (bool | None) – Italic (default: None)

  • blink (bool | None) – Blink (default: None)

  • reverse (bool | None) – Reverse (default: None)

  • strikethrough (bool | None) – Strikethrough (default: None)

  • reset (bool) – Reset (default: True)

Returns:

Formatted text

Return type:

str

class nodeps.Symbol(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: _Symbol

click.echo() and click.style() wrapper class for SYMBOLS.

Examples

>>> from nodeps import Symbol
>>>
>>> Symbol.OK() # OK
>>>
>>> Symbol.OK("Install")  # OK Install
>>>
>>> Symbol.OK("Install", "Complete")  # OK Install: Complete
>>>
>>> Symbol.OK("Install", "Complete", stderr=False)  
>>>
>>> Symbol.OK("Debug", "Error", " |", stderr=False)  
>>>
>>> Symbol.OK("Value", "2", " ==", file="/tmp/test.txt")  
>>>
>>> Symbol.OK("Value", "2", newline=False)  # OK Value: 2
CRITICAL = '\x1b[31m\x1b[1m\x1b[5mCRITICAL\x1b[0m'

YELLOW (blink)

Type:

symbol

Type:

‘…’, color

ERROR = '\x1b[31m\x1b[1mERROR\x1b[0m'

RED

Type:

symbol

Type:

‘✘’, color

OK = '\x1b[32m\x1b[1mOK\x1b[0m'

GREEN

Type:

symbol

Type:

‘✔’, color

NOTICE = '\x1b[36m\x1b[1mNOTICE\x1b[0m'

CYAN

Type:

symbol

Type:

‘‼’, color

SUCCESS = '\x1b[34m\x1b[1mSUCCESS\x1b[0m'

BLUE

Type:

symbol

Type:

‘◉’, color

VERBOSE = '\x1b[35m\x1b[1mVERBOSE\x1b[0m'

MAGENTA

Type:

symbol

Type:

‘+’, color

WARNING = '\x1b[33m\x1b[1mWARNING\x1b[0m'

YELLOW

Type:

symbol

Type:

‘!’, color

MINUS = '\x1b[31m\x1b[1mMINUS\x1b[0m'

RED

Type:

letter

Type:

‘-’, color

MORE = '\x1b[35m\x1b[1mMORE\x1b[0m'

MAGENTA

Type:

letter

Type:

‘>, color

MULTIPLY = '\x1b[34m\x1b[1mMULTIPLY\x1b[0m'

BLUE

Type:

letter

Type:

‘x’, color

PLUS = '\x1b[31m\x1b[1mPLUS\x1b[0m'

GREEN

Type:

letter

Type:

‘+’, color

WAIT = '\x1b[33m\x1b[1mWAIT\x1b[0m'

YELLOW (blink)

Type:

symbol

Type:

‘…’, color

nodeps.logger(fmt='<level>{level: <8}</level> <red>|</red> <cyan>{name}</cyan> <red>|</red> <red>|</red> <level>{message}</level>')[source]

Returns a new logger.

Examples

>>> from nodeps import logger
>>>
>>> l = logger("<level>{level: <8}</level> <red>|</red> "
...     "<cyan>{name}</cyan> <red>|</red> "
...     "<blue><level>{message}</level></blue><red>:</red> "
...     "<level>{extra[source]}</level> <red>-></red> "
...     "<level>{extra[destination]}</level>")
>>> l.info("test", source="source", destination="destination")
nodeps.cache(func=Ellipsis)[source]

Caches previous calls to the function if object can be encoded.

Examples

>>> import asyncio
>>> from typing import cast
>>> from typing import Coroutine
>>> from environs import Env as Environs
>>> from collections import namedtuple
>>> from nodeps import cache
>>>
>>> @cache
... def test(a):
...     print(True)
...     return a
>>>
>>> @cache
... async def test_async(a):
...     print(True)
...     return a
>>>
>>> test({})
True
{}
>>> test({})
{}
>>> asyncio.run(cast(Coroutine, test_async({})))
True
{}
>>> asyncio.run(cast(Coroutine, test_async({})))
{}
>>> test(Environs())
True
<Env {}>
>>> test(Environs())
<Env {}>
>>> asyncio.run(cast(Coroutine, test_async(Environs())))
True
<Env {}>
>>> asyncio.run(cast(Coroutine, test_async(Environs())))
<Env {}>
>>>
>>> @cache
... class Test:
...     def __init__(self, a):
...         print(True)
...         self.a = a
...
...     @property
...     @cache
...     def prop(self):
...         print(True)
...         return self
>>>
>>> Test({})  
True
<....Test object at 0x...>
>>> Test({})  
<....Test object at 0x...>
>>> Test({}).a
{}
>>> Test(Environs()).a
True
<Env {}>
>>> Test(Environs()).prop  
True
<....Test object at 0x...>
>>> Test(Environs()).prop  
<....Test object at 0x...>
>>>
>>> Test = namedtuple('Test', 'a')
>>> @cache
... class TestNamed(Test):
...     __slots__ = ()
...     def __new__(cls, *args, **kwargs):
...         print(True)
...         return super().__new__(cls, *args, **kwargs)
>>>
>>> TestNamed({})
True
TestNamed(a={})
>>> TestNamed({})
TestNamed(a={})
>>> @cache
... class TestNamed(Test):
...     __slots__ = ()
...     def __new__(cls, *args, **kwargs): return super().__new__(cls, *args, **kwargs)
...     def __init__(self): super().__init__()
>>> TestNamed({}) 
Traceback (most recent call last):
TypeError: __init__() takes 1 positional argument but 2 were given
Parameters:

func (Callable[[...], _T | Coroutine[Any, Any, _T]])

Return type:

Callable[[Callable[[…], _T]], _CacheWrapper[_T]] | _T | Coroutine[Any, Any, _T] | Any

nodeps.ins(obj, *, _console=None, title=None, _help=False, methods=True, docs=False, private=True, dunder=False, sort=True, _all=False, value=True)[source]

Wrapper rich.inspect() for rich._inspect.Inspect.

Changing defaults to: docs=False, methods=True, private=True.

Inspect any Python object.

Examples

>>> from nodeps import ins
>>>
>>> # to see summarized info.
>>> ins(ins)  
>>> # to not see methods.
>>> ins(ins, methods=False)  
>>> # to see full (non-abbreviated) help.
>>> ins(ins, help=True)  
>>> # to not see private attributes (single underscore).
>>> ins(ins, private=False)  
>>> # to see attributes beginning with double underscore.
>>> ins(ins, dunder=True)  
>>> # to see all attributes.
>>> ins(ins, _all=True)  
'
Parameters:
  • obj (Any) – An object to inspect.

  • _console (Console, optional) – Rich Console.

  • title (str, optional) – Title to display over inspect result, or None use type. Defaults to None.

  • _help (bool, optional) – Show full help text rather than just first paragraph. Defaults to False.

  • methods (bool, optional) – Enable inspection of callables. Defaults to False.

  • docs (bool, optional) – Also render doc strings. Defaults to True.

  • private (bool, optional) – Show private attributes (beginning with underscore). Defaults to False.

  • dunder (bool, optional) – Show attributes starting with double underscore. Defaults to False.

  • sort (bool, optional) – Sort attributes alphabetically. Defaults to True.

  • _all (bool, optional) – Show all attributes. Defaults to False.

  • value (bool, optional) – Pretty print value. Defaults to True.

nodeps.is_idlelib()[source]

Is idle repl.

Return type:

bool

nodeps.is_repl()[source]

Check if it is a repl.

Return type:

bool

nodeps.is_terminal(self=None)[source]

Patch for rich console is terminal.

Examples

>>> import time
>>> from rich.console import Console
>>> from rich.json import JSON
>>> from rich import print_json
>>>
>>> c = Console()
>>> with c.status("Working...", spinner="material"):  
...    time.sleep(2)
>>>
>>> c.log(JSON('["foo", "bar"]'))  
>>>
>>> print_json('["foo", "bar"]')  
>>>
>>> c.log("Hello, World!")  
>>> c.print([1, 2, 3])  
>>> c.print("[blue underline]Looks like a link")  
>>> c.print(locals())  
>>> c.print("FOO", style="white on blue")  
>>>
>>> blue_console = Console(style="white on blue")  
>>> blue_console.print("I'm blue. Da ba dee da ba di.")  
>>>
>>> c.input("What is [i]your[/i] [bold red]name[/]? :smiley: ")  

References

Test with: print(“[italic red]Hello[/italic red] World!”, locals())

Rich Inspect

rich.traceback.install(suppress=[click])

To see the spinners: python -m rich.spinner To print json from the comamand line: python -m rich.json cats.json

Rich Console

Input: console.input(“What is [i]your[/i] [bold red]name[/]? :smiley: “)

Parameters:

self (Console | BinaryIO | BufferedRandom | BufferedReader | BufferedWriter | FileIO | IO | TextIOWrapper | None)

Return type:

bool

nodeps.rich_install()[source]

Install rich.

class nodeps.Repo(path=None, expand_vars=True, odbt=None, search_parent_directories=True)[source]

Bases: object

Dataclass Wrapper for git.Repo.

Represents a git repository and allows you to query references, gather commit information, generate diffs, create and clone repositories query the log.

‘working_tree_dir’ is the working tree directory, but will raise AssertionError if we are a bare repository.

Examples

>>> from nodeps.extras.repo import Repo
>>>
>>> repo = Repo()  
>>> repo.config_writer().set_value("user", "name", "root").release()  
Parameters:
  • path (dataclasses.InitVar[Union[os.PathLike, ~AnyStr, IO[~AnyStr], NoneType]])

  • expand_vars (dataclasses.InitVar[bool])

  • odbt (dataclasses.InitVar[type[None]])

  • search_parent_directories (dataclasses.InitVar[bool])

git: None

The Repo class manages communication with the Git binary.

It provides a convenient interface to calling the Git binary, such as in:

g = Repo( git_dir )
g.init()                   # calls 'git init' program
rval = g.ls_files()        # calls 'git ls-files' program
Debugging

Set the GIT_PYTHON_TRACE environment variable print each invocation of the command to stdout. Set its value to ‘full’ to see details about the returned values.

git_dir: PathLike | AnyStr | IO | None = None

the .git repository directory, which is always set

odb: type[None]
working_dir: PathLike | AnyStr | IO | None = None

working directory of the git command, which is the working tree directory if available or the .git directory in case of bare repositories

path: dataclasses.InitVar[Union[os.PathLike, AnyStr, IO[AnyStr], NoneType]] = None

File or Directory inside the git repository, the default with search_parent_directories

expand_vars: dataclasses.InitVar[bool] = True
odbt: dataclasses.InitVar[type[None]] = None

the path to either the root git directory or the bare git repo

search_parent_directories: dataclasses.InitVar[bool] = True

if True, all parent directories will be searched for a valid repo as well.

property git_config

Wrapper for git.Repo.config_reader(), so it is already read and can be used.

The configuration will include values from the system, user and repository configuration files.

Examples

>>> import nodeps
>>> from nodeps import Repo, Path
>>>
>>> if not Path(nodeps.__file__).installed():
...     conf = Repo(__file__).git_config
...     assert conf.has_section('remote "origin"') is True
...     assert conf.has_option('remote "origin"', 'url') is True
...     assert 'https://github.com/' in conf.get('remote "origin"', 'url')
...     assert 'https://github.com/' in conf.get_value('remote "origin"', 'url', "")
Returns:

GitConfigParser instance

Return type:

GitConfigParser

property origin_url

Git Origin URL.

Examples

>>> import nodeps
>>> from nodeps import Repo, Path
>>>
>>> if not Path(nodeps.__file__).installed():
...     assert 'https://github.com' in Repo(nodeps.__file__).origin_url.geturl()
property top

Repo Top Directory Path.

nodeps.python_latest(start=None)[source]

Python latest version avaialble.

Examples

>>> import platform
>>> from nodeps import python_latest
>>>
>>> v = platform.python_version()
>>> if "rc" not in v:
...     major_minor = v.rpartition(".")[0]
...     assert python_latest(v).rpartition(".")[0] == major_minor
...     assert python_latest(v).rpartition(".")[2] >= v.rpartition(".")[2]
...     assert python_latest(major_minor).rpartition(".")[0] == major_minor
...     assert python_latest(major_minor).rpartition(".")[2] >= v.rpartition(".")[2]
Parameters:

start (str | int | None) – version startswith match, i.e.: “3”, “3.10”, “3.10”, 3 or None to use PYTHON_VERSION environment variable or :obj:sys.version if not set (Default: None).

Returns:

Latest Python Version

Return type:

str

nodeps.python_version()[source]

Major Minor Version $PYTHON_VERSION, $PYTHON_REQUIRES, PYTHON_DEFAULT_VERSION or sys.version.

Examples

>>> import os
>>> import platform
>>> from nodeps import python_version
>>>
>>> v = python_version()
>>> assert platform.python_version().startswith(v)
>>> assert len(v.split(".")) == 2
>>>
>>> os.environ["PYTHON_VERSION"] = "3.10"
>>> assert python_version() == "3.10"
>>>
>>> os.environ["PYTHON_VERSION"] = "3.12-dev"
>>> assert python_version() == "3.12-dev"
>>>
>>> os.environ["PYTHON_VERSION"] = "3.12.0b4"
>>> assert python_version() == "3.12"
Returns:

str

Return type:

str

nodeps.python_versions()[source]

Python versions avaialble.

Examples

>>> import platform
>>> from nodeps import python_versions
>>>
>>> v = platform.python_version()
>>> if not "rc" in v:
...     assert v in python_versions()
Returns:

Tuple of Python Versions

Return type:

list[str]

nodeps.request_x_api_key_json(url, key='')[source]

API request helper with API Key and returning json.

Examples

>>> from nodeps import request_x_api_key_json
>>>
>>> request_x_api_key_json("https://api.iplocation.net/?ip=8.8.8.8",                 "rn5ya4fp/tzI/mENxaAvxcMo8GMqmg7eMnCvUFLIV/s=")
{'ip': '8.8.8.8', 'ip_number': '134744072', 'ip_version': 4, 'country_name': 'United States of America', 'country_code2': 'US', 'isp': 'Google LLC', 'response_code': '200', 'response_message': 'OK'}
Parameters:
  • url – API url

  • key (str) – API Key

Returns:

response json

Return type:

dict[str, str] | None

nodeps.IPYTHONConfigType

alias of Config

nodeps.IPYTHONType

alias of object

nodeps.to_sys_path(path=None)[source]

Prepend path to sys.path if not in sys.path.

Parameters:

path (Path | str | None) – path to add, default None

Returns:

new sys.path

Return type:

list[str]

class nodeps.Chain(*maps, rv='unique', default=None)[source]

Bases: ChainMap

Variant of chain that allows direct updates to inner scopes and returns more than one value, not the first one.

Examples

>>> from nodeps import Chain
>>>
>>> class Test3:
...     a = 2
>>>
>>> class Test4:
...     a = 2
>>>
>>> Test1 = collections.namedtuple('Test1', 'a b')
>>> Test2 = collections.namedtuple('Test2', 'a d')
>>> test1 = Test1(1, 2)
>>> test2 = Test2(3, 5)
>>> test3 = Test3()
>>> test4 = Test4()
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2))]
>>> chain = Chain(*maps)
>>> assert chain['a'] == [1, 2, 3, {'z': 1}, {'z': 2}]
>>> chain = Chain(*maps, rv="first")
>>> assert chain['a'] == 1
>>> chain = Chain(*maps, rv="all")
>>> assert chain['a'] == [1, 2, 3, {'z': 1}, {'z': 1}, {'z': 2}]
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),        dict(a=dict(z=2)), test1, test2]
>>> chain = Chain(*maps)
>>> assert chain['a'] == [1, 2, 3, {'z': 1}, {'z': 2}]
>>> chain = Chain(*maps, rv="first")
>>> assert chain['a'] == 1
>>> chain = Chain(*maps, rv="all")
>>> assert chain['a'] == [1, 2, 3, {'z': 1}, {'z': 1}, {'z': 2}, 1, 3]
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test2]
>>> chain = Chain(*maps)
>>> del chain['a']
>>> assert chain == Chain({'b': 2}, {'c': 3}, {'d': 4}, test1, test2)
>>> assert chain['a'] == [1, 3]
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test2]
>>> chain = Chain(*maps)
>>> assert chain.delete('a') == Chain({'b': 2}, {'c': 3}, {'d': 4}, test1, test2)
>>> assert chain.delete('a')['a'] == [1, 3]
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test2]
>>> chain = Chain(*maps, rv="first")
>>> del chain['a']
>>> del maps[0]['a'] 
Traceback (most recent call last):
KeyError:
>>>
>>> assert chain['a'] == 2
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test2]
>>> chain = Chain(*maps, rv="first")
>>> new = chain.delete('a')
>>> del maps[0]['a'] 
Traceback (most recent call last):
KeyError:
>>> assert new.delete('a')
>>> del maps[1]['a'] 
Traceback (most recent call last):
KeyError:
>>>
>>> assert new['a'] == 3
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test3]
>>> chain = Chain(*maps)
>>> del chain['a']
>>> assert chain[4] == []
>>> assert not hasattr(test3, 'a')
>>> assert chain.set('a', 9)
>>> assert chain['a'] == [9, 1]
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test4]
>>> chain = Chain(*maps)
>>> chain.set('j', 9)  
Chain({'a': 1, 'b': 2, 'j': 9}, {'a': 2, 'c': 3}, {'a': 3, 'd': 4}, {'a': {'z': 1}}, {'a': {'z': 1}}, {'a': {'z': 2}}, Test1(a=1, b=2), <....Test4 object at 0x...>)
>>> assert [maps[0]['j']] == chain['j'] == [9]
>>> chain.set('a', 10)  
Chain({'a': 10, 'b': 2, 'j': 9}, {'a': 10, 'c': 3}, {'a': 10, 'd': 4}, {'a': 10}, {'a': 10}, {'a': 10}, Test1(a=1, b=2), <....Test4 object at 0x...>)
>>> # noinspection PyUnresolvedReferences
>>> assert [maps[0]['a'], 1] == chain['a'] == [maps[7].a, 1] == [10, 1]  # 1 from namedtuple
>>>
>>> maps = [dict(a=1, b=2), dict(a=2, c=3), dict(a=3, d=4), dict(a=dict(z=1)), dict(a=dict(z=1)),         dict(a=dict(z=2)), test1, test4]
>>> chain = Chain(*maps, rv="first")
>>> chain.set('a', 9)  
Chain({'a': 9, 'b': 2}, {'a': 2, 'c': 3}, {'a': 3, 'd': 4}, {'a': {'z': 1}}, {'a': {'z': 1}}, {'a': {'z': 2}}, Test1(a=1, b=2), <....Test4 object at 0x...>)
>>> assert maps[0]['a'] == chain['a'] == 9
>>> assert maps[1]['a'] == 2

Init.

Parameters:
  • rv (ChainLiteral)

  • default (Any)

maps: list[Iterable | NamedtupleMeta | MutableMapping] = []
rv: ChainLiteral = 'unique'
default: Any = None
delete(key)[source]

Delete item.

Parameters:

key (Hashable)

Return type:

Chain

set(key, value)[source]

Set item.

Parameters:
  • key (Hashable)

  • value (Any)

Return type:

Chain

class nodeps.ColorLogger(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

Color logger class.

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

black = '\x1b[30m'
blue = '\x1b[34m'
cyan = '\x1b[36m'
gr = '\x1b[32m'
grey = '\x1b[38;21m'
mg = '\x1b[35m'
red = '\x1b[31;21m'
red_bold = '\x1b[31;1m'
reset = '\x1b[0m'
white = '\x1b[37m'
yellow = '\x1b[33;21m'
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)'
vertical = '\x1b[31;21m|\x1b[0m '
FORMATS: ClassVar[dict[int, str]] = {10: '\x1b[38;21m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 20: '\x1b[36m%(levelname)8s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[36m%(name)s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[36m%(filename)s\x1b[0m:\x1b[36m%(lineno)d\x1b[0m \x1b[31;21m|\x1b[0m \x1b[32m%(extra)s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[36m%(message)s\x1b[0m', 30: '\x1b[33;21m%(levelname)8s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[33;21m%(name)s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[33;21m%(filename)s\x1b[0m:\x1b[33;21m%(lineno)d\x1b[0m \x1b[31;21m|\x1b[0m \x1b[32m%(repo)s\x1b[0m \x1b[31;21m|\x1b[0m \x1b[33;21m%(message)s\x1b[0m', 40: '\x1b[31;21m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m', 50: '\x1b[31;1m%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)\x1b[0m'}
format(record)[source]

Format log.

classmethod logger(name='nodeps.modules.classes')[source]

Get logger.

Examples

>>> from nodeps import ColorLogger
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> lo = ColorLogger.logger(NODEPS_PROJECT_NAME)
>>> lo.info("hola", extra=dict(extra="bapy"))
>>> lo.info("hola")
Parameters:

name (str) – logger name

Returns:

logging.Logger

Return type:

Logger

class nodeps.ConfigParser(defaults=None, dict_type=<class 'dict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)[source]

Bases: ConfigParser

Config parser to get list from setup.cfg.

getlist(section='options', option='scripts')[source]

Get list.

Parameters:
Return type:

list

setlist(section='options', option='scripts', value=None)[source]

Set list.

Parameters:
class nodeps.dd(factory=None, *args, **kwargs)[source]

Bases: defaultdict

Default Dict Helper Class.

Examples

>>> from nodeps import dd
>>>
>>> d = dd()
>>> d
dd(None, {})
>>> d[1]
>>> d.get(1)
>>>
>>> d = dd({})
>>> d
dd(None, {})
>>> d[1]
>>> d.get(1)
>>>
>>> d = dd({}, a=1)
>>> d
dd(None, {'a': 1})
>>> d[1]
>>> d.get(1)
>>>
>>> d = dd(dict)
>>> d
dd(<class 'dict'>, {})
>>> d.get(1)
>>> d
dd(<class 'dict'>, {})
>>> d[1]
{}
>>> d
dd(<class 'dict'>, {1: {}})
>>> d = dd(tuple)
>>> d
dd(<class 'tuple'>, {})
>>> d[1]
()
>>> d.get(1)
()
>>>
>>> d = dd(True)
>>> d
dd(True, {})
>>> d[1]
True
>>> d.get(1)
True
>>>
>>> d = dd({1: 1}, a=1)
>>> d
dd(None, {1: 1, 'a': 1})
>>> d[1]
1
>>> d.get(1)
1
>>>
>>> d = dd(list, {1: 1}, a=1)
>>> d
dd(<class 'list'>, {1: 1, 'a': 1})
>>> d[2]
[]
>>> d
dd(<class 'list'>, {1: 1, 'a': 1, 2: []})
>>>
>>> d = dd(True, {1: 1}, a=1)
>>> d
dd(True, {1: 1, 'a': 1})
>>> d.get('c')
>>> d['c']
True

Init.

Parameters:
  • factory (Union[Callable, Any])

  • args (Any)

  • kwargs (Any)

class nodeps.dictsort(*args, **kwargs)[source]

Bases: dict, MutableMapping[_KT, _VT]

Dict Sort Class.

Examples

>>> from nodeps import dictsort
>>>
>>> d = dictsort(b=1, c=2, a=3)
>>> assert d.sort() == dictsort({'a': 3, 'b': 1, 'c': 2})

Init.

Parameters:
  • args (Any)

  • kwargs (Any)

sort()[source]

Sort.

Return type:

dictsort[_KT, _VT]

class nodeps.getter(attr, *attrs, default=None)[source]

Bases: Callable[[Any], Any | tuple[Any, …]]

Return a callable object that fetches the given attribute(s)/item(s) from its operand.

Examples

>>> from types import SimpleNamespace
>>> from pickle import dumps, loads
>>> from copy import deepcopy
>>> from nodeps import getter
>>>
>>> test = SimpleNamespace(a='a', b='b')
>>> assert getter('a b')(test) == (test.a, test.b)
>>> assert getter('a c')(test) == (test.a, None)
>>> dicts = getter('a c d', default={})(test)
>>> assert dicts == (test.a, {}, {})
>>> assert id(dicts[1]) != id(dicts[2])
>>> assert getter('a')(test) == test.a
>>> assert getter('a b', 'c')(test) == (test.a, test.b, None)
>>> assert getter(['a', 'b'], 'c')(test) == (test.a, test.b, None)
>>> assert getter(['a', 'b'])(test) == (test.a, test.b)
>>>
>>> test = dict(a='a', b='b')
>>> assert getter('a b')(test) == (test['a'], test['b'])
>>> assert getter('a c')(test) == (test['a'], None)
>>> dicts = getter('a c d', default={})(test)
>>> assert dicts == (test['a'], {}, {})
>>> assert id(dicts[1]) != id(dicts[2])
>>> assert getter('a')(test) == test['a']
>>> assert getter('a b', 'c')(test) == (test['a'], test['b'], None)
>>> assert getter(['a', 'b'], 'c')(test) == (test['a'], test['b'], None)
>>> assert getter(['a', 'b'])(test) == (test['a'], test['b'])
>>>
>>> test = SimpleNamespace(a='a', b='b')
>>> test1 = SimpleNamespace(d='d', test=test)
>>> assert getter('d test.a test.a.c test.c test.m.j.k')(test1) == (test1.d, test1.test.a, None, None, None)
>>> assert getter('a c')(test1) == (None, None)
>>> dicts = getter('a c d test.a', 'test.b', default={})(test1)
>>> assert dicts == ({}, {}, test1.d, test1.test.a, test1.test.b)
>>> assert id(dicts[1]) != id(dicts[2])
>>> assert getter('a')(test1) is None
>>> assert getter('test.b')(test1) == test1.test.b
>>> assert getter(['a', 'test.b'], 'c')(test1) == (None, test1.test.b, None)
>>> assert getter(['a', 'a.b.c'])(test1) == (None, None)
>>>
>>> test = dict(a='a', b='b')
>>> test1_dict = dict(d='d', test=test)
>>> assert getter('d test.a test.a.c test.c test.m.j.k')(test1_dict) ==                 getter('d test.a test.a.c test.c test.m.j.k')(test1)
>>> assert getter('d test.a test.a.c test.c test.m.j.k')(test1_dict) ==                 (test1_dict['d'], test1_dict['test']['a'], None, None, None)
>>> assert getter('a c')(test1_dict) == (None, None)
>>> dicts = getter('a c d test.a', 'test.b', default={})(test1_dict)
>>> assert dicts == ({}, {}, test1_dict['d'], test1_dict['test']['a'], test1_dict['test']['b'])
>>> assert id(dicts[1]) != id(dicts[2])
>>> assert getter('a')(test1_dict) is None
>>> assert getter('test.b')(test1_dict) == test1_dict['test']['b']
>>> assert getter(['a', 'test.b'], 'c')(test1_dict) == (None, test1_dict['test']['b'], None)
>>> assert getter(['a', 'a.b.c'])(test1_dict) == (None, None)
>>>
>>> encode = dumps(test1_dict)
>>> test1_dict_decode = loads(encode)
>>> assert id(test1_dict) != id(test1_dict_decode)
>>> test1_dict_copy = deepcopy(test1_dict)
>>> assert id(test1_dict) != id(test1_dict_copy)
>>>
>>> assert getter('d test.a test.a.c test.c test.m.j.k')(test1_dict_decode) ==         (test1_dict_decode['d'], test1_dict_decode['test']['a'], None, None, None)
>>> assert getter('a c')(test1_dict_decode) == (None, None)
>>> dicts = getter('a c d test.a', 'test.b', default={})(test1_dict_decode)
>>> assert dicts == ({}, {}, test1_dict_decode['d'], test1_dict['test']['a'], test1_dict_decode['test']['b'])
>>> assert id(dicts[1]) != id(dicts[2])
>>> assert getter('a')(test1_dict_decode) is None
>>> assert getter('test.b')(test1_dict_decode) == test1_dict_decode['test']['b']
>>> assert getter(['a', 'test.b'], 'c')(test1_dict_decode) == (None, test1_dict_decode['test']['b'], None)
>>> assert getter(['a', 'a.b.c'])(test1_dict_decode) == (None, None)
The call returns:
  • getter(‘name’)(r): r.name/r[‘name’].

  • getter(‘name’, ‘date’)(r): (r.name, r.date)/(r[‘name’], r[‘date’]).

  • getter(‘name.first’, ‘name.last’)(r):(r.name.first, r.name.last)/(r[‘name.first’], r[‘name.last’]).

Init.

Parameters:
class nodeps.LetterCounter(start='A')[source]

Bases: object

Letter Counter generator function. This way, each time you call next() on the generator.

It will yield the next counter value. We will also remove the maximum counter check

Examples

>>> from nodeps import LetterCounter
>>>
>>> c = LetterCounter("Z")
>>> assert c.increment() == 'AA'

Init.

Parameters:

start (str)

increment()[source]

Increments 1.

Exaamples:
>>> from nodeps import LetterCounter
>>>
>>> c = LetterCounter('BWDLQZZ')
>>> assert c.increment() == 'BWDLRAA'
>>> assert c.increment() == 'BWDLRAB'
Returns:

str

Return type:

str

class nodeps.NamedtupleMeta[source]

Bases: object

Namedtuple Metaclass.

Examples

>>> import collections
>>> from nodeps import NamedtupleMeta
>>>
>>> named = collections.namedtuple('named', 'a', defaults=('a', ))
>>>
>>> assert isinstance(named(), NamedtupleMeta) == True
>>> assert isinstance(named(), tuple) == True
>>>
>>> assert issubclass(named, NamedtupleMeta) == True
>>> assert issubclass(named, tuple) == True
class nodeps.Noset(name='')[source]

Bases: object

Marker object for globals not initialized or other objects.

Examples

>>> from nodeps import NOSET
>>>
>>> name = Noset.__name__.lower()
>>> assert str(NOSET) == f'<{name}>'
>>> assert repr(NOSET) == f'<{name}>'
>>> assert repr(Noset("test")) == f'<test>'

Init.

Parameters:

name (str)

name: str
class nodeps.IdName(id, name)[source]

Bases: object

Id and Name dataclass.

Parameters:
id: int
name: str
class nodeps.GitStatus(base='', dirty=False, diverge=False, local='', pull=False, push=False, remote='')[source]

Bases: object

Git SHA and status.

Parameters:
base

base SHA

Type:

str

dirty

is repository dirty including untracked files

Type:

bool

diverge

need push and pull. It considers is dirty.

Type:

bool

local

local SHA

Type:

str

pull

needs pull

Type:

bool

push

needs push

Type:

bool

remote

remote SHA

Type:

str

base: str = ''
dirty: bool = False
diverge: bool = False
local: str = ''
pull: bool = False
push: bool = False
remote: str = ''
class nodeps.GroupUser(group, user)[source]

Bases: object

GroupUser class.

Parameters:
group: IdName
user: IdName
class nodeps.Bump(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Bump class.

MAJOR = 'MAJOR'
MINOR = 'MINOR'
PATCH = 'PATCH'
class nodeps.ProjectRepos(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Options to show repos in Project class.

DICT = '1'
INSTANCES = '2'
NAMES = '3'
PATHS = '4'
PY = '5'
class nodeps.Env(parsed=True)[source]

Bases: object

Environ Class.

See Also: Environment variables

If you need to use a workflow run’s URL from within a job, you can combine these environment variables:

$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID

If you generate a value in one step of a job, you can use the value in subsequent steps of

the same job by assigning the value to an existing or new environment variable and then writing this to the GITHUB_ENV environment file, see Commands.

If you want to pass a value from a step in one job in a workflow to a step in another job in the workflow,

you can define the value as a job output, see Syntax.

Parameters:

parsed (dataclasses.InitVar[bool])

config: CONFIG = None

var = Env()._config(“VAR”, default=True, cast=bool).

Type:

Searches for settings.ini and .env cwd up. Usage

CI: bool | str | None = None

Always set to true in a GitHub Actions environment.

GITHUB_ACTION: str | None = None

The name of the action currently running, or the id of a step.

For example, for an action, __repo-owner_name-of-action-repo.

GitHub removes special characters, and uses the name __run when the current step runs a script without an id.

If you use the same script or action more than once in the same job, the name will include a suffix that consists of the sequence number preceded by an underscore.

For example, the first script you run will have the name __run, and the second script will be named __run_2.

Similarly, the second invocation of actions/checkout will be actionscheckout2.

GITHUB_ACTION_PATH: Path | str | None = None

The path where an action is located. This property is only supported in composite actions.

You can use this path to access files located in the same repository as the action.

For example, /home/runner/work/_actions/repo-owner/name-of-action-repo/v1.

GITHUB_ACTION_REPOSITORY: str | None = None

For a step executing an action, this is the owner and repository name of the action.

For example, actions/checkout.

GITHUB_ACTIONS: bool | str | None = None

Always set to true when GitHub Actions is running the workflow.

You can use this variable to differentiate when tests are being run locally or by GitHub Actions.

GITHUB_ACTOR: str | None = None

The name of the person or app that initiated the workflow.

For example, octocat.

GITHUB_API_URL: ParseResult | str | None = None

API URL.

For example: https://api.github.com.

GITHUB_BASE_REF: str | None = None

The name of the base ref or target branch of the pull request in a workflow run.

This is only set when the event that triggers a workflow run is either pull_request or pull_request_target.

For example, main.

GITHUB_ENV: Path | str | None = None

The path on the runner to the file that sets environment variables from workflow commands.

This file is unique to the current step and changes for each step in a job.

For example, /home/runner/work/_temp/_runner_file_commands/set_env_87406d6e-4979-4d42-98e1-3dab1f48b13a.

For more information, see Workflow commands for GitHub Actions.

GITHUB_EVENT_NAME: str | None = None

The name of the event that triggered the workflow.

For example, workflow_dispatch.

GITHUB_EVENT_PATH: Path | str | None = None

The path to the file on the runner that contains the full event webhook payload.

For example, /github/workflow/event.json.

GITHUB_GRAPHQL_URL: ParseResult | str | None = None

Returns the GraphQL API URL.

For example: https://api.github.com/graphql.

GITHUB_HEAD_REF: str | None = None

The head ref or source branch of the pull request in a workflow run.

This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target.

For example, feature-branch-1.

GITHUB_JOB: str | None = None

The job_id of the current job.

For example, greeting_job.

GITHUB_PATH: Path | str | None = None

The path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and changes for each step in a job.

For example, /home/runner/work/_temp/_runner_file_commands/add_path_899b9445-ad4a-400c-aa89-249f18632cf5.

For more information, see Workflow commands for GitHub Actions.

GITHUB_REF: str | None = None

The branch or tag ref that triggered the workflow run.

For branches this is the format refs/heads/<branch_name>, for tags it is refs/tags/<tag_name>, and for pull requests it is refs/pull/<pr_number>/merge.

This variable is only set if a branch or tag is available for the event type.

For example, refs/heads/feature-branch-1.

GITHUB_REF_NAME: str | None = None

The branch or tag name that triggered the workflow run.

For example, feature-branch-1.

GITHUB_REF_PROTECTED: bool | str | None = None

true if branch protections are configured for the ref that triggered the workflow run.

GITHUB_REF_TYPE: str | None = None

The type of ref that triggered the workflow run.

Valid values are branch or tag.

For example, branch.

GITHUB_REPOSITORY: str | None = None

The owner and repository name.

For example, octocat/Hello-World.

GITHUB_REPOSITORY_OWNER: str | None = None

The repository owner’s name.

For example, octocat.

GITHUB_RETENTION_DAYS: str | None = None

The number of days that workflow run logs and artifacts are kept.

For example, 90.

GITHUB_RUN_ATTEMPT: str | None = None

A unique number for each attempt of a particular workflow run in a repository.

This number begins at 1 for the workflow run’s first attempt, and increments with each re-run.

For example, 3.

GITHUB_RUN_ID: str | None = None

A unique number for each workflow run within a repository.

This number does not change if you re-run the workflow run.

For example, 1658821493.

GITHUB_RUN_NUMBER: str | None = None

A unique number for each run of a particular workflow in a repository.

This number begins at 1 for the workflow’s first run, and increments with each new run. This number does not change if you re-run the workflow run.

For example, 3.

GITHUB_SERVER_URL: ParseResult | str | None = None

The URL of the GitHub Enterprise Cloud server.

For example: https://github.com.

GITHUB_SHA: str | None = None

The commit SHA that triggered the workflow.

The value of this commit SHA depends on the event that triggered the workflow. For more information, see Events that trigger workflows.

For example, ffac537e6cbbf934b08745a378932722df287a53.

GITHUB_WORKFLOW: Path | str | None = None

The name of the workflow.

For example, My test workflow.

If the workflow file doesn’t specify a name, the value of this variable is the full path of the workflow file in the repository.

GITHUB_WORKSPACE: Path | str | None = None

The default working directory on the runner for steps, and the default location of your repository when using the checkout action.

For example, /home/runner/work/my-repo-name/my-repo-name.

RUNNER_ARCH: str | None = None

The architecture of the runner executing the job.

Possible values are X86, X64, ARM, or ARM64.

For example, X86.

RUNNER_NAME: str | None = None

The name of the runner executing the job.

For example, Hosted Agent.

RUNNER_OS: str | None = None

The operating system of the runner executing the job.

Possible values are Linux, Windows, or macOS.

For example, Linux.

RUNNER_TEMP: Path | str | None = None

The path to a temporary directory on the runner.

This directory is emptied at the beginning and end of each job.

Note that files will not be removed if the runner’s user account does not have permission to delete them.

For example, _temp.

RUNNER_TOOL_CACHE: str | None = None

The path to the directory containing preinstalled tools for GitHub-hosted runners.

For more information, see About GitHub-hosted runners.

Ubuntu latest macOS latest

For example, C:/hostedtoolcache/windows.

COMMAND_MODE: str | None = None
HOME: str | None = None
IPYTHONENABLE: str | None = None
LC_TYPE: str | None = None
LOGNAME: str | None = None
OLDPWD: str | None = None
PATH: str | None = None
PS1: str | None = None
PWD: str | None = None
PYCHARM_DISPLAY_PORT: str | None = None
PYCHARM_HOSTED: str | None = None
PYCHARM_MATPLOTLIB_INDEX: str | None = None
PYCHARM_MATPLOTLIB_INTERACTIVE: str | None = None
PYCHARM_PROPERTIES: str | None = None
PYCHARM_VM_OPTIONS: str | None = None
PYDEVD_LOAD_VALUES_ASYNC: str | None = None
PYTHONIOENCODING: str | None = None
PYTHONPATH: str | None = None
PYTHONUNBUFFERED: str | None = None
SHELL: str | None = None
SSH_AUTH_SOCK: str | None = None
SUDO_USER: str | None = None
TMPDIR: str | None = None
XPC_FLAGS: str | None = None
XPC_SERVICE_NAME: str | None = None
LOGURU_LEVEL: str | None = 'DEBUG'
LOG_LEVEL: int | str | None = 'DEBUG'
parsed: dataclasses.InitVar[bool] = True
classmethod as_int(key, value='')[source]

Parse as int if environment variable should be forced to be parsed as int checking if:.

  • has value,

  • key in Env._parse_as_int or

  • key ends with one of the items in Env._parse_as_int_suffix.

Parameters:
  • key (str) – Environment variable name.

  • value (str) – Environment variable value (default: “”).

Returns:

int, if key should be parsed as int and has value, otherwise according to parse_str().

Return type:

bool | Path | ParseResult | IPv4Address | IPv6Address | int | str

static parse_as_bool(variable='USER')[source]

Parses variable from environment 1 and 0 as bool instead of int.

Parses:
  • bool: 1, 0, True, False, yes, no, on, off (case insensitive)

  • int: integer only numeric characters but 1 and 0 or SUDO_UID or SUDO_GID

  • ipaddress: ipv4/ipv6 address

  • url: if “//” or “@” is found it will be parsed as url

  • path: start with / or ~ or .

  • others as string

Parameters:

variable (str) – variable name to parse from environment (default: USER)

Return type:

bool | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

Examples

>>> from nodeps import Path, MACOS, LOCAL
>>> from nodeps import Env
>>>
>>> if MACOS and LOCAL:
...     assert isinstance(Env.parse_as_bool(), str)
>>>
>>> os.environ['FOO'] = '1'
>>> assert Env.parse_as_bool("FOO") is True
>>>
>>> os.environ['FOO'] = '0'
>>> assert Env.parse_as_bool("FOO") is False
>>>
>>> os.environ['FOO'] = 'TrUe'
>>> assert Env.parse_as_bool("FOO") is True
>>>
>>> os.environ['FOO'] = 'OFF'
>>> assert Env.parse_as_bool("FOO") is False
>>>
>>> os.environ['FOO'] = '~/foo'
>>> assert Env.parse_as_bool("FOO") == Path('~/foo')
>>>
>>> os.environ['FOO'] = '/foo'
>>> assert Env.parse_as_bool("FOO") == Path('/foo')
>>>
>>> os.environ['FOO'] = './foo'
>>> assert Env.parse_as_bool("FOO") == Path('./foo')
>>>
>>> os.environ['FOO'] = './foo'
>>> assert Env.parse_as_bool("FOO") == Path('./foo')
>>>
>>> v = "https://github.com"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_bool("FOO").geturl() == v
>>>
>>> v = "git@github.com"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_bool("FOO").geturl() == v
>>>
>>> v = "0.0.0.0"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_bool("FOO").exploded == v
>>>
>>> os.environ['FOO'] = "::1"
>>> assert Env.parse_as_bool("FOO").exploded.endswith(":0001")
>>>
>>> v = "2"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_bool("FOO") == int(v)
>>>
>>> v = "2.0"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_bool("FOO") == v
>>>
>>> del os.environ['FOO']
>>> assert Env.parse_as_bool("FOO") is None
Returns:

None

Parameters:

variable (str)

Return type:

bool | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

classmethod parse_as_int(name='USER')[source]

Parses variable from environment using mreleaser.parse_str(),.

except SUDO_UID or SUDO_GID which are parsed as int instead of bool.

Parameters:

name (str) – variable name to parse from environment (default: USER)

Return type:

bool | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

Examples

>>> from nodeps import Path, MACOS, LOCAL
>>> from nodeps import Env
>>>
>>> if MACOS and LOCAL:
...     assert isinstance(Env.parse_as_int(), str)
>>>
>>> os.environ['FOO'] = '1'
>>> assert Env.parse_as_int("FOO") is True
>>>
>>> os.environ['FOO'] = '0'
>>> assert Env.parse_as_int("FOO") is False
>>>
>>> os.environ['FOO'] = 'TrUe'
>>> assert Env.parse_as_int("FOO") is True
>>>
>>> os.environ['FOO'] = 'OFF'
>>> assert Env.parse_as_int("FOO") is False
>>>
>>> os.environ['FOO'] = '~/foo'
>>> assert Env.parse_as_int("FOO") == Path('~/foo')
>>>
>>> os.environ['FOO'] = '/foo'
>>> assert Env.parse_as_int("FOO") == Path('/foo')
>>>
>>> os.environ['FOO'] = './foo'
>>> assert Env.parse_as_int("FOO") == Path('./foo')
>>>
>>> os.environ['FOO'] = './foo'
>>> assert Env.parse_as_int("FOO") == Path('./foo')
>>>
>>> v = "https://github.com"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_int("FOO").geturl() == v
>>>
>>> v = "git@github.com"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_int("FOO").geturl() == v
>>>
>>> v = "0.0.0.0"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_int("FOO").exploded == v
>>>
>>> os.environ['FOO'] = "::1"
>>> assert Env.parse_as_int("FOO").exploded.endswith(":0001")
>>>
>>> v = "2"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_int("FOO") == int(v)
>>>
>>> v = "2.0"
>>> os.environ['FOO'] = v
>>> assert Env.parse_as_int("FOO") == v
>>>
>>> del os.environ['FOO']
>>> assert Env.parse_as_int("FOO") is None
>>>
>>> if not os.environ.get("CI"):
...     assert isinstance(Env.parse_as_int("PATH"), str)
Returns:

Value parsed

Parameters:

name (str)

Return type:

bool | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

class nodeps.EnvBuilder(system_site_packages=False, clear=False, symlinks=True, upgrade=True, with_pip=True, prompt='.', upgrade_deps=True, env_dir='venv')[source]

Bases: EnvBuilder

Wrapper for venv.EnvBuilder.

Changed defaults for: prompt` symlinks and with_pip, adds env_dir to __init__ arguments.

Post install in post_setup().

This class exists to allow virtual environment creation to be customized. The constructor parameters determine the builder’s behaviour when called upon to create a virtual environment.

By default, the builder makes the system (global) site-packages dir *un*available to the created environment.

If invoked using the Python -m option, the default is to use copying on Windows platforms but symlinks elsewhere. If instantiated some other way, the default is to not use symlinks (changed with the wrapper to use symlinks always).

Parameters:
system_site_packages

bool If True, the system (global) site-packages dir is available to created environments.

Type:

bool

clear

bool If True, delete the contents of the environment directory if it already exists, before environment creation.

Type:

bool

bool If True, attempt to symlink rather than copy files into virtual environment.

Type:

bool

upgrade

bool If True, upgrade an existing virtual environment.

Type:

bool

with_pip

bool If True, ensure pip is installed in the virtual environment.

Type:

bool

prompt

str Alternative terminal prefix for the environment.

Type:

str | None

upgrade_deps

bool Update the base venv modules to the latest on PyPI (python 3.9+).

Type:

bool

context

Simplenamespace The information for the environment creation request being processed.

Type:

types.SimpleNamespace | None

env_dir

bool The target directory to create an environment in.

Type:

Path | str | None

system_site_packages: bool = False
clear: bool = False
symlinks: bool = True
upgrade: bool = True

Upgrades scripts and run venv.EnvBuilder.post_setup.

with_pip: bool = True
prompt: str | None = '.'

To use basename use ‘.’.

upgrade_deps: bool = True

upgrades venv.CORE_VENV_DEPS.

env_dir: Path | str | None = 'venv'
context: types.SimpleNamespace | None = None
create(env_dir=None)[source]

Create a virtual environment in a directory.

Parameters:

env_dir (Path | str | None) – The target directory to create an environment in.

Return type:

None

ensure_directories(env_dir=None)[source]

Create the directories for the environment.

Parameters:

env_dir (Path | str | None) – The target directory to create an environment in.

Returns:

A context object which holds paths in the environment, for use by subsequent logic.

Return type:

types.SimpleNamespace

post_setup(context=None)[source]

Hook for post-setup modification of the venv.

Subclasses may install additional packages or scripts here, add activation shell scripts, etc.

Parameters:

context (types.SimpleNamespace | None) – The information for the environment creation request being processed.

Return type:

None

nodeps.parse_str(data=None)[source]

Parses str or data.__str__().

Parses:
  • bool: 1, 0, True, False, yes, no, on, off (case insensitive)

  • int: integer only numeric characters but 1 and 0

  • ipaddress: ipv4/ipv6 address

  • url: if “://” or “@” is found it will be parsed as url

  • path: if “.” or start with “/” or “~” or “.” and does contain “:”

  • others as string

Parameters:

data (Any | None) – variable name to parse from environment (default: USER)

Return type:

bool | GitUrl | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

Examples

>>> import os
>>> from nodeps import Path
>>> from nodeps import parse_str
>>>
>>> assert parse_str() is None
>>>
>>> assert parse_str("1") is True
>>> assert parse_str("0") is False
>>> assert parse_str("TrUe") is True
>>> assert parse_str("OFF") is False
>>>
>>> u = "https://github.com/user/repo"
>>> assert parse_str(u).url == u
>>> u = "git@github.com:user/repo"
>>> assert parse_str(u).url == u
>>> u = "https://github.com"
>>> assert parse_str(u).geturl() == u
>>> u = "git@github.com"
>>> assert parse_str(u).geturl() == u
>>>
>>> assert parse_str("~/foo") == Path('~/foo')
>>> assert parse_str("/foo") == Path('/foo')
>>> assert parse_str("./foo") == Path('foo')
>>> assert parse_str(".") == Path('.')
>>> assert parse_str(Path()) == Path()
>>>
>>> assert parse_str("0.0.0.0").exploded == "0.0.0.0"
>>> assert parse_str("::1").exploded.endswith(":0001")
>>>
>>> assert parse_str("2") == 2
>>> assert parse_str("2.0") == "2.0"
>>> assert parse_str("/usr/share/man:") == "/usr/share/man:"
>>> if not os.environ.get("CI"):
...     assert isinstance(parse_str(os.environ.get("PATH")), str)
Returns:

None

Parameters:

data (Any | None)

Return type:

bool | GitUrl | Path | ParseResult | IPv4Address | IPv6Address | int | str | None

exception nodeps.CalledProcessError(returncode=None, cmd=None, output=None, stderr=None, completed=None)[source]

Bases: SubprocessError

Patched subprocess.CalledProcessError.

Raised when run() and the process returns a non-zero exit status.

cmd

The command that was run.

Type:

AnyStr | os.PathLike[str] | os.PathLike[bytes] | collections.abc.Sequence[AnyStr | os.PathLike[str] | os.PathLike[bytes]]

returncode

The exit code of the process.

Type:

int

output

The output of the process.

Type:

AnyStr | None

stderr

The error output of the process.

Type:

AnyStr | None

completed

subprocess.CompletedProcess object.

Type:

subprocess.CompletedProcess | None

Patched subprocess.CalledProcessError.

Parameters:
Return type:

None

Examples

>>> import subprocess
>>> 3/0  
Traceback (most recent call last):
ZeroDivisionError: division by zero
>>> subprocess.run(["ls", "foo"], capture_output=True, check=True)  
Traceback (most recent call last):
errors.CalledProcessError:
  Return Code:
    1

  Command:
    ['ls', 'foo']

  Stderr:
    b'ls: foo: No such file or directory\n'

  Stdout:
    b''
completed: CompletedProcess | None
returncode: int
cmd: AnyStr | PathLike[str] | PathLike[bytes] | Sequence[AnyStr | PathLike[str] | PathLike[bytes]]
output: AnyStr | None
stderr: AnyStr | None
property stdout: str

Alias for output attribute, to match stderr.

exception nodeps.CmdError(process=None)[source]

Bases: CalledProcessError

Raised when run() and the process returns a non-zero exit status.

Attribute:

process: The CompletedProcess object returned by run().

Init.

Parameters:

process (CompletedProcess | None)

Return type:

None

exception nodeps.CommandNotFoundError[source]

Bases: _NoDepsBaseError

Raised when command is not found.

exception nodeps.InvalidArgumentError[source]

Bases: _NoDepsBaseError

Raised when function is called with invalid argument.

nodeps.aioclosed()[source]

Check if event loop is closed.

Return type:

bool

async nodeps.aiocmd(*args, **kwargs)[source]

Async Exec Command.

Examples

>>> import asyncio
>>> from tempfile import TemporaryDirectory
>>> from nodeps import Path, aiocmd
>>> with TemporaryDirectory() as tmp:
...     tmp = Path(tmp)
...     rv = asyncio.run(aiocmd("git", "clone", "https://github.com/octocat/Hello-World.git", cwd=tmp))
...     assert rv.returncode == 0
...     assert (tmp / "Hello-World" / "README").exists()
Parameters:
  • *args – command and args

  • **kwargs – subprocess.run kwargs

Raises:

JetBrainsError

Returns:

None

Return type:

CompletedProcess

async nodeps.aiocommand(data, decode=True, utf8=False, lines=False)[source]

Asyncio run cmd.

Parameters:
  • data (str | list) – command.

  • decode (bool) – decode and strip output.

  • utf8 (bool) – utf8 decode.

  • lines (bool) – split lines.

Returns:

CompletedProcess.

Return type:

CompletedProcess

async nodeps.aiodmg(src, dest)[source]

Async Open dmg file and copy the app to dest.

Examples

>>> from nodeps import aiodmg
>>> async def test():    
...     await aiodmg("/tmp/JetBrains.dmg", "/tmp/JetBrains")
Parameters:
Returns:

CompletedProcess

Return type:

None

async nodeps.aiogz(src, dest='.')[source]

Async ncompress .gz src to dest (default: current directory).

It will be uncompressed to the same directory name as src basename. Uncompressed directory will be under dest directory.

Examples

>>> import os
>>> import tempfile
>>> from nodeps import Path, aiogz, tardir
>>>
>>> cwd = Path.cwd()
>>> with tempfile.TemporaryDirectory() as workdir:
...     os.chdir(workdir)
...     with tempfile.TemporaryDirectory() as compress:
...         file = Path(compress) / "test.txt"
...         _ = file.touch()
...         compressed = tardir(compress)
...         with tempfile.TemporaryDirectory() as uncompress:
...             uncompressed = asyncio.run(aiogz(compressed, uncompress))
...             assert uncompressed.is_dir()
...             assert Path(uncompressed).joinpath(file.name).exists()
>>> os.chdir(cwd)
Parameters:
Returns:

Absolute Path of the Uncompressed Directory

Return type:

Path

nodeps.aioloop()[source]

Get running loop.

Return type:

RunningLoop | None

nodeps.aioloopid()[source]

Get running loop id.

Return type:

int | None

nodeps.aiorunning()[source]

Check if event loop is running.

Return type:

bool

nodeps.allin(origin, destination)[source]

Checks all items in origin are in destination iterable.

Examples

>>> from nodeps import allin
>>> from nodeps.variables.builtin import BUILTIN_CLASS
>>>
>>> class Int(int):
...     pass
>>> allin(tuple.__mro__, BUILTIN_CLASS)
True
>>> allin(Int.__mro__, BUILTIN_CLASS)
False
>>> allin('tuple int', 'bool dict int')
False
>>> allin('bool int', ['bool', 'dict', 'int'])
True
>>> allin(['bool', 'int'], ['bool', 'dict', 'int'])
True
Parameters:
  • origin (Iterable) – origin iterable.

  • destination (Iterable) – destination iterable to check if origin items are in.

Returns:

True if all items in origin are in destination.

Return type:

bool

nodeps.ami(user='root')[source]

Check if Current User is User in Argument (default: root).

Examples

>>> from nodeps import ami
>>> from nodeps import USER
>>> from nodeps import LOCAL
>>> from nodeps import DOCKER
>>> from nodeps import MACOS
>>>
>>> assert ami(USER) is True
>>> if LOCAL and MACOS:
...     assert ami() is False
>>> if DOCKER:
...     assert ami() is True
Parameters:

user (str) – to check against current user (Default: root)

Returns:

bool True if I am user, False otherwise

Return type:

bool

nodeps.anyin(origin, destination)[source]

Checks any item in origin are in destination iterable and return the first found.

Examples

>>> from nodeps import anyin
>>> from nodeps.variables.builtin import BUILTIN_CLASS
>>>
>>> class Int(int):
...     pass
>>> anyin(tuple.__mro__, BUILTIN_CLASS)
<class 'tuple'>
>>> assert anyin('tuple int', BUILTIN_CLASS) is None
>>> anyin('tuple int', 'bool dict int')
'int'
>>> anyin('tuple int', ['bool', 'dict', 'int'])
'int'
>>> anyin(['tuple', 'int'], ['bool', 'dict', 'int'])
'int'
Parameters:
  • origin (Iterable) – origin iterable.

  • destination (Iterable) – destination iterable to check if any of origin items are in.

Returns:

First found if any item in origin are in destination.

Return type:

Any | None

nodeps.chdir(data=True)[source]

Change directory and come back to previous directory.

Examples

>>> from nodeps import Path
>>> from nodeps import chdir
>>> from nodeps import MACOS
>>>
>>> previous = Path.cwd()
>>> new = Path('/usr')
>>> with chdir(new) as (pr, ne):
...     assert previous == pr
...     assert new == ne
...     assert ne == Path.cwd()
>>>
>>> if MACOS:
...     new = Path('/bin/ls')
...     with chdir(new) as (pr, ne):
...         assert previous == pr
...         assert new.parent == ne
...         assert ne == Path.cwd()
>>>
>>> if MACOS:
...     new = Path('/bin/foo')
...     with chdir(new) as (pr, ne):
...         assert previous == pr
...         assert new.parent == ne
...         assert ne == Path.cwd()
>>>
>>> with chdir() as (pr, ne):
...     assert previous == pr
...     if MACOS:
...         assert "var" in str(ne)
...     assert ne == Path.cwd() 
Parameters:

data (Path | AnyStr | PathLike[str] | PathLike[bytes] | IO | bool) – directory or parent if file or True for temp directory

Returns:

Old directory and new directory

Return type:

Iterable[tuple[Path, Path]]

nodeps.cmd(*args, **kwargs)[source]

Exec Command.

Examples

>>> import tempfile
>>> from nodeps import Path, cmd
>>>
>>> with tempfile.TemporaryDirectory() as tmp:
...     rv = cmd("git", "clone", "https://github.com/octocat/Hello-World.git", tmp)
...     assert rv.returncode == 0
...     assert (Path(tmp) / "README").exists()
Parameters:
  • *args – command and args

  • **kwargs – subprocess.run kwargs

Raises:

CmdError

Returns:

None

Return type:

CompletedProcess

nodeps.cmdrun(data, exc=False, lines=True, shell=True, py=False, pysite=True)[source]

Runs a cmd.

Examples

>>> from nodeps import CI
>>> from nodeps import cmdrun
>>> from nodeps import in_tox
>>>
>>> cmdrun('ls a')  
CompletedProcess(args='ls a', returncode=..., stdout=[], stderr=[...])
>>> cmdrun('ls a', shell=False, lines=False)  
CompletedProcess(args=['ls', 'a'], returncode=..., stdout='', stderr=...)
>>> cmdrun('echo a', lines=False)  # Extra '\' added to avoid docstring error.
CompletedProcess(args='echo a', returncode=0, stdout='a\n', stderr='')
>>> assert "venv" not in cmdrun("sysconfig", py=True, lines=False).stdout
>>> if os.environ.get("VIRTUAL_ENV"):
...     assert "venv" in cmdrun("sysconfig", py=True, pysite=False, lines=False).stdout
Parameters:
  • data (Iterable) – command.

  • exc (bool) – raise exception.

  • lines (bool) – split lines so \\n is removed from all lines (extra ‘' added to avoid docstring error).

  • py (bool) – runs with python executable.

  • shell (bool) – expands shell variables and one line (shell True expands variables in shell).

  • pysite (bool) – run on site python if running on a VENV.

Returns:

Completed process output.

Return type:

Union[CompletedProcess, int, list, str]

Raises:

CmdError

nodeps.cmdsudo(*args, user='root', **kwargs)[source]

Run Program with sudo if user is different that the current user.

Parameters:
  • *args – command and args to run

  • user (str) – run as user (Default: False)

  • **kwargs – subprocess.run kwargs

Returns:

CompletedProcess if the current user is not the same as user, None otherwise

Return type:

CompletedProcess | None

nodeps.command(*args, **kwargs)[source]

Exec Command with the following defaults compared to subprocess.run().

  • capture_output=True

  • text=True

  • check=True

Examples

>>> from nodeps import Path
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as tmp:
...     rv = command("git", "clone", "https://github.com/octocat/Hello-World.git", tmp)
...     assert rv.returncode == 0
...     assert (Path(tmp) / ".git").exists()
Parameters:
  • *args – command and args

  • **kwargssubprocess.run kwargs

Raises:

CmdError

Returns:

None

Return type:

CompletedProcess

nodeps.completions(name, install=True, uninstall=False)[source]

Generate completions for command.

Parameters:
  • name (str) – command name

  • install (bool) – install completions to /usr/local/etc/bash_completion.d/ or /etc/bash_completion.d

  • uninstall (bool) – uninstall completions

Returns:

Path to file if installed or prints if not installed

Return type:

str | None

nodeps.current_task_name()[source]

Current asyncio task name.

Return type:

str

nodeps.dict_sort(data, ordered=False, reverse=False)[source]

Order a dict based on keys.

Examples

>>> import platform
>>> from collections import OrderedDict
>>> from nodeps import dict_sort
>>>
>>> d = {"b": 2, "a": 1, "c": 3}
>>> dict_sort(d)
{'a': 1, 'b': 2, 'c': 3}
>>> dict_sort(d, reverse=True)
{'c': 3, 'b': 2, 'a': 1}
>>> v = platform.python_version()
>>> if "rc" not in v:
...     # noinspection PyTypeHints
...     assert dict_sort(d, ordered=True) == OrderedDict([('a', 1), ('b', 2), ('c', 3)])
Parameters:
  • data (dict[_KT, _VT]) – dict to be ordered.

  • ordered (bool) – OrderedDict.

  • reverse (bool) – reverse.

Returns:

Dict sorted

Return type:

Union[dict, collections.OrderedDict]

nodeps.dmg(src, dest)[source]

Open dmg file and copy the app to dest.

Examples

>>> from nodeps import dmg
>>> dmg("/tmp/JetBrains.dmg", "/tmp/JetBrains")  
Parameters:
Returns:

CompletedProcess

Return type:

None

nodeps.effect(apply, *args)[source]

Perform function on iterable.

Examples

>>> from types import SimpleNamespace
>>> from nodeps import effect
>>> simple = SimpleNamespace()
>>> effect(lambda x: simple.__setattr__(x, dict()), 'a b', 'c')
>>> assert simple.a == {}
>>> assert simple.b == {}
>>> assert simple.c == {}
Parameters:
  • apply (Callable) – Function to apply.

  • *args (Iterable) – Iterable to perform function.

Returns:

No Return.

Return type:

None

nodeps.elementadd(name, closing=False)[source]

Converts to HTML element.

Examples

>>> from nodeps import elementadd
>>>
>>> assert elementadd('light-black') == '<light-black>'
>>> assert elementadd('light-black', closing=True) == '</light-black>'
>>> assert elementadd(('green', 'bold',)) == '<green><bold>'
>>> assert elementadd(('green', 'bold',), closing=True) == '</green></bold>'
Parameters:
  • name (str | tuple[str, ...]) – text or iterable text.

  • closing (bool | None) – True if closing/end, False if opening/start.

Returns:

Str

Return type:

str

nodeps.elevate()[source]

Other https://github.com/netinvent/command_runner/blob/master/command_runner/elevate.py.

nodeps.envsh(path='.env', missing_ok=False, override=True)[source]

Source path or ``path``relative to cwd upwards and return the resulting environment as a dictionary.

Parameters:
  • path (Path | AnyStr | PathLike[str] | PathLike[bytes] | IO) – bash file to source or name relative to cwd upwards.

  • missing_ok (bool) – do not raise exception if file ot found.

  • override (bool) – override os.environ.

Raises:

FileNotFoundError.

Returns:

Dict with updated values

Return type:

dict[str, str]

nodeps.exec_module_from_file(file, name=None)[source]

Executes module from file location.

Examples

>>> import nodeps
>>> from nodeps import exec_module_from_file
>>> m = exec_module_from_file(nodeps.__file__)
>>> assert m.__name__ == nodeps.__name__
Parameters:
  • file (Path | str) – file location

  • name (str | None) – module name (default from file)

Returns:

Module instance

Return type:

ModuleType

nodeps.filterm(d, k=<function <lambda>>, v=<function <lambda>>)[source]

Filter Mutable Mapping.

Examples

>>> from nodeps import filterm
>>>
>>> assert filterm({'d':1}) == {'d': 1}
>>> # noinspection PyUnresolvedReferences
>>> assert filterm({'d':1}, lambda x: x.startswith('_')) == {}
>>> # noinspection PyUnresolvedReferences
>>> assert filterm({'d': 1, '_a': 2}, lambda x: x.startswith('_'), lambda x: isinstance(x, int)) == {'_a': 2}
Returns:

Filtered dict with

Parameters:
Return type:

MutableMapping[_KT, _VT]

nodeps.findfile(pattern, path=None)[source]

Find file with pattern.

Examples

>>> from pathlib import Path
>>> import nodeps
>>> from nodeps import findfile, MACOS, LOCAL
>>>
>>> if MACOS and LOCAL:
...     assert Path(nodeps.__file__) in findfile("*.py")
Parameters:
Returns:

list of files found

Return type:

list[Path]

nodeps.findup(path=None, kind='is_file', name='.env', uppermost=False)[source]

Find up if name exists or is file or directory.

Examples

>>> import email
>>> import email.mime
>>> import nodeps
>>> from nodeps import chdir, findup, parent, Path, Env
>>>
>>>
>>> file = Path(email.mime.__file__)
>>>
>>> env = Env()
>>> input_file = env.GITHUB_WORKSPACE if env.GITHUB_WORKSPACE else nodeps.__file__
>>> with chdir(parent(input_file)):
...     pyproject_toml = findup(input_file, name="pyproject.toml")
...     assert pyproject_toml.is_file()
>>>
>>> with chdir(parent(email.mime.__file__)):
...     email_mime_py = findup(name="__init__.py")
...     assert email_mime_py.is_file()
...     assert email_mime_py == Path(email.mime.__file__)
...     email_py = findup(name="__init__.py", uppermost=True)
...     assert email_py.is_file()
...     assert email_py == Path(email.__file__)
>>>
>>> assert findup(file, kind="exists", name="__init__.py") == file.parent / "__init__.py"
>>> assert findup(file, name="__init__.py") == file.parent / "__init__.py"
>>> assert findup(file, name="__init__.py", uppermost=True) == file.parent.parent / "__init__.py"
Parameters:
  • path (AnyPath) – CWD if None or Path.

  • kind (PathIsLiteral) – Exists, file or directory.

  • name (str | Path) – File or directory name.

  • uppermost (bool) – Find uppermost found if True (return the latest found if more than one) or first if False.

Returns:

Path if found.

Return type:

Path | None

nodeps.firstfound(data, apply)[source]

Returns first value in data if apply is True.

Examples

>>> from nodeps import firstfound
>>>
>>> assert firstfound([1, 2, 3], lambda x: x == 2) == 2
>>> assert firstfound([1, 2, 3], lambda x: x == 4) is None
Parameters:
Returns:

Value if found.

Return type:

Any

nodeps.flatten(data, recurse=False, unique=False, sort=True)[source]

Flattens an Iterable.

Examples

>>> from nodeps import flatten
>>>
>>> assert flatten([1, 2, 3, [1, 5, 7, [2, 4, 1, ], 7, 6, ]]) == [1, 2, 3, 1, 5, 7, [2, 4, 1], 7, 6]
>>> assert flatten([1, 2, 3, [1, 5, 7, [2, 4, 1, ], 7, 6, ]], recurse=True) == [1, 1, 1, 2, 2, 3, 4, 5, 6, 7, 7]
>>> assert flatten((1, 2, 3, [1, 5, 7, [2, 4, 1, ], 7, 6, ]), unique=True) == (1, 2, 3, 4, 5, 6, 7)
Parameters:
Return type:

Union[list, Iterable]

nodeps.framesimple(data)[source]

Returns nodeps.FrameSimple.

Examples

>>> import inspect
>>> from nodeps import Path
>>> from nodeps import framesimple
>>>
>>> frameinfo = inspect.stack()[0]
>>> finfo = framesimple(frameinfo)
>>> ftype = framesimple(frameinfo.frame)
>>> assert frameinfo.frame.f_code == finfo.code
>>> assert frameinfo.frame == finfo.frame
>>> assert frameinfo.filename == str(finfo.path)
>>> assert frameinfo.lineno == finfo.lineno
Returns:

FrameSimple.

Parameters:

data (FrameInfo | FrameType | TracebackType)

Return type:

FrameSimple | None

nodeps.from_latin9(*args)[source]

Converts string from latin9 hex.

Examples

>>> from nodeps import from_latin9
>>>
>>> from_latin9("f1")
'ñ'
>>>
>>> from_latin9("4a6f73e920416e746f6e696f205075e972746f6c6173204d6f6e7461f1e973")
'José Antonio Puértolas Montañés'
>>>
>>> from_latin9("f1", "6f")
'ño'
Parameters:

args – strings to convert to latin9

Returns:

str

Return type:

str

nodeps.fromiter(data, *args)[source]

Gets attributes from Iterable of objects and returns dict with.

Examples

>>> from types import SimpleNamespace as Simple
>>> from nodeps import fromiter
>>>
>>> assert fromiter([Simple(a=1), Simple(b=1), Simple(a=2)], 'a', 'b', 'c') == {'a': [1, 2], 'b': [1]}
>>> assert fromiter([Simple(a=1), Simple(b=1), Simple(a=2)], ('a', 'b', ), 'c') == {'a': [1, 2], 'b': [1]}
>>> assert fromiter([Simple(a=1), Simple(b=1), Simple(a=2)], 'a b c') == {'a': [1, 2], 'b': [1]}
Parameters:
  • data – object.

  • *args – attributes.

Returns:

Tuple

nodeps.getpths()[source]

Get list of pths under sitedir.

Examples

>>> from nodeps import getpths
>>>
>>> pths = getpths()
>>> assert "distutils-precedence" in pths
Returns:

Dictionary with pth name and file

Return type:

dict[str, Path] | None

nodeps.getsitedir(index=2)[source]

Get site directory from stack if imported by site in a .pth file or sysconfig.

Examples

>>> from nodeps import getsitedir
>>> assert "packages" in str(getsitedir())
Parameters:

index (bool) – 1 if directly needed by this function (default: 2), for caller to this function

Returns:

Path instance with site directory

Return type:

Path

nodeps.group_user(data='root')[source]

Group and User for Name (id if name is str and vice versa).

Examples

>>> import os
>>> import pathlib
>>>
>>> from nodeps import group_user
>>> from nodeps import PW_USER, PW_ROOT, MACOS, LOCAL
>>>
>>> stat = pathlib.Path().stat()
>>> gu = group_user()
>>> assert gu.group.id == stat.st_gid and gu.user.id == stat.st_uid
>>> gu = group_user(data=PW_USER.pw_uid)
>>> actual_gname = gu.group.name
>>> assert gu.user.name == PW_USER.pw_name
>>> gu = group_user('root')
>>> if MACOS and LOCAL:
...     assert gu.group.id != stat.st_gid and gu.user.id == 0
>>> gu = group_user(data=0)
>>> if MACOS and LOCAL:
...     assert gu.group.name != actual_gname and gu.user.name == 'root'
Parameters:

data (int | str) – usename or id (default: USER)

Returns:

GroupUser.

Return type:

GroupUser

nodeps.gz(src, dest='.')[source]

Uncompress .gz src to dest (default: current directory).

It will be uncompressed to the same directory name as src basename. Uncompressed directory will be under dest directory.

Examples

>>> import os
>>> import tempfile
>>> from nodeps import Path, gz, tardir
>>> cwd = Path.cwd()
>>> with tempfile.TemporaryDirectory() as workdir:
...     os.chdir(workdir)
...     with tempfile.TemporaryDirectory() as compress:
...         file = Path(compress) / "test.txt"
...         _ = file.touch()
...         compressed = tardir(compress)
...         with tempfile.TemporaryDirectory() as uncompress:
...             uncompressed = gz(compressed, uncompress)
...             assert uncompressed.is_dir()
...             assert Path(uncompressed).joinpath(file.name).exists()
>>> os.chdir(cwd)
Parameters:
Returns:

Absolute Path of the Uncompressed Directory

Return type:

Path

nodeps.in_tox()[source]

Running in tox.

Return type:

bool

nodeps.indict(data, items=None, **kwargs)[source]

All item/kwargs pairs in flat dict.

Examples

>>> from nodeps import indict
>>> from nodeps.variables.builtin import BUILTIN
>>>
>>> assert indict(BUILTIN, {'iter': iter}, credits=credits) is True
>>> assert indict(BUILTIN, {'iter': 'fake'}) is False
>>> assert indict(BUILTIN, {'iter': iter}, credits='fake') is False
>>> assert indict(BUILTIN, credits='fake') is False
Parameters:
Returns:

True if all pairs in dict.

Return type:

bool

nodeps.iscoro(data)[source]

Is coro?.

Parameters:

data (Any)

Return type:

bool

nodeps.map_with_args(data, func, /, *args, pred=<function <lambda>>, split=' ', **kwargs)[source]

Apply pred/filter to data and map with args and kwargs.

Examples

>>> from nodeps import map_with_args
>>>
>>> # noinspection PyUnresolvedReferences
>>> def f(i, *ar, **kw):
...     return f'{i}: {[a(i) for a in ar]}, {", ".join([f"{k}: {v(i)}" for k, v in kw.items()])}'
>>> map_with_args('0.1.2', f, int, list, pred=lambda x: x != '0', split='.', int=int, str=str)
["1: [1, ['1']], int: 1, str: 1", "2: [2, ['2']], int: 2, str: 2"]
Parameters:
  • data (Any) – data.

  • func (Callable) – final function to map.

  • *args – args to final map function.

  • pred (Callable) – pred to filter data before map.

  • split (str) – split for data str.

  • **kwargs – kwargs to final map function.

Returns:

List with results.

Return type:

list

nodeps.mip()[source]

My Public IP.

Examples

>>> from nodeps import mip
>>>
>>> mip()  
'...............'
Return type:

str | None

nodeps.noexc(func, *args, default_=None, exc_=<class 'Exception'>, **kwargs)[source]

Execute function suppressing exceptions.

Examples

>>> from nodeps import noexc
>>> assert noexc(dict(a=1).pop, 'b', default_=2, exc_=KeyError) == 2
Parameters:
  • func (Callable[..., _T]) – callable.

  • *args (Any) – args.

  • default – default value if exception is raised.

  • exc – exception or exceptions.

  • **kwargs (Any) – kwargs.

  • default_ (Any)

  • exc_ (ExcType)

  • **kwargs

Returns:

Function return.

Return type:

Any

nodeps.parent(path='/home/docs/checkouts/readthedocs.org/user_builds/nodeps/envs/latest/lib/python3.11/site-packages/nodeps/modules/functions.py', none=True)[source]

Parent if File or None if it does not exist.

Examples

>>> from nodeps import parent
>>>
>>> parent("/bin/ls")
Path('/bin')
>>> parent("/bin")
Path('/bin')
>>> parent("/bin/foo", none=False)
Path('/bin')
>>> parent("/bin/foo")
Parameters:
Returns:

Path

Return type:

Path | None

nodeps.printe(*values, sep=' ', end='\n', flush=False)[source]

Print to sys.stderr.

Parameters:
Return type:

None

nodeps.returncode(c, shell=True)[source]

Runs command in shell and returns returncode showing stdout and stderr.

No exception is raised

Examples

>>> from nodeps import returncode
>>>
>>> assert returncode("ls /bin/ls") == 0
>>> assert returncode("ls foo") in  [1, 2]
Parameters:
  • c (str | list[str]) – command to run

  • shell (bool) – run in shell (default: True)

Returns:

return code

Return type:

int

nodeps.sourcepath(data)[source]

Get path of object.

Examples

>>> import asyncio
>>> from nodeps import Path
>>> from nodeps import sourcepath
>>>
>>> finfo = inspect.stack()[0]
>>> globs_locs = (finfo.frame.f_globals | finfo.frame.f_locals).copy()
>>> assert sourcepath(sourcepath) == Path(__file__)
>>> assert sourcepath(asyncio.__file__) == Path(asyncio.__file__)
>>> assert sourcepath(dict(a=1)) == Path("{'a': 1}")
Returns:

Path.

Parameters:

data (Any)

Return type:

Path

nodeps.siteimported()[source]

True if imported by site in a .pth file.

Return type:

str | None

nodeps.split_pairs(text)[source]

Split text in pairs for even length.

Examples

>>> from nodeps import split_pairs
>>>
>>> split_pairs("123456")
[('1', '2'), ('3', '4'), ('5', '6')]
Parameters:

text – text to split in pairs

Returns:

text

nodeps.stdout(shell, keepends=False, split=False, cwd=None)[source]

Return stdout of executing cmd in a shell or None if error.

Execute the string ‘cmd’ in a shell with ‘subprocess.getstatusoutput’ and return a stdout if success. The locale encoding is used to decode the output and process newlines.

A trailing newline is stripped from the output.

Examples

>>> from nodeps import stdout
>>>
>>> stdout("ls /bin/ls")
'/bin/ls'
>>> stdout("true")
''
>>> stdout("ls foo")
>>> stdout("ls /bin/ls", split=True)
['/bin/ls']
Parameters:
  • shell (AnyStr) – command to be executed

  • keepends (bool) – line breaks when split if true, are not included in the resulting list unless keepends is given and true.

  • split (bool) – return a list of the stdout lines in the string, breaking at line boundaries.(default: False)

  • cwd (Path | str | None) – cwd

Returns:

Stdout or None if error.

Return type:

list[str] | str | None

nodeps.stdquiet()[source]

Redirect stdout/stderr to StringIO objects to prevent console output from distutils commands.

Returns:

Stdout, Stderr

Return type:

tuple[TextIO, TextIO]

nodeps.suppress(func, *args, exception=<class 'Exception'>, **kwargs)[source]

Try and supress exception.

Parameters:
  • func (Callable[P, T]) – function to call

  • *args (P.args) – args to pass to func

  • exception (ExcType | None) – exception to suppress (default: Exception)

  • **kwargs (P.kwargs) – kwargs to pass to func

Returns:

result of func

Return type:

T

nodeps.syssudo(user='root')[source]

Rerun Program with sudo sys.executable and sys.argv if user is different that the current user.

Parameters:

user (str) – run as user (Default: False)

Returns:

CompletedProcess if the current user is not the same as user, None otherwise

Return type:

CompletedProcess | None

nodeps.tardir(src)[source]

Compress directory src to <basename src>.tar.gz in cwd.

Examples

>>> import os
>>> import tempfile
>>> from nodeps import Path, tardir
>>> cwd = Path.cwd()
>>> with tempfile.TemporaryDirectory() as workdir:
...     os.chdir(workdir)
...     with tempfile.TemporaryDirectory() as compress:
...         file = Path(compress) / "test.txt"
...         _ = file.touch()
...         compressed = tardir(compress)
...         with tempfile.TemporaryDirectory() as uncompress:
...             uncompressed = gz(compressed, uncompress)
...             assert uncompressed.is_dir()
...             assert Path(uncompressed).joinpath(file.name).exists()
>>> os.chdir(cwd)
Parameters:

src (Path | AnyStr | PathLike[str] | PathLike[bytes] | IO) – directory to compress

Raises:
Returns:

Compressed Absolute File Path

Return type:

Path

nodeps.tilde(path='.')[source]

Replaces $HOME with ~.

Examples

>>> from nodeps import Path, tilde
>>> assert tilde(f"{Path.home()}/file") == f"~/file"
Parameters:

path (Path | AnyStr | PathLike[str] | PathLike[bytes] | IO) – path to replace (default: ‘.’)

Returns:

str

Return type:

str

nodeps.timestamp_now(file)[source]

Set modified and create date of file to now.

Parameters:

file (Path | str)

nodeps.to_camel(text, replace=True)[source]

Convert to Camel.

Examples

>>> to_camel("__ignore_attr__")
'IgnoreAttr'
>>> to_camel("__ignore_attr__", replace=False)  
'__Ignore_Attr__'
Parameters:
  • text (str) – text to convert.

  • replace (bool) – remove ‘_’ (default: True)

Returns:

Camel text.

Return type:

str

nodeps.to_latin9(chars)[source]

Converts string to latin9 hex.

Examples

>>> from nodeps import AUTHOR
>>> from nodeps import to_latin9
>>>
>>> to_latin9("ñ")
'f1'
>>>
>>> to_latin9(AUTHOR)
'4a6f73e920416e746f6e696f205075e972746f6c6173204d6f6e7461f1e973'
Parameters:

chars (str) – chars to converto to latin9

Returns:

hex str

Return type:

str

nodeps.tomodules(obj, suffix=True)[source]

Converts Iterable to A.B.C.

Examples

>>> from nodeps import tomodules
>>> assert tomodules('a b c') == 'a.b.c'
>>> assert tomodules('a b c.py') == 'a.b.c'
>>> assert tomodules('a/b/c.py') == 'a.b.c'
>>> assert tomodules(['a', 'b', 'c.py']) == 'a.b.c'
>>> assert tomodules('a/b/c.py', suffix=False) == 'a.b.c.py'
>>> assert tomodules(['a', 'b', 'c.py'], suffix=False) == 'a.b.c.py'
Parameters:
  • obj (Any) – iterable.

  • suffix (bool) – remove suffix.

Returns:

String A.B.C

Return type:

str

nodeps.urljson(data, rm=False)[source]

Url open json.

Examples

>>> import os
>>> from nodeps import urljson
>>> from nodeps import GIT
>>> from nodeps import GITHUB_TOKEN
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> if os.environ.get('GITHUB_TOKEN'):
...     github = urljson(f"https://api.github.com/repos/{GIT}/{NODEPS_PROJECT_NAME}")
...     assert github['name'] == NODEPS_PROJECT_NAME
>>>
>>> pypi = urljson(f"https://pypi.org/pypi/{NODEPS_PROJECT_NAME}/json")
>>> assert pypi['info']['name'] == NODEPS_PROJECT_NAME
Parameters:
  • data (str) – url

  • rm (bool) – use pickle cache or remove it before

Return type:

dict

nodeps.varname(index=2, lower=True, prefix=None, sep='_')[source]

Caller var name.

Examples

>>> from dataclasses import dataclass
>>> from nodeps import varname
>>>
>>> def function() -> str:
...     return varname()
>>>
>>> class ClassTest:
...     def __init__(self):
...         self.name = varname()
...
...     @property
...     def prop(self):
...         return varname()
...
...     # noinspection PyMethodMayBeStatic
...     def method(self):
...         return varname()
>>>
>>> @dataclass
... class DataClassTest:
...     def __post_init__(self):
...         self.name = varname()
>>>
>>> name = varname(1)
>>> Function = function()
>>> classtest = ClassTest()
>>> method = classtest.method()
>>> prop = classtest.prop
>>> dataclasstest = DataClassTest()
>>>
>>> def test_var():
...     assert name == 'name'
>>>
>>> def test_function():
...     assert Function == function.__name__.lower()
>>>
>>> def test_class():
...     assert classtest.name == ClassTest.__name__.lower()
>>>
>>> def test_method():
...     assert classtest.method() == ClassTest.__name__.lower()
...     assert method == 'method'
>>> def test_property():
...     assert classtest.prop == ClassTest.__name__.lower()
...     assert prop == 'prop'
>>> def test_dataclass():
...     assert dataclasstest.name == DataClassTest.__name__.lower()
class A:

    def __init__(self):

        self.instance = varname()

a = A()

var = varname(1)
Parameters:
  • index – index.

  • lower – lower.

  • prefix – prefix to add.

  • sep – split.

Returns:

Var name.

Return type:

Optional[str]

nodeps.which(data='sudo', raises=False)[source]

Checks if cmd or path is executable.

Examples

>>> from nodeps import which
>>> if which():
...    assert "sudo" in which()
>>> assert which('/bin/ls') == '/bin/ls'
>>> which("foo", raises=True) 
Traceback (most recent call last):
nodeps.modules.errors.CommandNotFoundError: foo
Attribute:

data: command or path. raises: raise exception if command not found

Raises:

CommandNotFound

Returns:

Cmd path or “”

Parameters:

raises (bool)

Return type:

str

nodeps.yield_if(data, pred=<function <lambda>>, split=' ', apply=None)[source]

Yield value if condition is met and apply function if predicate.

Examples

>>> from nodeps import yield_if
>>>
>>> assert list(yield_if([True, None])) == [True]
>>> assert list(yield_if('test1.test2', pred=lambda x: x.endswith('2'), split='.')) == ['test2']
>>> assert list(yield_if('test1.test2', pred=lambda x: x.endswith('2'), split='.',         apply=lambda x: x.removeprefix('test'))) == ['2']
>>> assert list(yield_if('test1.test2', pred=lambda x: x.endswith('2'), split='.',         apply=(lambda x: x.removeprefix('test'), lambda x: int(x)))) == [2]
Parameters:
  • data (Any) – data

  • pred (Callable) – predicate (default: if value)

  • split (str) – split char for str.

  • apply (Callable | tuple[Callable, ...] | None) – functions to apply if predicate is met.

Returns:

Yield values if condition is met and apply functions if provided.

Return type:

Generator

nodeps.yield_last(data, split=' ')[source]

Yield value if condition is met and apply function if predicate.

Examples

>>> from nodeps import yield_last
>>>
>>> assert list(yield_last([True, None])) == [(False, True, None), (True, None, None)]
>>> assert list(yield_last('first last')) == [(False, 'first', None), (True, 'last', None)]
>>> assert list(yield_last('first.last', split='.')) == [(False, 'first', None), (True, 'last', None)]
>>> assert list(yield_last(dict(first=1, last=2))) == [(False, 'first', 1), (True, 'last', 2)]
Parameters:
  • data (Any) – data.

  • split (str) – split char for str.

Returns:

Yield value and True when is the last item on iterable

Return type:

Iterator[tuple[bool, Any, None]]

class nodeps.GitUrl(data='', repo='')[source]

Bases: object

Parsed Git URL Helper Class.

Parameters:
data

Url, path or user (to be used with name), default None for cwd. Does not have .git unless is git+file

Type:

dataclasses.InitVar[str | nodeps.modules.path.Path | nodeps.modules.gh._SupportsWorkingDir | None]

repo

Repo name. If not None it will use data as the owner if not None, otherwise $GIT.

Type:

str

Examples

>>> import nodeps
>>> from nodeps import GitUrl
>>> from nodeps import Path
>>> from nodeps import NODEPS_PROJECT_NAME, CI
>>> from nodeps import NODEPS_MODULE_PATH
>>>
>>> p = GitUrl()
>>> p1 = GitUrl(nodeps.__file__)
>>> p2 = GitUrl(repo=NODEPS_PROJECT_NAME)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('github.com', 'j5pu', 'nodeps', 'https', ['https'], 'github', '/j5pu/nodeps', 'j5pu/nodeps')
>>> assert p2.url == p1.url == p.url == "https://github.com/j5pu/nodeps"
>>> if not CI:
...     assert NODEPS_MODULE_PATH == p1._path
>>>
>>> u = 'git@bitbucket.org:AaronO/some-repo.git'
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('bitbucket.org', 'AaronO', 'some-repo', 'ssh', ['ssh'], 'bitbucket', 'AaronO/some-repo.git', 'AaronO/some-repo')
>>> assert p.normalized == u
>>> assert p.url == u.removesuffix(".git")
>>> assert p.ownerrepo == "AaronO/some-repo"
>>>
>>> u = "https://github.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('github.com', 'cpython', 'cpython', 'https', ['https'], 'github', '/cpython/cpython', 'cpython/cpython')
>>> assert p.normalized == u + ".git"
>>> assert p.url == u
>>>
>>> p1 = GitUrl(data="cpython", repo="cpython")
>>> assert p == p1
>>>
>>> u = "git+https://github.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('github.com', 'cpython', 'cpython', 'https', ['git', 'https'], 'github', '/cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2githttps
('https://github.com/cpython/cpython.git', 'git+https://github.com/cpython/cpython', 'git+https://github.com/cpython/cpython.git')
>>> assert p.normalized == u.removeprefix("git+") + ".git"
>>> assert p.url == u
>>> assert p.url2githttps == u + ".git"
>>>
>>> u = "git+ssh://git@github.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('github.com', 'cpython', 'cpython', 'ssh', ['git', 'ssh'], 'github', '/cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2githttps
('git@github.com:cpython/cpython.git', 'git+ssh://git@github.com/cpython/cpython', 'git+https://github.com/cpython/cpython.git')
>>> assert p.normalized == 'git@github.com:cpython/cpython.git'
>>> assert p.url == u
>>> assert p.url2gitssh == u + ".git"
>>>
>>> u = "git@github.com:cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('github.com', 'cpython', 'cpython', 'ssh', ['ssh'], 'github', 'cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2git
('git@github.com:cpython/cpython.git', 'git@github.com:cpython/cpython', 'git://github.com/cpython/cpython.git')
>>> assert p.normalized == u + ".git"
>>> assert p.url == u
>>>
>>> u = "https://domain.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('domain.com', 'cpython', 'cpython', 'https', ['https'], 'gitlab', '/cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2https
('https://domain.com/cpython/cpython.git', 'https://domain.com/cpython/cpython', 'https://domain.com/cpython/cpython.git')
>>> assert p.normalized == u + ".git"
>>> assert p.url == u
>>>
>>> u = "git+https://domain.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('domain.com', 'cpython', 'cpython', 'https', ['git', 'https'], 'gitlab', '/cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2githttps
('https://domain.com/cpython/cpython.git', 'git+https://domain.com/cpython/cpython', 'git+https://domain.com/cpython/cpython.git')
>>> assert p.normalized == u.removeprefix("git+") + ".git"
>>> assert p.url == u
>>> assert p.url2githttps == u + ".git"
>>>
>>> u = "git+ssh://git@domain.com/cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('domain.com', 'cpython', 'cpython', 'ssh', ['git', 'ssh'], 'gitlab', '/cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2gitssh
('git@domain.com:cpython/cpython.git', 'git+ssh://git@domain.com/cpython/cpython', 'git+ssh://git@domain.com/cpython/cpython.git')
>>> assert p.normalized == "git@domain.com:cpython/cpython.git"
>>> assert p.url == u
>>> assert p.url2gitssh == u + ".git"
>>>
>>> u = "git@domain.com:cpython/cpython"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('domain.com', 'cpython', 'cpython', 'ssh', ['ssh'], 'gitlab', 'cpython/cpython', 'cpython/cpython')
>>> p.normalized, p.url, p.url2ssh
('git@domain.com:cpython/cpython.git', 'git@domain.com:cpython/cpython', 'git@domain.com:cpython/cpython.git')
>>> assert p.normalized == u + ".git"
>>> assert p.url == u
>>> assert p.url2ssh == u + ".git"
>>>
>>> u = "git+file:///tmp/cpython.git"
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('/tmp', '', 'cpython', 'file', ['git', 'file'], 'base', '/cpython.git', 'cpython')
>>> p.normalized, p.url
('git+file:///tmp/cpython.git', 'git+file:///tmp/cpython.git')
>>>
>>> p = GitUrl("git+file:///tmp/cpython")
>>> p.host, p.owner, p.repo, p.protocol, p.protocols, p.platform, p.pathname, p.ownerrepo
('/tmp', '', 'cpython', 'file', ['git', 'file'], 'base', '/cpython', 'cpython')
>>> p.normalized, p.url
('git+file:///tmp/cpython.git', 'git+file:///tmp/cpython.git')
>>> assert p.normalized == u
>>> assert p.url == u
data: dataclasses.InitVar[str | nodeps.modules.path.Path | nodeps.modules.gh._SupportsWorkingDir | None] = ''

Url, path or user (to be used with name), default None for cwd. Does not have .git unless is git+file

repo: str = ''

Repo name. If not None it will use data as the owner if not None, otherwise $GIT.

access_token: str = ''
branch: str = ''
domain: str = ''
groups_path: str = ''
owner: str = ''
ownerrepo: str = ''
path: str = ''
pathname: str = ''
path_raw: str = ''
platform: str = ''
protocol: str = ''
protocols: list[str]
port: str = ''
url: str | Path = ''
username: str = ''
api_repos_url: ClassVar[str] = 'https://api.github.com/repos'
admin(user='j5pu', rm=False)[source]

Check if user has admin permissions.

Examples

>>> import nodeps
>>> from nodeps import GitUrl
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> assert GitUrl(nodeps.__file__).admin() is True
>>> assert GitUrl(nodeps.__file__).admin("foo") is False
Parameters:
  • user (str) – default $GIT

  • rm (bool) – use pickle cache or remove it before

Returns:

bool

Return type:

bool

default(rm=False)[source]

Default remote branch.

Examples

>>> import nodeps
>>> from nodeps import GitUrl
>>>
>>> assert GitUrl(nodeps.__file__).default() == "main"
Parameters:

rm (bool) – remove cache

Returns:

bool

Return type:

str

format(protocol)[source]

Reformat URL to protocol.

github(rm=False)[source]

GitHub repos api.

Examples

>>> from nodeps import GitUrl
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> assert GitUrl().github()["name"] == NODEPS_PROJECT_NAME
Returns:

pypi information rm: use pickle cache or remove it.

Return type:

dict

Parameters:

rm (bool)

property groups

List of groups. GitLab only.

property host

Alias property for domain.

property is_github

GitHub platform.

property is_bitbucket

BitBucket platform.

property is_friendcode

FriendCode platform.

property is_assembla

Assembla platform.

property is_gitlab

GitLab platform.

property name

Alias property for repo.

property normalized

Normalize URL with .git.

public(rm=False)[source]

Check if repo ius public.

Examples

>>> import nodeps
>>> from nodeps import GitUrl
>>>
>>> assert GitUrl(nodeps.__file__).public() is True
>>> assert GitUrl(repo="pdf").public() is False
Parameters:

rm (bool) – remove cache

Returns:

bool

Return type:

bool

property resource

Alias property for domain.

property url2git

Rewrite url to git.

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> p = GitUrl(url)
>>> p.url2git
'git://github.com/Org/Private-repo.git'
property url2githttps

Rewrite url to git.

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> p = GitUrl(url)
>>> p.url2githttps
'git+https://github.com/Org/Private-repo.git'
property url2gitssh

Rewrite url to git.

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> p = GitUrl(url)
>>> p.url2gitssh
'git+ssh://git@github.com/Org/Private-repo.git'
property url2https

Rewrite url to https.

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> p = GitUrl(url)
>>> p.url2https
'https://github.com/Org/Private-repo.git'
property url2ssh

Rewrite url to ssh.

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> p = GitUrl(url)
>>> p.url2ssh
'git@github.com:Org/Private-repo.git'
property urls

All supported urls for a repo.

Examples

>>> from nodeps import GitUrl
>>> url = 'git@github.com:Org/Private-repo.git'
>>>
>>> GitUrl(url).urls
{'git': 'git://github.com/Org/Private-repo.git', 'git+https': 'git+https://github.com/Org/Private-repo.git', 'git+ssh': 'git+ssh://git@github.com/Org/Private-repo.git', 'https': 'https://github.com/Org/Private-repo.git', 'ssh': 'git@github.com:Org/Private-repo.git'}
property user

Alias property for _user or owner. _user == “git for ssh.

property valid

Checks if url is valid.

It is equivalent to validate().

Examples

>>> from nodeps import GitUrl
>>>
>>> url = 'git@github.com:Org/Private-repo.git'
>>> GitUrl(url).valid
True
>>> GitUrl.validate(url)
True
classmethod validate(data=None, repo=None)[source]

Validate url.

Examples

>>> from nodeps import GitUrl
>>>
>>> u = 'git@bitbucket.org:AaronO/some-repo.git'
>>> p = GitUrl(u)
>>> p.host, p.owner, p.repo
('bitbucket.org', 'AaronO', 'some-repo')
>>> assert p.valid is True
>>> assert GitUrl.validate(u) is True
Parameters:
  • data (str | Path | None) – user (when repo is provided, default GIT), url, path to get from git config if exists, default None for cwd.

  • repo (str | None) – repo to parse url from repo and get user from data

class nodeps.Gh(data='', repo='')[source]

Bases: GitUrl

Git Repo Class.

Examples

>>> import os
>>> import pytest
>>> import nodeps
>>> from nodeps import Gh
>>>
>>> r = Gh()
>>> r.url 
'https://github.com/.../nodeps'
Parameters:
  • owner – repo owner or Path

  • repo (str) – repo name or repo path for git+file scheme (default: None)

  • data (dataclasses.InitVar[str | nodeps.modules.path.Path | nodeps.modules.gh._SupportsWorkingDir | None])

Raises:

InvalidArgumentError – if GitUrl is not initialized with path

info(msg)[source]

Logger info.

Parameters:

msg (str)

warning(msg)[source]

Logger warning.

Parameters:

msg (str)

commit(msg=None, force=False, quiet=True)[source]

commit.

Raises:
Parameters:
Return type:

None

config_add(key, value)[source]

Add key and value to git repository config if not set.

Parameters:
Return type:

None

current()[source]

Current branch.

Examples

>>> from nodeps import Gh
>>>
>>> assert Gh().current() == 'main'
Return type:

str

gh_check_call(line)[source]

Runs git command and raises exception if error (stdout is not captured and shown).

Examples

>>> from nodeps import Gh
>>>
>>> assert Gh().gh_check_call("repo view") == 0  
Parameters:

line (str)

gh_stdout(line)[source]

Runs git command and returns stdout.

Examples

>>> from nodeps import Gh
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> assert NODEPS_PROJECT_NAME in Gh().gh_stdout("repo view")  
Parameters:

line (str)

git_check_call(line)[source]

Runs git command and raises exception if error (stdout is not captured and shown).

Examples

>>> from nodeps import Gh
>>>
>>> assert Gh().git_check_call("rev-parse --abbrev-ref HEAD") == 0
Parameters:

line (str)

git_stdout(line)[source]

Runs git command and returns stdout.

Examples

>>> from nodeps import Gh
>>>
>>> assert Gh().git_stdout("rev-parse --abbrev-ref HEAD") == "main"
Parameters:

line (str)

latest()[source]

Latest tag: git {c} describe –abbrev=0 –tags.

Return type:

str

next(part=Bump.PATCH, force=False)[source]

Show next version based on fix: feat: or BREAKING CHANGE:.

Parameters:
  • part (Bump) – part to increase if force

  • force (bool) – force bump

Return type:

str

pull(force=False, quiet=True)[source]

pull.

Raises:
Parameters:
Return type:

None

push(force=False, quiet=True)[source]

push.

Raises:
Parameters:
Return type:

None

secrets(force=False)[source]

Update GitHub repository secrets.

Parameters:

force (bool)

Return type:

int

secrets_names()[source]

List GitHub repository secrets names.

Return type:

list[str]

status(quiet=True)[source]

Git status instance and fetch if necessary.

Parameters:

quiet (bool)

Return type:

GitStatus

superproject()[source]

Git rev-parse –show-superproject-working-tree –show-toplevel.

Return type:

Path | None

tag(tag, quiet=True)[source]

Git tag.

Parameters:
Return type:

str | None

sync()[source]

Sync repository.

top()[source]

Git rev-parse –show-toplevel.

Return type:

Path | None

async nodeps.aioclone(owner=None, repository='nodeps', path=None)[source]

Async Clone Repository.

Examples

>>> import asyncio
>>> from nodeps import Path
>>> from nodeps import aioclone
>>>
>>> with Path.tempdir() as tmp:
...     directory = tmp / "1" / "2" / "3"
...     rv = asyncio.run(aioclone("octocat", "Hello-World", path=directory))
...     assert (rv / "README").exists()
Parameters:
  • owner (str | None) – github owner, None to use GIT or USER environment variable if not defined (Default: GIT)

  • repository (str) – github repository (Default: PROJECT)

  • path (Path | str | None) – path to clone (Default: repo)

Returns:

Path of cloned repository

Return type:

Path

nodeps.clone(owner=None, repository='nodeps', path=None)[source]

Clone Repository.

Examples

>>> import os
>>> from nodeps import Path
>>> from nodeps import clone
>>>
>>> with Path.tempdir() as tmp:
...     directory = tmp / "1" / "2" / "3"
>>> if not os.environ.get("CI"):
...     rv = clone("octocat", "Hello-World", directory)
...     assert (rv / "README").exists()
Parameters:
  • owner (str | None) – github owner, None to use GIT or USER environment variable if not defined (Default: GIT)

  • repository (str) – github repository (Default: PROJECT)

  • path (Path | str) – path to clone (Default: repo)

Returns:

CompletedProcess

Return type:

Path

nodeps.git_config_global()[source]

Sets values in git global config if not set.

class nodeps.PipMetaPathFinder[source]

Bases: MetaPathFinder

A importlib.abc.MetaPathFinder to auto-install missing modules using pip.

Examples

>>> import sys
>>> from nodeps import PipMetaPathFinder
>>> # noinspection PyTypeChecker
>>> sys.meta_path.append(PipMetaPathFinder)  
>>> # noinspection PyUnresolvedReferences
>>> import simplejson  
find_spec(path, target=None)[source]

Try to find a module spec for the specified module.

Parameters:
Return type:

ModuleSpec | None

nodeps.pipmetapathfinder()[source]

Context for PipMetaPathFinder.

Examples

>>> from nodeps import pipmetapathfinder
>>>
>>> with pipmetapathfinder():  
...    import simplejson  # type: ignore[attr-defined]
class nodeps.FileConfig(file=None, config=<factory>)[source]

Bases: object

FileConfig class.

Parameters:
file: Path | None = None
config: dict | configparser.ConfigParser
class nodeps.FrameSimple(back, code, frame, function, globals, lineno, locals, name, package, path, vars)[source]

Bases: object

Simple frame class.

Parameters:
back: types.FrameType
code: types.CodeType
frame: types.FrameType
function: str
globals: dict[str, Any]
lineno: int
locals: dict[str, Any]
name: str
package: str
path: Path
vars: dict[str, Any]
class nodeps.Passwd(data='root')[source]

Bases: object

Passwd class from either uid or user.

Args:

uid: int

User ID

user: str

Username

Attributes:

gid: int

Group ID

gecos: str

Full name

group: str

Group name

groups: tuple(str)

Groups list

home: Path

User’s home

shell: Path

User shell

uid: int

User ID (default: os.getuid() current user id)

user: str

Username

data: dataclasses.InitVar[Union[nodeps.modules.path.Passwd, nodeps.modules.path.Path, AnyStr, os.PathLike[str], os.PathLike[bytes], IO[AnyStr], str, int]] = 'root'
gid: int = None
gecos: str = None
group: str = None
groups: dict[str, int] = None
home: Path = None
shell: Path = None
uid: int = None
user: str = None
property is_su

Returns True if login as root, uid=0 and not SUDO_USER.

property is_sudo

Returns True if SUDO_USER is set.

property is_user

Returns True if user and not SUDO_USER.

classmethod from_login()[source]

Returns instance of nodeps:Passwd from ‘/dev/console’ on macOS and os.getlogin() on Linux.

classmethod from_sudo()[source]

Returns instance of nodeps:Passwd from SUDO_USER if set or current user.

classmethod from_root()[source]

Returns instance of nodeps:Passwd for root.

Parameters:

data (dataclasses.InitVar[Union[nodeps.modules.path.Passwd, nodeps.modules.path.Path, ~AnyStr, os.PathLike[str], os.PathLike[bytes], IO[~AnyStr], str, int]])

class nodeps.Path(*args, **kwargs)[source]

Bases: Path, PurePosixPath

Path helper class.

Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.

access(os_mode=2, *, dir_fd=None, effective_ids=True, follow_symlinks=False)[source]

Checks if file or directory exists and has access (returns None if file/directory does not exist.

Use the real uid/gid to test for access to a path `Real Effective IDs.`_.

  • real: user owns the completed.

  • effective: user invoking.

Examples

>>> import os
>>> from nodeps import Path
>>> from nodeps import MACOS
>>> from nodeps import LOCAL
>>> from nodeps import USER
>>>
>>> assert Path().access() is True
>>> if USER == "root":
...     assert Path('/usr/bin').access() is True
... else:
...     assert Path('/usr/bin').access() is False
>>> assert Path('/tmp').access(follow_symlinks=True) is True
>>> assert Path('/tmp').access(effective_ids=False, follow_symlinks=True) is True
>>> if MACOS and LOCAL:
...     assert Path('/etc/bashrc').access(effective_ids=False) is False
...     assert Path('/etc/sudoers').access(effective_ids=False, os_mode=os.R_OK) is False
Parameters:
  • os_mode – Operating-system mode bitfield. Can be F_OK to test existence, or the inclusive-OR of R_OK, W_OK, and X_OK (default: os.W_OK).

  • dir_fd – If not None, it should be a file descriptor open to a directory, and path should be relative; path will then be relative to that directory.

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: True).

  • follow_symlinks – If False, and the last element of the path is a symbolic link, access will examine the symbolic link itself instead of the file the link points to (default: False).

Note

Most operations will use the effective uid/gid (what the operating system looks at to make a decision whether you are allowed to do something), therefore this routine can be used in a suid/sgid environment to test if the invoking user has the specified access to the path.

When a setuid program (-rwsr-xr-x) executes, the completed changes its Effective User ID (EUID) from the default RUID to the owner of this special binary executable file:

  • euid: owner of executable (os.geteuid()).

  • uid: user starting the completed (os.getuid()).

Returns:

True if access.

See Also: Real Effective IDs.

add(*args, exception=False)[source]

Add args to self.

Examples

>>> from nodeps import Path
>>> import nodeps
>>>
>>> p = Path().add('a/a')
>>> assert Path() / 'a/a' == p
>>> p = Path().add(*['a', 'a'])
>>> assert Path() / 'a/a' == p
>>> p = Path(nodeps.__file__)
>>> p.add('a', exception=True)  
Traceback (most recent call last):
FileNotFoundError...
Parameters:
  • *args – parts to be added.

  • exception – raise exception if self is not dir and parts can not be added (default: False).

Raises:

FileNotFoundError – if self is not dir and parts can not be added.

Returns:

Compose path.

append_text(text, encoding=None, errors=None)[source]

Open the file in text mode, append to it, and close the file (creates file if not file).

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempfile() as tmp:
...    _ = tmp.write_text('Hello')
...    assert 'Hello World!' in tmp.append_text(' World!')
Parameters:
  • text – text to add.

  • encoding – encoding (default: None).

  • errors – raise error if there is no file (default: None).

Returns:

File text with text appended.

cd()[source]

Change dir context manager to self if dir or parent if file and exists.

Examples

>>> from nodeps import Path
>>>
>>> new = Path('/usr/local')
>>> p = Path.cwd()
>>> with new.cd() as prev:
...     assert new == Path.cwd()
...     assert prev == p
>>> assert p == Path.cwd()
Returns:

Old Pwd Path.

chdir()[source]

Change to self if dir or file parent if file and file exists.

Examples

>>> from nodeps import Path
>>>
>>> new = Path(__file__).chdir()
>>> assert new == Path(__file__).parent
>>> assert Path.cwd() == new
>>>
>>> new = Path(__file__).parent
>>> assert Path.cwd() == new
>>>
>>> Path("/tmp/foo").chdir()  
Traceback (most recent call last):
FileNotFoundError: ... No such file or directory: '/tmp/foo'
Raises:

FileNotFoundError – No such file or directory if path does not exist.

Returns:

Path with changed directory.

checksum(algorithm='sha256', block_size=65536)[source]

Calculate the checksum of a file.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempfile() as tmp:
...    _ = tmp.write_text('Hello')
...    assert tmp.checksum() == '185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969'
Parameters:
  • algorithm – hash algorithm (default: ‘sha256’).

  • block_size – block size (default: 65536).

Returns:

Checksum of file.

chmod(mode=None, effective_ids=True, exception=True, follow_symlinks=False, recursive=False)[source]

Change mode of self.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempfile() as tmp:
...     changed = tmp.chmod(777)
...     assert changed.stat().st_mode & 0o777 == 0o777
...     assert changed.stats().mode == "-rwxrwxrwx"
...     assert changed.chmod("o-x").stats().mode == '-rwxrwxrw-'
>>>
>>> Path("/tmp/foo").chmod()  
Traceback (most recent call last):
FileNotFoundError: ... No such file or directory: '/tmp/foo'
Raises:

FileNotFoundError – No such file or directory if path does not exist and exception is True.

Parameters:
  • mode – mode to change to (default: None).

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • follow_symlinks – resolve self if self is symlink (default: True).

  • exception – raise exception if self does not exist (default: True).

  • recursive – change owner of self and all subdirectories (default: False).

Returns:

Path with changed mode.

chown(passwd=None, effective_ids=True, exception=True, follow_symlinks=False, recursive=False)[source]

Change owner of path.

Examples

>>> from nodeps import Path
>>> from nodeps import Passwd
>>> from nodeps import MACOS
>>>
>>> with Path.tempfile() as tmp:
...     changed = tmp.chown(passwd=Passwd.from_root())
...     st = changed.stat()
...     assert st.st_gid == 0
...     assert st.st_uid == 0
...     stats = changed.stats()
...     assert stats.gid == 0
...     assert stats.uid == 0
...     assert stats.user == "root"
...     if MACOS:
...         assert stats.group == "wheel"
...         g = "admin"
...     else:
...         assert stats.group == "root"
...         g = "adm"
...     changed = tmp.chown(f"{os.getuid()}:{g}")
...     stats = changed.stats()
...     assert stats.group == g
...     assert stats.uid == os.getuid()
>>>
>>> Path("/tmp/foo").chown()  
Traceback (most recent call last):
FileNotFoundError: ... No such file or directory: '/tmp/foo'
Raises:
  • FileNotFoundError – No such file or directory if path does not exist and exception is True.

  • ValueError – passwd must be string with user:group.

Parameters:
  • passwd – user/group passwd to use, or string with user:group (default: None for USER).

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • exception – raise exception if self does not exist (default: True).

  • follow_symlinks – resolve self if self is symlink (default: True).

  • recursive – change owner of self and all subdirectories (default: False).

Returns:

Path with changed owner.

cmp(other)[source]

Determine, whether two files provided to it are the same or not.

By the same means that their contents are the same or not (excluding any metadata). Uses Cryptographic Hashes (using SHA256 - Secure hash algorithm 256) as a hash function.

Examples

>>> from nodeps import Path
>>> import nodeps
>>> import asyncio
>>>
>>> assert Path(nodeps.__file__).cmp(nodeps.__file__) is True
>>> assert Path(nodeps.__file__).cmp(asyncio.__file__) is False
Parameters:

other – other file to compare to

Returns:

True if equal.

cp(dest, contents=False, effective_ids=True, follow_symlinks=False, preserve=False)[source]

Wrapper for shell cp command to copy file recursivily and adding sudo if necessary.

Examples

>>> import sys
>>> from nodeps import Path
>>> from nodeps import SUDO, USER
>>> from nodeps import Passwd
>>>
>>> with Path.tempfile() as tmp:
...     changed = tmp.chown(passwd=Passwd.from_root())
...     copied = Path(__file__).cp(changed)
...     st = copied.stat()
...     assert st.st_gid == 0
...     assert st.st_uid == 0
...     stats = copied.stats()
...     assert "-rw-" in stats.mode
...     _ = tmp.chown()
...     assert copied.cmp(__file__)
>>> with Path.tempdir() as tmp:
...     _ = tmp.chmod("go+rx")
...     _ = tmp.chown(passwd=Passwd.from_root())
...     src = Path(__file__).parent
...     dirname = src.name
...     filename = Path(__file__).name
...
...     _ = src.cp(tmp)
...     destination = tmp / dirname
...     stats = destination.stats()
...     assert stats.mode == "drwxr-xr-x"
...     file = destination / filename
...     st = file.stat()
...     assert st.st_gid == 0
...     assert st.st_uid == 0
...     assert file.owner() == "root"
...     tmp = tmp.chown(recursive=True)
...     assert file.owner() == USER
...     assert file.cmp(__file__)
...
...     _ = src.cp(tmp, contents=True)
...     file = tmp / filename
...     assert file.cmp(__file__)
>>>
>>> Path("/tmp/foo").cp("/tmp/boo")  
Traceback (most recent call last):
FileNotFoundError: ... No such file or directory: '/tmp/foo'
Parameters:
  • dest – destination.

  • contents – copy contents of self to dest, cp src/ dest instead of cp src dest (default: False)`.

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • follow_symlinks – ‘-P’ the ‘cp’ default, no symlinks are followed, all symbolic links are followed when True ‘-L’ (actual files are copyed but if there are existing links will be left them untouched) (default: False) -H cp option is not implemented (default: False).

  • preserve – preserve file attributes (default: False).

Raises:

FileNotFoundError – No such file or directory if path does not exist.

Returns:

Dest.

exists()[source]

Check if file exists or is a broken link (super returns False if it is a broken link, we return True).

Examples

>>> from nodeps import Path
>>>
>>> Path(__file__).exists()
True
>>> with Path.tempcd() as tmp:
...    source = tmp.touch(tmp / "source")
...    destination = source.ln(tmp / "destination")
...    assert destination.is_symlink()
...    source.unlink()
...    assert destination.exists()
...    assert not pathlib.Path(destination).exists()
Returns:

True if file exists or is broken link.

classmethod expandvars(path=None)[source]

Return a Path instance from expanded environment variables in path.

Expand shell variables of form $var and ${var}. Unknown variables are left unchanged.

Examples

>>> from nodeps import Path
>>>
>>> Path.expandvars('~/repo')  
Path('~/repo')
>>> Path.expandvars('${HOME}/repo')  
Path('.../repo')
Returns:

Expanded Path.

file_in_parents(exception=True, follow_symlinks=False)[source]

Find up until file with name is found.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempfile() as tmpfile:
...     new = tmpfile / "sub" / "file.py"
...     assert new.file_in_parents(exception=False) == tmpfile.absolute()
>>>
>>> with Path.tempdir() as tmpdir:
...    new = tmpdir / "sub" / "file.py"
...    assert new.file_in_parents() is None
Parameters:
  • exception – raise exception if a file is found in parents (default: False).

  • follow_symlinks – resolve self if self is symlink (default: True).

Raises:

NotADirectoryError – … No such file or directory: ‘/tmp/foo’

Returns:

File found in parents (str) or None

find_up(uppermost=False)[source]

Find file or dir up.

Examples

>>> import email.mime.application
>>> import email
>>> import email.mime
>>> from nodeps import Path
>>>
>>> assert 'email/mime/__init__.py' in Path(email.mime.__file__, "__init__.py").find_up()
>>> assert 'email/__init__.py' in Path(email.__file__, "__init__.py").find_up(uppermost=True)
Parameters:

uppermost – find uppermost (default: False).

Return type:

FindUp

has(value)[source]

Checks all items in value exist in self.parts (not absolute and not relative).

Only checks parts and not resolved as checked by __contains__ or absolute.

Examples

>>> from nodeps import Path
>>>
>>> assert Path('/usr/local').has('/usr') is True
>>> assert Path('/usr/local').has('usr local') is True
>>> assert Path('/usr/local').has('home') is False
>>> assert Path('/usr/local').has('') is False
Parameters:

value – space separated list of items to check, or iterable of items.

Returns:

bool

installed()[source]

Check if file is installed.

Examples

>>> import pytest
>>> from nodeps import Path
>>>
>>> assert Path(pytest.__file__).installed() is True
ln(dest, force=True)[source]

Wrapper for super symlink_to to return the new path and changing the argument.

If symbolic link already exists and have the same source, it will not be overwritten.

Similar:

  • dest.symlink_to(src)

  • src.ln(dest) -> dest

  • os.symlink(src, dest)

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempcd() as tmp:
...     source = tmp.touch("source")
...     _ = source.ln(tmp / "destination")
...     destination = source.ln(tmp / "destination")
...     assert destination.is_symlink()
...     assert destination.resolve() == source.resolve()
...     assert destination.readlink().resolve() == source.resolve()
...
...     touch = tmp.touch(tmp / "touch")
...     _ = tmp.ln(tmp / "destination", force=False)  
Traceback (most recent call last):
FileExistsError:
Raises:

FileExistsError – if dest already exists or is a symbolic link with different source and force is False.

Parameters:
  • dest – link destination (ln -s self dest)

  • force – force creation of link, if file or link exists and is different (default: True)

ln_rel(dest)[source]

Create a symlink pointing to target from location.

Parameters:

dest – The location of the symlink itself.

mkdir(name='', passwd=None, mode=None, effective_ids=True, follow_symlinks=False)[source]

Add directory, make directory, change mode and return new Path.

Examples

>>> import getpass
>>> from nodeps import Path
>>> from nodeps import Passwd
>>>
>>> with Path.tempcd() as tmp:
...     directory = tmp('1/2/3/4')
...     assert directory.is_dir() is True
...     assert directory.owner() == getpass.getuser()
...
...     _ = directory.chown(passwd=Passwd.from_root())
...     assert directory.owner() == "root"
...     five = directory.mkdir("5")
...     assert five.text.endswith('/1/2/3/4/5') is True
...     assert five.owner() == "root"
...
...     six = directory("6")
...     assert six.owner() == "root"
...
...     seven = directory("7", passwd=Passwd())
...     assert seven.owner() == getpass.getuser()
...
...     _ = directory.chown(passwd=Passwd())
Parameters:
  • name – name.

  • passwd – group/user for chown, if None ownership will not be changed (default: None).

  • mode – mode.

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: True).

  • follow_symlinks – resolve self if self is symlink (default: True).

Raises:

NotADirectoryError – Directory can not be made because it’s a file.

Return type:

Path

mv(dest)[source]

Move.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempdir() as tmp:
...     name = 'dir'
...     pth = tmp(name)
...     assert pth.is_dir()
...     _ = pth.mv(tmp('dir2'))
...     assert not pth.is_dir()
...     assert tmp('dir2').is_dir()
...     name = 'file'
...     pth = tmp(name, "is_file")
...     assert pth.is_file()
...     _ = pth.mv(tmp('file2'))
...     assert not pth.is_file()
Parameters:

dest – destination.

Returns:

None.

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None, token=False)[source]

Open the file pointed by this path and return a file object, as the built-in open function does.

classmethod pickle(data=None, name=None, rm=False)[source]

Load or dumps pickle file from ~/.pickle directory.

Examples

>>> import pickle
>>> from nodeps import Path
>>>
>>> assert Path.pickle(name="test") is None
>>>
>>> obj = {'a': 1}
>>> _ = Path.pickle(obj, name="test")
>>> assert Path.pickle(name="test") == obj
>>>
>>> obj2 = {'a': 2}
>>> _ = Path.pickle(obj2, name="test", rm=True)
>>> assert Path.pickle(name="test") == obj2
>>>
>>> assert Path.pickle(name="test", rm=True) is None
Parameters:
  • data – data to pickle (default: None to read from file).

  • name – name.__name__ or name of object which will be used as file stem (default: None to get the name from __name__ in data)

  • rm – rm existing data.

Raises:

InvalidArgumentError – when no name can be derived from data.__name__ or not name provided

Returns:

Pickle object (None if no data exists) if data is None else None.

privileges(effective_ids=True)[source]

Return privileges of file.

Parameters:

effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: True).

Return type:

Privileges

classmethod purelib()[source]

Returns sysconfig purelib path.

realpath(exception=False)[source]

Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path.

Examples

>>> from nodeps import Path
>>>
>>> assert Path('/usr/local').realpath() == Path('/usr/local')
Parameters:

exception – raise exception if path does not exist (default: False).

Returns:

Path with real path.

relative(path)[source]

Return relative to path if is relative to path else None.

Examples

>>> from nodeps import Path
>>>
>>> assert Path('/usr/local').relative('/usr') == Path('local')
>>> assert Path('/usr/local').relative('/usr/local') == Path('.')
>>> assert Path('/usr/local').relative('/usr/local/bin') is None
Parameters:

path – path.

Returns:

Relative path or None.

rm(*args, effective_ids=True, follow_symlinks=False, missing_ok=True)[source]

Delete a folder/file (even if the folder is not empty).

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempdir() as tmp:
...     name = 'dir'
...     pth = tmp(name)
...     assert pth.is_dir()
...     pth.rm()
...     assert not pth.is_dir()
...     name = 'file'
...     pth = tmp(name, "is_file")
...     assert pth.is_file()
...     pth.rm()
...     assert not pth.is_file()
...     assert Path('/tmp/a/a/a/a')().is_dir()
Raises:

FileNotFoundError – … No such file or directory: ‘/tmp/foo’

Parameters:
  • *args – parts to add to self.

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • follow_symlinks – True for resolved (default: False).

  • missing_ok – missing_ok

rm_empty(preserve=True)[source]

Remove empty directories recursive.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempdir() as tmp:
...     first = tmp("1")
...
...     _ = tmp('1/2/3/4')
...     first.rm_empty()
...     assert first.exists() is True
...     assert Path("1").exists() is False
...
...     _ = tmp('1/2/3/4')
...     first.rm_empty(preserve=False)
...     assert first.exists() is False
...
...     _ = tmp('1/2/3/4/5/6/7.py', file="is_file")
...     first.rm_empty()
...     assert first.exists() is True
Parameters:

preserve – preserve top directory (default: True).

setid(name=None, uid=True, effective_ids=True, follow_symlinks=False)[source]

Sets the set-user-ID-on-execution or set-group-ID-on-execution bits.

Works if interpreter binary is setuid u+s,+x (-rwsr-xr-x), and:

  • executable script and setuid interpreter on shebang (#!/usr/bin/env setuid_interpreter).

  • setuid_interpreter -m module (venv would be created as root

Works if interpreter binary is setuid g+s,+x (-rwxr-sr-x), and:

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempdir() as p:
...     a = p.touch('a')
...     _ = a.setid()
...     assert a.stats().suid is True
...     _ = a.setid(uid=False)
...     assert a.stats().sgid is True
...
...     a.rm()
...
...     _ = a.touch()
...     b = a.setid('b')
...     assert b.stats().suid is True
...     assert a.cmp(b) is True
...
...     _ = b.setid('b', uid=False)
...     assert b.stats().sgid is True
...
...     _ = a.write_text('a')
...     assert a.cmp(b) is False
...     b = a.setid('b')
...     assert b.stats().suid is True
...     assert a.cmp(b) is True
Parameters:
  • name – name to rename if provided.

  • uid – True to set UID bit, False to set GID bit (default: True).

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • follow_symlinks – True for resolved, False for absolute and None for relative or doesn’t exist (default: True).

Returns:

Updated Path.

classmethod setid_executable_is()[source]

True if Set user ID execution bit is set.

classmethod setid_executable()[source]

Sets the set-user-ID-on-execution bits for sys.executable.

Returns:

Updated Path.

classmethod setid_executable_cp(name=None, uid=True)[source]

Sets the set-user-ID-on-execution or set-group-ID-on-execution bits for sys.executable.

Examples

>>> import shutil
>>> import subprocess
>>> from nodeps import Path, MACOS, USER
>>> def test():
...     f = Path.setid_executable_cp('setid_python_test')
...     assert subprocess.check_output([f, '-c', 'import os;print(os.geteuid())'], text=True) == '0\n'
...     if USER != "root":
...         assert subprocess.check_output([f, '-c', 'import os;print(os.getuid())'], text=True) != '0\n'
...     else:
...         assert subprocess.check_output([f, '-c', 'import os;print(os.getuid())'], text=True) == '0\n'
...     f.rm()
...     assert f.exists() is False
>>> test()
Parameters:
  • name – name to rename if provided or False to add ‘r’ to original name (default: False).

  • uid – True to set UID bit, False to set GID bit (default: True).

Returns:

Updated Path.

stats(follow_symlinks=False)[source]

Return result of the stat() system call on this path, like os.stat() with extra parsing for bits and root.

Examples

>>> from nodeps import Path
>>>
>>> rv = Path().stats()
>>> assert all([rv.root, rv.sgid, rv.sticky, rv.suid]) is False
>>>
>>> with Path.tempfile() as file:
...     _ = file.chmod('u+s,+x')
...     assert file.stats().suid is True
...     _ = file.chmod('g+s,+x')
...     assert file.stats().sgid is True
Parameters:

follow_symlinks – If False, and the last element of the path is a symbolic link, stat will examine the symbolic link itself instead of the file the link points to (default: False).

Returns:

gid: file GID group: file group name mode: file mode string formatted as ‘-rwxrwxrwx’ own: user and group string formatted as ‘user:group’ passwd: instance of nodeps:Passwd for file owner result: result of os.stat root: is owned by root sgid: group executable and sticky bit (GID bit), members execute as the executable group (i.e.: crontab) sticky: sticky bit (directories), new files created in this directory will be owned by the directory’s owner suid: user executable and sticky bit (UID bit), user execute and as the executable owner (i.e.: sudo) uid: file UID user: file owner name

Return type:

PathStat namedtuple nodeps.PathStat

sudo(force=False, to_list=True, os_mode=2, effective_ids=True, follow_symlinks=False)[source]

Returns sudo command if path or ancestors exist and is not own by user and sudo command not installed.

Examples

>>> from nodeps import which
>>> from nodeps import Path
>>> from nodeps import SUDO
>>>
>>> assert Path('/tmp').sudo(to_list=False, follow_symlinks=True) == ''
>>> if SUDO:
...     assert "sudo" in Path('/usr/bin').sudo(to_list=False)
>>> assert Path('/usr/bin/no_dir/no_file.text').sudo(to_list=False) == SUDO
>>> assert Path('no_dir/no_file.text').sudo(to_list=False) == ''
>>> assert Path('/tmp').sudo(follow_symlinks=True) == []
>>> if SUDO:
...     assert Path('/usr/bin').sudo() == [SUDO]
... else:
...     assert Path('/usr/bin').sudo() == []
Parameters:
  • force – if sudo installed and user is not root, return always sudo path

  • to_list – return starred/list for command with no shell (default: True).

  • os_mode – Operating-system mode bitfield. Can be F_OK to test existence, or the inclusive-OR of R_OK, W_OK, and X_OK (default: os.W_OK).

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: True).

  • follow_symlinks – If False, and the last element of the path is a symbolic link, access will examine the symbolic link itself instead of the file the link points to (default: False).

Returns:

sudo or “”, str or list.

sys()[source]

Insert self absolute if exists to sys.path 0 if it is not in sys.path.

Examples

>>> import sys
>>> from nodeps import Path
>>>
>>> cwd = Path.cwd()
>>> cwd.sys()
>>> assert str(cwd.absolute()) in sys.path
property text

Path as text.

Examples

>>> from nodeps import Path
>>>
>>> assert Path('/usr/local').text == '/usr/local'
Returns:

Path string.

classmethod tempcd(suffix=None, prefix=None, directory=None)[source]

Create temporaly directory, change to it and return it.

This has the same behavior as mkdtemp but can be used as a context manager.

Upon exiting the context, the directory and everything contained in it are removed.

Examples

>>> from nodeps import Path
>>>
>>> work = Path.cwd()
>>> with Path.tempcd() as tmp:
...     assert tmp.exists() and tmp.is_dir()
...     assert Path.cwd() == tmp.resolve()
>>> assert work == Path.cwd()
>>> assert tmp.exists() is False
Parameters:
  • suffix – If ‘suffix’ is not None, the directory name will end with that suffix, otherwise there will be no suffix. For example, …/T/tmpy5tf_0suffix

  • prefix – If ‘prefix’ is not None, the directory name will begin with that prefix, otherwise a default prefix is used.. For example, …/T/prefixtmpy5tf_0

  • directory – If ‘directory’ is not None, the directory will be created in that directory (must exist, otherwise a default directory is used. For example, DIRECTORY/tmpy5tf_0

Returns:

Directory Path.

classmethod tempdir(suffix=None, prefix=None, directory=None)[source]

Create and return tmp directory. This has the same behavior as mkdtemp but can be used as a context manager.

Upon exiting the context, the directory and everything contained in it are removed.

Examples

>>> from nodeps import Path
>>>
>>> work = Path.cwd()
>>> with Path.tempdir() as tmpdir:
...     assert tmpdir.exists() and tmpdir.is_dir()
...     assert Path.cwd() != tmpdir
...     assert work == Path.cwd()
>>> assert tmpdir.exists() is False
Parameters:
  • suffix – If ‘suffix’ is not None, the directory name will end with that suffix, otherwise there will be no suffix. For example, …/T/tmpy5tf_0suffix

  • prefix – If ‘prefix’ is not None, the directory name will begin with that prefix, otherwise a default prefix is used.. For example, …/T/prefixtmpy5tf_0

  • directory – If ‘directory’ is not None, the directory will be created in that directory (must exist, otherwise a default directory is used. For example, DIRECTORY/tmpy5tf_0

Returns:

Directory Path.

classmethod tempfile(mode='w', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, directory=None, delete=True, *, errors=None)[source]

Create and return a temporary file.

Examples

>>> from nodeps import Path
>>>
>>> with Path.tempfile() as tmpfile:
...    assert tmpfile.exists() and tmpfile.is_file()
>>> assert tmpfile.exists() is False
Parameters:
  • mode – the mode argument to io.open (default “w+b”).

  • buffering – the buffer size argument to io.open (default -1).

  • encoding – the encoding argument to io.open (default None)

  • newline – the newline argument to io.open (default None)

  • delete – whether the file is deleted on close (default True).

  • suffix – prefix for filename.

  • prefix – prefix for filename.

  • directory – directory.

  • errors – the errors’ argument to io.open (default None)

Returns:

An object with a file-like interface; the name of the file is accessible as its ‘name’ attribute. The file will be automatically deleted when it is closed unless the ‘delete’ argument is set to False.

to_parent()[source]

Return Parent if is file and exists or self.

Examples

>>> from nodeps import Path
>>>
>>> assert Path(__file__).to_parent() == Path(__file__).parent
Returns:

Path of directory if is file or self.

touch(name='', passwd=None, mode=None, effective_ids=True, follow_symlinks=False)[source]

Add file, touch and return post_init Path. Parent paths are created.

Examples

>>> from nodeps import Path
>>> from nodeps import Passwd
>>>
>>> import getpass
>>> with Path.tempcd() as tmp:
...     file = tmp('1/2/3/4/5/6/root.py', file="is_file", passwd=Passwd.from_root())
...     assert file.is_file() is True
...     assert file.parent.owner() == getpass.getuser()
...     assert file.owner() == "root"
...
...     new = file.parent("user.py", file="is_file")
...     assert new.owner() == getpass.getuser()
...
...     touch = file.parent.touch("touch.py")
...     assert touch.owner() == getpass.getuser()
...
...     last = (file.parent / "last.py").touch()
...     assert last.owner() == getpass.getuser()
...     assert last.is_file() is True
...
...     file.rm()
Parameters:
  • name – name.

  • passwd – group/user for chown, if None ownership will not be changed (default: None).

  • mode – mode.

  • effective_ids – If True, access will use the effective uid/gid instead of the real uid/gid (default: False).

  • follow_symlinks – If False, I think is useless (default: False).

Returns:

Path.

with_suffix(suffix='')[source]

Sets default for suffix to “”, since pathlib.Path does not have default.

Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.

Examples

>>> from nodeps import Path
>>>
>>> Path("/tmp/test.txt").with_suffix()
Path('/tmp/test')
Parameters:

suffix – suffix (default: ‘’)

Returns:

Path.

class nodeps.PathStat(gid, group, mode, own, passwd, result, root, sgid, sticky, suid, uid, user)[source]

Bases: object

Helper class for nodeps.Path.stats().

Parameters:
  • gid (int) – file GID

  • group (str) – file group name

  • mode (str) – file mode string formatted as ‘-rwxrwxrwx’

  • own (str) – user and group string formatted as ‘user:group’

  • passwd (Passwd) – instance of nodeps:Passwd for file owner

  • result (stat_result) – result of os.stat

  • root (bool) – is owned by root

  • sgid (bool) – group executable and sticky bit (GID bit), members execute as the executable group (i.e.: crontab)

  • sticky (bool) – sticky bit (directories), new files created in this directory will be owned by the directory’s owner

  • suid (bool) – user executable and sticky bit (UID bit), user execute and as the executable owner (i.e.: sudo)

  • uid (int) – file UID

  • user (str) – file user name

gid: int
group: str
mode: str
own: str
passwd: Passwd
result: stat_result
root: bool
sgid: bool
sticky: bool
suid: bool
uid: int
user: str
nodeps.toiter(obj, always=False, split=' ')[source]

To iter.

Examples

>>> import pathlib
>>> from nodeps import toiter
>>>
>>> assert toiter('test1') == ['test1']
>>> assert toiter('test1 test2') == ['test1', 'test2']
>>> assert toiter({'a': 1}) == {'a': 1}
>>> assert toiter({'a': 1}, always=True) == [{'a': 1}]
>>> assert toiter('test1.test2') == ['test1.test2']
>>> assert toiter('test1.test2', split='.') == ['test1', 'test2']
>>> assert toiter(pathlib.Path("/tmp/foo")) == ('/', 'tmp', 'foo')
Parameters:
  • obj – obj.

  • always – return any iterable into a list.

  • split – split for str.

Returns:

Iterable.

class nodeps.Project(data=None, rm=False)[source]

Bases: object

Project Class.

Parameters:
data: Path | str | ModuleType = None

current working directory)

Type:

File, directory or name (str or path with one word) of project (default

brewfile: Path | None = None

Data directory Brewfile

ci: bool = False

running in CI or tox

data_dir: Path | None = None

Data directory

directory: Path | None = None

Parent of data if data is a file or None if it is a name (one word)

docsdir: Path | None = None

Docs directory

gh: Gh = None
git: str = 'git'

git -C directory if self.directory is not None

installed: bool = False
name: str = None

Pypi project name from setup.cfg, pyproject.toml or top name or self.data when is one word

profile: Path | None = None

Data directory profile.d

pyproject_toml: FileConfig
repo: Path = None

top or superproject

root: Path = None

pyproject.toml or setup.cfg parent or superproject or top directory

source: Path | None = None

sources directory, parent of __init__.py or module path

clean_match: ClassVar[list[str]] = ['*.egg-info', 'build', 'dist']
rm: dataclasses.InitVar[bool] = False

remove cache

info(msg)[source]

Logger info.

Parameters:

msg (str)

warning(msg)[source]

Logger warning.

Parameters:

msg (str)

bin(executable=None, version='3.11')[source]

Bin directory.

Args;

executable: command to add to path version: python version

Parameters:
  • executable (str | None)

  • version (str)

Return type:

Path

brew(c=None)[source]

Runs brew bundle.

Parameters:

c (str | None)

Return type:

int

browser(version='3.11', quiet=True)[source]

Build and serve the documentation with live reloading on file changes.

Parameters:
  • version (str) – python version

  • quiet (bool) – quiet mode (default: True)

Return type:

int

build(version='3.11', quiet=True, rm=False)[source]

Build a project venv, completions, docs and clean.

Parameters:
  • version (str) – python version (default: PYTHON_DEFAULT_VERSION)

  • quiet (bool) – quiet mode (default: True)

  • rm (bool) – remove cache

Return type:

Path | None

builds(quiet=True, rm=False)[source]

Build a project venv, completions, docs and clean.

Parameters:
  • quiet (bool) – quiet mode (default: True)

  • rm (bool) – remove cache

Return type:

None

buildrequires()[source]

pyproject.toml build-system requires.

Return type:

list[str]

clean()[source]

Clean project.

Return type:

None

completions(uninstall=False)[source]

Generate completions to /usr/local/etc/bash_completion.d.

Parameters:

uninstall (bool)

coverage()[source]

Runs coverage.

Return type:

int

dependencies()[source]

Dependencies from pyproject.toml or distribution.

Return type:

list[str]

distribution()[source]

Distribution.

Return type:

Distribution | None

docker(quiet=True)[source]

Docker push.

Parameters:

quiet (bool) – quiet mode (default: True)

Return type:

int

docs(version='3.11', quiet=True)[source]

Build the documentation.

Parameters:
  • version (str) – python version

  • quiet (bool) – quiet mode (default: True)

Return type:

int

executable(version='3.11')[source]

Executable.

Parameters:

version (str)

Return type:

Path

extras(as_list=False, rm=False)[source]

Optional dependencies from pyproject.toml or distribution.

Examples

>>> import typer
>>> from nodeps import Project
>>>
>>> nodeps = Project.nodeps()
>>> nodeps.extras()  
{'...': ['...
>>> nodeps.extras(as_list=True)  
['...
>>> Project(typer.__name__).extras()  
{'all':...
>>> Project("sampleproject").extras()  
{'dev':...
Parameters:
  • as_list (bool) – return as list

  • rm (bool) – remove cache

Returns:

dict or list

Return type:

dict[str, list[str]] | list[str]

classmethod nodeps()[source]

Project Instance of nodeps.

Return type:

Project

post(uninstall=False)[source]

Run post install for package: completions, brew and _post_install.py.

Parameters:

uninstall (bool)

Return type:

None

publish(part=Bump.PATCH, force=False, ruff=True, tox=False, quiet=True, rm=False)[source]

Publish runs runs tests, commit, tag, push, twine and clean.

Parameters:
  • part (Bump) – part to increase if force

  • force (bool) – force bump

  • ruff (bool) – run ruff

  • tox (bool) – run tox

  • quiet (bool) – quiet mode (default: True)

  • rm (bool) – remove cache

pypi(rm=False)[source]

Pypi information for a package.

Examples

>>> from nodeps import Project
>>> from nodeps import NODEPS_PROJECT_NAME
>>>
>>> assert Project(NODEPS_PROJECT_NAME).pypi()["info"]["name"] == NODEPS_PROJECT_NAME
Returns:

pypi information rm: use pickle cache or remove it.

Return type:

dict

Parameters:

rm (bool)

pytest(version='3.11')[source]

Runs pytest.

Parameters:

version (str)

Return type:

int

pytests()[source]

Runs pytest for all versions.

Return type:

int

classmethod repos(ret=ProjectRepos.NAMES, sync=False, archive=False, rm=False)[source]

Repo paths, names or Project instances under home, Archive or parent of nodeps top.

Examples

>>> from nodeps import Project
>>> from nodeps import NODEPS_PROJECT_NAME, Path, NODEPS_TOP
>>>
>>> assert NODEPS_PROJECT_NAME in Project.repos()
>>> assert NODEPS_PROJECT_NAME in Project.repos(ProjectRepos.DICT)
>>> assert NODEPS_PROJECT_NAME in Project.repos(ProjectRepos.INSTANCES)
>>> assert NODEPS_PROJECT_NAME in Project.repos(ProjectRepos.PY)
>>>
>>> shrc = Path.home() / "shrc/.git"
>>> if shrc.is_dir():
...     assert "shrc" not in Project.repos(ProjectRepos.PY)
...     assert "shrc" in Project.repos()
Parameters:
  • ret (ProjectRepos) – return names, paths, dict or instances

  • sync (bool) – push or pull all repos

  • archive (bool) – look for repos under ~/Archive

  • rm (bool) – remove cache

Return type:

list[Path] | list[str] | dict[str, Project | str] | None

requirement(version='3.11', install=False, upgrade=False, quiet=True, rm=False)[source]

Dependencies and optional dependencies from pyproject.toml or distribution.

Parameters:
Return type:

list[str] | int

requirements(upgrade=False, quiet=True, rm=False)[source]

Install dependencies and optional dependencies from pyproject.toml or distribution for python versions.

Parameters:
Return type:

None

ruff(version='3.11')[source]

Runs ruff.

Parameters:

version (str)

Return type:

int

test(version='3.11', ruff=True, tox=False, quiet=True)[source]

Test project, runs build, ruff, pytest and tox.

Parameters:
  • version (str) – python version

  • ruff (bool) – run ruff (default: True)

  • tox (bool) – run tox (default: True)

  • quiet (bool) – quiet mode (default: True)

Return type:

int

tests(ruff=True, tox=False, quiet=True)[source]

Test project, runs build, ruff, pytest and tox for all versions.

Parameters:
  • ruff (bool) – runs ruff

  • tox (bool) – runs tox

  • quiet (bool) – quiet mode (default: True)

Return type:

int

tox()[source]

Runs tox.

Return type:

int

twine(part=Bump.PATCH, force=False, rm=False)[source]

Twine.

Parameters:
  • part (Bump) – part to increase if force

  • force (bool) – force bump

  • rm (bool) – remove cache

Return type:

int

venv(version='3.11', clear=False, upgrade=False, quiet=True, rm=False)[source]

Creates venv, runs: write and requirements.

Parameters:
  • version (str) – python version

  • clear (bool) – remove venv

  • upgrade (bool) – upgrade packages

  • quiet (bool) – quiet

  • rm (bool) – remove cache

Return type:

None

venvs(upgrade=False, quiet=True, rm=False)[source]

Installs venv for all python versions in PYTHON_VERSIONS.

Parameters:
version(rm=True)[source]

Version from pyproject.toml, tag, distribution or pypi.

Parameters:

rm (bool) – remove cache

Return type:

str

version_pypi(rm=True)[source]

Pypi version.

Parameters:

rm (bool) – remove cache

Return type:

str | None

write(rm=False)[source]

Updates setup.cfg (cmdclass, scripts), pyproject.toml and docs conf.py.

[options.data_files] bin =

bin/*

;/etc/gitconfig = ; .gitconfig ;/etc/profile.d = ; lib/* ;etc/gh = ; gh/*

Parameters:

rm (bool) – remove cache

nodeps.root(func, *args, **kwargs)[source]

Runs function with euid set to 0.

Parameters:
  • func (Callable[P, T])

  • args (P.args)

  • kwargs (P.kwargs)

Return type:

T

class nodeps.ModuleSpec(name, loader, *, origin=None, loader_state=None, is_package=None)[source]

Bases: object

The specification for a module, used for loading.

A module’s spec is the source for information about the module. For data associated with the module, including source, use the spec’s loader.

name is the absolute name of the module. loader is the loader to use when loading the module. parent is the name of the package the module is in. The parent is derived from the name.

is_package determines if the module is considered a package or not. On modules this is reflected by the __path__ attribute.

origin is the specific location used by the loader from which to load the module, if that information is available. When filename is set, origin will match.

has_location indicates that a spec’s “origin” reflects a location. When this is True, __file__ attribute of the module is set.

cached is the location of the cached bytecode file, if any. It corresponds to the __cached__ attribute.

submodule_search_locations is the sequence of path entries to search when importing submodules. If set, is_package should be True–and False otherwise.

Packages are simply modules that (may) have submodules. If a spec has a non-None value in submodule_search_locations, the import system will consider modules loaded from the spec as packages.

Only finders (see importlib.abc.MetaPathFinder and importlib.abc.PathEntryFinder) should modify ModuleSpec instances.

property cached
property parent

The name of the module’s parent.

property has_location
nodeps.ThreadLock()

allocate_lock() -> lock object (allocate() is an obsolete synonym)

Create a new lock object. See help(type(threading.Lock())) for information about locks.

nodeps.RunningLoop

alias of _RunningLoop

nodeps.LockClass

alias of lock

class nodeps.BuildPy(dist, **kw)[source]

Bases: build_py

Build py with pth files installed.

Construct the command for dist, updating vars(self) with any keyword parameters.

Parameters:

dist (Distribution)

run()[source]

Run build py.

get_outputs(include_bytecode=1)[source]

Get outputs.

class nodeps.Develop(dist, **kw)[source]

Bases: develop

PTH Develop Install.

Construct the command for dist, updating vars(self) with any keyword parameters.

Parameters:

dist (Distribution)

run()[source]

Run develop.

class nodeps.EasyInstall(dist, **kw)[source]

Bases: easy_install

PTH Easy Install.

Construct the command for dist, updating vars(self) with any keyword parameters.

Parameters:

dist (Distribution)

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

Run easy install.

class nodeps.InstallLib(dist, **kw)[source]

Bases: install_lib

PTH Install Library.

Construct the command for dist, updating vars(self) with any keyword parameters.

Parameters:

dist (Distribution)

run()[source]

Run Install Library.

get_outputs()[source]

Get outputs.