hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Unable to build package with custom folder structure

Open AlessandroStaffolani opened this issue 1 year ago • 3 comments

I'm trying to setup the pyproject.toml for project that requires a custom folder structure. My current configuration allows me to install in editable mode the package, I can run tests and while developing everythings seems to be ok (I just need to set the right PYTHONPATH before executing the scripts).

However, if I build the package and I open the tar.gz, the package code is not included. Only the metadata are generated.

Here my structure:

hatchling-pyproject/
├── src/
│ ├── main/
│ │ └── lib/
│ │ └──── pyproject/
│ │ ├────── sub_package/
│ │ │ ├──── __init__.py
│ │ │ ├──── __version__.py
│ │ │ └──── main.py
│ └── test/
│ └────── lib/
│ └────────── pyproject/
│ ├────── __init__.py
│ └────── conftest.py
├── pyproject.toml
└── README.md

pyproject is my main package and I'd like to use it like this from pyproject import something.

This is my pyproject.toml:

[project]
name = "hatchling-pyproject"
description = "Test with hatchling build-backed pyproject.toml"
dynamic = ["version"]
requires-python = ">=3.11"
dependencies = [
    "numpy==1.26.4",
    "python-dotenv"
]

[project.optional-dependencies]
dev = [
    "coverage[toml]",
    "pytest",
    "pytest-cov",
    "build"
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/main/lib/pyproject"]

[tool.hatch.version]
path = "src/main/lib/pyproject/__version__.py"


[tool.pytest.ini_options]
addopts = "--junit-xml=test-report.xml --cov --cov-report term --cov-report xml:test-coverage.xml -v -r A"
pythonpath = "./src/main/lib"
testpaths = [
    "./src/test/lib",
]

[tool.coverage.report]
omit = [
    "src/test/lib/*",
]

I have also tried to set the source on my wheel target (source = ["src/main/lib"]). However, the result doesn't change.

Any idea?

System Version

OS: MacOS 14.2 M2 Python: 3.12 Hatch: 1.10

AlessandroStaffolani avatar May 21 '24 14:05 AlessandroStaffolani

Have you tried:

[tool.hatch.build.targets.wheel]
include = ["src/main/lib/pyproject/**"]

sirosc avatar Jul 31 '24 23:07 sirosc

Show build command and what artifact you are opening

ofek avatar Jul 31 '24 23:07 ofek

Thank you for your support.

After reviewing the situation, I realized the issue was on my end. I had generated the .gitignore file automatically using PyCharm, which included a rule to ignore the lib folder. As a result, hatch, by default, ignored these files as well.

You can go ahead and close the issue. I appreciate your help

AlessandroStaffolani avatar Aug 22 '24 06:08 AlessandroStaffolani