Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports for packaging #33

Open
benbrastmckie opened this issue Jul 15, 2024 · 0 comments
Open

Imports for packaging #33

benbrastmckie opened this issue Jul 15, 2024 · 0 comments

Comments

@benbrastmckie
Copy link
Owner

The model_checker project directory is flat, containing the following modules:

__main__.py (imports: __init__.py, model_structure.py)
__init__.py (imports: model_structure.py)
model_structure.py (imports: semantics.py, model_definitions.py, syntax.py)
semantics.py
model_definitions.py
syntax.py

Currently, module imports take the following form (viz __main__.py below):

from model_structure import (
    StateSpace,
    make_model_for,
    )

It is then possible to run the package with the following command:

python3 /path/to/.../model_checker /path/to/file/.../test_file.py

This all works nicely. However, to package and upload the software to PyPi, I have noticed that absolute imports are required as given below:

from model_checker.model_structure import (
    StateSpace,
    make_model_for,
    )

Now the package builds just fine, but the python3 command given above now longer works. I would like to find a way to leave the absolute imports while still making use of the python3 command that I am using to test the package. I know that it is common to build the package locally in editable mode with pip but I am using NixOS, and so using pip is a pain, requiring that I enter into a virtual environment. Here is something I've tried adding without success:

current_dir = os.path.dirname(__file__) # Get the directory path of the current file
project_root = os.path.abspath(os.path.join(current_dir, "..")) # Construct the full path to your project root
sys.path.append(project_root) # Add the project root to the Python path

The hope was that by adding the project root to the path, I could leave the absolute imports and run the python3 command without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant