Skip to content

Relax dependency of executing source scripts on handbook-tools package installation #24

@uribench

Description

@uribench

With the current implementation, the source code can be executed using handbook_tools/handbook.py only when the handbook-tools package is installed.

This is true for the development repository, as well as for Travis-CI.

It will be better to relax this dependency.

Background:
Given the following source file structure (partial):
handbook_tools/
├─ init.py
└─ handbook.py

The file init.py is non-empty and defines version.
The handbook.py script requires version, therefore tries to import it from its own directory.

This can be done using relative import:
from . import version as VERSION

But this gives the following error:
SystemError: Parent module '' not loaded, cannot perform relative import

According to the python documentation:

Note that relative imports are based on the name of the current module. Since the name of the main
module is always "main", modules intended for use as the main module of a Python application
must always use absolute imports.

When using absolute import:
from handbook_tools import version as VERSION

It works well when the code is installed as a package and executed using the package.
However, if the package is not installed and the code is executed from the source with handbook_tools/handbook.py it gives the following error:
ImportError: No module named 'handbook_tools'

Note that when using the absolute path as described above the problem is relevant to other scripts that relies on handbook_tools.

Possible Solutions:
Check if adding the parent directory (i.e., handbook_tool) to sys.path helps.
Alternatively, check if setting 'package' or 'path' in the script helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions