5

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! :)

Barzi2001
  • 989
  • 8
  • 24
  • Does this answer your question? [Including non-Python files with setup.py](https://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py) – ThePyGuy Sep 17 '22 at 14:42
  • Hum, not really. The problem is that I am using hatchling (not setuptools nor distutils) I have updated the question. – Barzi2001 Sep 17 '22 at 15:35
  • 1
    I found a solution: I have to add this `[tool.hatch.build.force-include] "scripts" = "mypackage/scripts"` but the problem is that it also install the `__pycache__` folders. :( – Barzi2001 Sep 17 '22 at 17:08
  • If that works,you can add it as answer; it'll help future readers – ThePyGuy Sep 17 '22 at 18:15

1 Answers1

3

The solution:

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

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

from here.

Barzi2001
  • 989
  • 8
  • 24