-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
AttributeError: 'SafeApplication' object has no attribute 'project' #1468
Comments
I managed to get the same error (or a similar one, not sure) with all environnments already created. │ /Users/tobi/Library/Application │
│ Support/pyapp/hatch/554652334309206614/1.9.3/lib/python3.11/site-packages/hatch/env/virtual.py:1 │
│ 16 in uv_path │
│ │
│ 113 │ │ │ # Prevent recursive loop │
│ 114 │ │ │ self.name == env_name │
│ 115 │ │ │ # Only if dependencies have been set by the user │
│ ❱ 116 │ │ │ or is_default_environment(env_name, self.app.project.config.internal_envs[en │
│ 117 │ │ ): │
│ 118 │ │ │ uv_env = self.app.get_environment(env_name) │
│ 119 │ │ │ self.app.prepare_environment(uv_env) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'SafeApplication' object has no attribute 'project' |
Latest version of that plugin? |
Yes |
Thanks for the mention @ofek 🙏 @Tobi-De I will get a look at this as soon as I can and follow up with some debugging steps once I have an idea. I'm actually on a business / vacation trip right now in Europe from the US and a bit jet-lagged so no promises on exact ETA to resolution, I'll do my best for something quick. |
Silly me, now that I've taken a closer look at the traceback, I've realized that yes, it's related to hatch-pip-compile. Sorry for bothering you @ofek
Don't worry, it's just annoying, it doesn't stop me from working. |
😅 I'm still out on vacation but it's looking like hatch I think this has to do with the new hatch/src/hatch/env/plugin/interface.py Lines 93 to 103 in 7986421
I'm debugging on a train in Portugal right now and it's slow going... I'll continue to provide more details. EDIT I'm working on this over at juftin/hatch-pip-compile#80 where I've got a minimal reproducible example |
Hey @ofek, just curious what what the recursive loop issue here? https://github.com/pypa/hatch/blame/6a147fc1d6e8f5c9e04ccbe28201b71a783f2ec8/src/hatch/env/virtual.py#L113 I ran into my own recursive error when trying to resolve this issue |
I fel like I'm on the right track to resolve this here - if I could replace the hatch/src/hatch/env/plugin/interface.py Lines 93 to 103 in 7986421
|
|
Can this be closed? |
@ofek I would love to get to a place where this code block uses a hatch/src/hatch/env/plugin/interface.py Lines 93 to 103 in 7986421
Currently lines 99-101 are uncovered in hatch's test suite and are only surfacing in I've tried to look into making a hatch PR for this but am a little lost, curious if you think switching over to a (FWIW I believe I've come up with a solution to this but it breaks a big part of my unit tests which switching to a |
I was unaware that |
Basically I'm creating an environment outside of the context of a I have a large test fixture (called assert original_requirements == [packaging.requirements.Requirement("hatch")]
pip_compile.toml_doc["project"]["dependencies"] = ["requests"]
pip_compile.update_pyproject()
test_environment = pip_compile.reload_environment("test")
pip_compile.application.prepare_environment(environment=test_environment)
new_lockfile_requirements = (
pip_compile.default_environment.piptools_lock.read_header_requirements()
)
assert new_lockfile_requirements == [packaging.requirements.Requirement("requests")] It's all a bit hacky, but basically I would like to test scenarios where an environment is created and all dependencies are installed, then a dependency changes and the environment is invoked again and it recognizes that new dependencies need to be installed (and the lockfile is regenerated). All of this hackiness worked before hatch 1.10.x - you can see that the test suite succeeds for older versions of hatch https://github.com/juftin/hatch-pip-compile/actions/runs/9226545268/job/25386557544?pr=80 If swapping a |
Like I said there I think literally the only reason is because of the test suite and procrastinating changing that much because a simple find/replace wouldn't quite be enough. In the example you showed you can just pass a real application to the environment like I would have to do for the test suite. |
Please let me know what I have to do (if anything)! |
I think you are all good - I've tried reworking my unit tests to instantiate an Application and pass it through but kept running into errors. My issues are in my test suite so I will likely just end up reworking my unit tests to be more of integration tests with the click CliRunner instead. I appreciate all of the help! |
Oh great, thank you! Please link that here when it's open so I can copy for my tests lol |
I was annoyed at my own procrastination so I updated every test and fixed the property #1546 |
Lol what a G |
I wasn't sure what to title this issue, but it seems to be a regression because I feel like it wasn't happening with the previous version of hatch.
If I have a custom environment, let's say
docs
, that inherits from the default environment which was not created beforehand, and I try to run a command in thedocs
environment, it will fail with the error below.This issue still happens, for example, if I have two custom environments,
dev
andtest
, withtest
inheriting fromdev
, if thedev
environment is not created beforehand, then trying to run a command in thetest
environment will result in the same error. If I'm not mistaken, previously hatch would create the base environment if there is one before trying to run the command.This is part of the
pyproject.toml
of the project that generate the error above, I'm using hatch-pip-compile but I doubt it has anything to do with this issue.I remove the dependencies key since it was not relevant
The text was updated successfully, but these errors were encountered: