Skip to content

Commit

Permalink
Honor env.features when skip-install is set (#826)
Browse files Browse the repository at this point in the history
* Honor env.features when skip-install is set

Fixes: #729

* add release note

---------

Co-authored-by: Ofek Lev <[email protected]>
  • Loading branch information
viccie30 and ofek authored Nov 26, 2023
1 parent 4f4f5b2 commit 9c753a5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add `dependency_hash` method to the `environment` interface
- The state of installed dependencies for environments is saved as metadata so if dependency definitions have not changed then no checking is performed, which can be computationally expensive
- The `build` command now supports backends other than Hatchling
- Allow the use of `features` for environments when `skip-install` is enabled
- The default is now `__TOKEN__` when prompting for a username for the `publish` command
- Bump the minimum supported version of Hatchling to 1.17.1
- Bump the minimum supported version of `click` to 8.0.6
Expand Down
8 changes: 5 additions & 3 deletions src/hatch/env/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,13 @@ def dependencies_complex(self):

# Ensure these are checked last to speed up initial environment creation since
# they will already be installed along with the project
if not self.skip_install and self.dev_mode:
if (not self.skip_install and self.dev_mode) or self.features:
from hatch.utils.dep import get_project_dependencies_complex

dependencies_complex, optional_dependencies_complex = get_project_dependencies_complex(self)

all_dependencies_complex.extend(dependencies_complex.values())
if not self.skip_install and self.dev_mode:
all_dependencies_complex.extend(dependencies_complex.values())

for feature in self.features:
if feature not in optional_dependencies_complex:
Expand All @@ -336,7 +337,8 @@ def dependencies(self) -> list[str]:
"""
The list of all [project dependencies](../../config/metadata.md#dependencies) (if
[installed](../../config/environment/overview.md#skip-install) and in
[dev mode](../../config/environment/overview.md#dev-mode)) and
[dev mode](../../config/environment/overview.md#dev-mode)), selected
[optional dependencies](../../config/environment/overview.md#features), and
[environment dependencies](../../config/environment/overview.md#dependencies).
"""
if self._dependencies is None:
Expand Down
36 changes: 36 additions & 0 deletions tests/env/plugin/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,42 @@ def test_full_skip_install(self, isolation, isolated_data_dir, platform):

assert environment.dependencies == ['dep2', 'dep3']

def test_full_skip_install_and_features(self, isolation, isolated_data_dir, platform):
config = {
'project': {
'name': 'my_app',
'version': '0.0.1',
'dependencies': ['dep1'],
'optional-dependencies': {'feat': ['dep4']},
},
'tool': {
'hatch': {
'envs': {
'default': {
'dependencies': ['dep2'],
'extra-dependencies': ['dep3'],
'skip-install': True,
'features': ['feat'],
}
}
}
},
}
project = Project(isolation, config=config)
environment = MockEnvironment(
isolation,
project.metadata,
'default',
project.config.envs['default'],
{},
isolated_data_dir,
isolated_data_dir,
platform,
0,
)

assert environment.dependencies == ['dep2', 'dep3', 'dep4']

def test_full_dev_mode(self, isolation, isolated_data_dir, platform):
config = {
'project': {'name': 'my_app', 'version': '0.0.1', 'dependencies': ['dep1']},
Expand Down

0 comments on commit 9c753a5

Please sign in to comment.