Skip to main content

Simple Module to resolve module namespace

Project description

module_name

Simple module to make it easy to run python files with -m flag.

The benefits of running with -m is that your relative imports will work. Running a python file as a script doesn't understand that it is part of a package.

usage: py-module-name [-h] [-f] [-d] path

positional arguments:
  path         path to python file

optional arguments:
  -h, --help   show this help message and exit
  -f, --flag   Will output -m flag if path is importable
  -d, --debug  Debug

Examples

> py-module-name module_name/resolve.py
module_name.resolve

> py-module-name -f module_name/resolve.py
-m 'module_name.resolve'

> py-module-name -f /tmp/not_package/standalone.py
'/tmp/not_package/standalone.py'

The -f flag is useful for use with scripting. I use it from my .vimrc to run files I am editing.

.vimrc

autocmd FileType python map <buffer> <S-r> :w<CR>:!tmux send-keys -t :.{bottom-right} "\%time \%run `py-module-name -f %:p`" enter<CR><CR>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

module_name-0.6.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

module_name-0.6.0-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file module_name-0.6.0.tar.gz.

File metadata

  • Download URL: module_name-0.6.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for module_name-0.6.0.tar.gz
Algorithm Hash digest
SHA256 e16c2425f779b2f193d24bc858afa94aed36869df38bdc42e14a7028d0b2ed6b
MD5 02b283cb8e7dc3a59b94ea6492d3682e
BLAKE2b-256 1125ff4b1ad56270798ecd0ed7c1bbe5674c3e5f7c2f60a229331d00dd27fba2

See more details on using hashes here.

File details

Details for the file module_name-0.6.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for module_name-0.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b07eedb8ed8f46729b6a1575af9066c6d9c4f21f01b33936546a5a1c62f16132
MD5 22b9be843bde06008c20e3c1780b4115
BLAKE2b-256 12c3743e1a310c8c5cba0703115736539dae488d9f6de80fde9cafac190a1ec8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page