hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Local dependency changes are not reflected when using `hatch shell`

Open speksen-kb01 opened this issue 1 year ago • 4 comments

Hello,

I am trying to write two packages using a single repo. I have this simple structure:

  otherproject
    src/otherproject
      __init__.py
      main.py
    pyproject.toml
  testproject
    src/testproject
      __init__.py
      adder.py
    pyproject.toml

My otherproject depends on my testproject

otherproject/pyproject.toml content:

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

[project]
name = "otherproject"
version = "0.0.1"
dependencies = []

[tool.hatch.build.targets.wheel]
packages = ["src/otherproject"]

[tool.hatch.envs.default]
path = ".venv" 
dependencies = ["testproject @ {root:uri}/../testproject"]

and my testproject/pyproject.toml:

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

[project]
name = "testproject"
version = "0.0.1"
description = ''
dependencies = []

[tool.hatch.build.targets.wheel]
packages = ["src/testproject"]

[tool.hatch.envs.default]
path = ".venv"

The current issue I am facing is, whenever I cd otherproject && hatch shell my testproject changes are not reflected on my current environment. For ex: I have adder.py in my testproject:

def adder(a, b):
    return a + b

I add another function to my adder module:

def adder(a, b):
    return a + b

def multiplier(a, b):
    return a * b

After adding this function to my testproject module, I go into my otherproject module, and I hatch env prune && hatch shell for it to reflect my changes. But seems like it doesnt, the package that gets build is the old version with only adder function and not multiplier function. Seems like the old wheel is cached? It feels weird if I declare a local dependency in my current environment and the changes are not reflected when recreating the environment. Any ideas why this happens?

speksen-kb01 avatar Dec 22 '23 08:12 speksen-kb01

This is unsupported until workspaces functionality is implemented early next year.

ofek avatar Dec 24 '23 01:12 ofek

Ah, I see. I found this workaround for now: pip cache purge; hatch env prune; hatch shell but it isn't pretty. Makes me redownload all the dependencies. Another alternative I found is just pip install . in each package after hatch shell without declaring a local dependency, but well that makes everything pretty "manual" so to say. Saves me from redownloading all the dependencies tho. Is there any more workarounds to this problem that I haven't found? If not I'll just wait for the workspaces functionality and purge the cache.

speksen-kb01 avatar Dec 24 '23 06:12 speksen-kb01

Your workaround is reasonable yes! An optimization would be to purge from the cache only the package in question

ofek avatar Dec 24 '23 18:12 ofek

Alright, I'll just use this untill workspaces: pip cache remove *-0.0.1*; hatch env prune; hatch shell when I make any chances to local dependencies that my package depends on. @ofek thanks for the help, we can close this issue then

speksen-kb01 avatar Dec 25 '23 10:12 speksen-kb01