Skip to main content

Utility functions for LogicBase

Project description

Utility Functions for Logic Bank, and others (no Logic Bank dependencies).

Addressing Python Path, for proper import operation

This is from stackoverflow. Essentially, many of us have discovered the hard way is that:

  • import statements often work in PyCharm

  • but fail in VSCode, Command Line, etc

Setting `PYTHONPATH` is what makes imports work. I use the following VSCODE .env content so that it works for any project:

PYTHONPATH=${PROJ_DIR}:${PYTHONPATH}

This is essentially what PyCharm does when you check Add Content Roots to PYTHONPATH in your run/debug configuration. It’s a helpful setting, but it spoils you because your code fails outside PyCharm.

Or, if you run in terminal, first export:

export PYTHONPATH=…

add_python_path

You may find it easier to address this in your application, by calling the following:

def add_python_path(project_dir: str, my_file: str) -> (str, str):
    """
    @param project_dir: enclosing path node, with optional "*" for starts-with (e.g., LogicBank, LogicBank*)
    @param my_file: callers __file__ variable
    @result (path_was_fixed, path)

For example, if you are several levels deep in a project were the root is `MyProjectRoot`:

import logic_bank_utils.util as logic_bank_utils

(did_fix_path, sys_env_info) = \
    logic_bank_utils.add_python_path(project_dir="MyProjectRoot", my_file=__file__)
print("\n" + did_fix_path + "\n\n" + sys_env_info + "\n\n")

Depends on:

  • Python 3.8

Change Log

0.3.0 - Initial Version

0.4.0 - Improved doc

0.5.0 - More formatting on return string

0.6.0 - Provide for my-project* (startsWith)

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

logicbankutils-0.6.0.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

logicbankutils-0.6.0-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

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