How to add package data to pyproject.toml when using hatchling?

Viewed 50

NOTE This question relates to hatch (not setuptools nor distutils).

I am developing my first package and I am following this guide.

My project structure is as follows:

mypackage
│   LICENSE
│   pyproject.toml
│   README.md
│   requiremets.txt            
├───docs
├───scripts          
├───src
│   └───mypackage
│          config.py
│          first_module.py
│          datatypes.py
│          utils.py
│          first_module.py
│          __init__.py         
└───tests

However, I noticed that in C:\Users\<User>\Miniconda3\envs\myenv\Lib\site-packages\mypackage there is only the content of ./mypackage/scr/mypackage of the above tree.

What I want to achieve is to install also the scripts folder, because in the source code I am defining a function

def open_tutorial() -> None:
    site_packages = next(
        p for p in sys.path if "site-packages" in p
    )
    open(site_packages+"\\mypackage\\scripts\\tutorial.py")

that would allow the user to run a code like the following

import mypackage as mpkg

mpkg.open_tutorial()

What I expect is that the scripts/tutorial.py opens in the user editor.

How to achieve my goal? I guess that I should edit something in the pyproject.toml file, or that I have to set hatch in some way but I have no idea how. Any suggestion?

Related question: I would like that to work for any OS, so any hints on how shall I change my open_tutorial() function is welcome! :)

1 Answers

The solution:

[tool.hatch.build.targets.wheel]
only-include = ["src/mypackage", "scripts"]

[tool.hatch.build.targets.wheel.sources]
"src" = ""
"scripts" = "mypackage/scripts"

from here.

Related