Skip to content

Commit 751b8ca

Browse files
authored
Fix builds for other backends (#1079)
1 parent b15daaf commit 751b8ca

File tree

2 files changed

+96
-51
lines changed

2 files changed

+96
-51
lines changed

src/hatch/env/virtual.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class VirtualEnvironment(EnvironmentInterface):
3030
def __init__(self, *args, **kwargs):
3131
super().__init__(*args, **kwargs)
3232

33-
project_name = self.metadata.name
34-
venv_name = project_name if self.name == 'default' else self.name
35-
3633
# Always compute the isolated app path for build environments
3734
hashed_root = sha256(str(self.root).encode('utf-8')).digest()
3835
checksum = urlsafe_b64encode(hashed_root).decode('utf-8')[:8]
3936

37+
project_name = self.metadata.name if 'project' in self.metadata.config else f'{checksum}-unmanaged'
38+
venv_name = project_name if self.name == 'default' else self.name
39+
4040
# Conditions requiring a flat structure for build env
4141
if (
4242
self.isolated_data_directory == self.platform.home / '.virtualenvs'
@@ -376,7 +376,7 @@ def _python_constraint(self) -> SpecifierSet:
376376
# Note that we do not support this field being dynamic because if we were to set up the
377377
# build environment to retrieve the field then we would be stuck because we need to use
378378
# a satisfactory version to set up the environment
379-
return SpecifierSet(self.metadata.core_raw_metadata.get('requires-python', ''))
379+
return SpecifierSet(self.metadata.config.get('project', {}).get('requires-python', ''))
380380

381381
@contextmanager
382382
def safe_activation(self):

tests/cli/build/test_build.py

Lines changed: 92 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,111 @@
1111

1212

1313
@pytest.mark.requires_internet
14-
def test_other_backend(hatch, temp_dir, helpers):
15-
project_name = 'My.App'
14+
class TestOtherBackend:
15+
def test_standard(self, hatch, temp_dir, helpers):
16+
project_name = 'My.App'
1617

17-
with temp_dir.as_cwd():
18-
result = hatch('new', project_name)
19-
assert result.exit_code == 0, result.output
18+
with temp_dir.as_cwd():
19+
result = hatch('new', project_name)
20+
assert result.exit_code == 0, result.output
2021

21-
path = temp_dir / 'my-app'
22-
data_path = temp_dir / 'data'
23-
data_path.mkdir()
22+
path = temp_dir / 'my-app'
23+
data_path = temp_dir / 'data'
24+
data_path.mkdir()
2425

25-
project = Project(path)
26-
config = dict(project.raw_config)
27-
config['build-system']['requires'] = ['flit-core']
28-
config['build-system']['build-backend'] = 'flit_core.buildapi'
29-
config['project']['version'] = '0.0.1'
30-
config['project']['dynamic'] = []
31-
del config['project']['license']
32-
project.save_config(config)
26+
project = Project(path)
27+
config = dict(project.raw_config)
28+
config['build-system']['requires'] = ['flit-core']
29+
config['build-system']['build-backend'] = 'flit_core.buildapi'
30+
config['project']['version'] = '0.0.1'
31+
config['project']['dynamic'] = []
32+
del config['project']['license']
33+
project.save_config(config)
3334

34-
build_directory = path / 'dist'
35-
assert not build_directory.is_dir()
35+
build_directory = path / 'dist'
36+
assert not build_directory.is_dir()
3637

37-
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
38-
result = hatch('build')
38+
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
39+
result = hatch('build')
3940

40-
assert result.exit_code == 0, result.output
41-
assert result.output == helpers.dedent(
42-
"""
43-
Creating environment: build
44-
Checking dependencies
45-
Syncing dependencies
46-
"""
47-
)
41+
assert result.exit_code == 0, result.output
42+
assert result.output == helpers.dedent(
43+
"""
44+
Creating environment: build
45+
Checking dependencies
46+
Syncing dependencies
47+
"""
48+
)
4849

49-
assert build_directory.is_dir()
50-
assert (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
51-
assert (build_directory / 'my_app-0.0.1.tar.gz').is_file()
50+
assert build_directory.is_dir()
51+
assert (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
52+
assert (build_directory / 'my_app-0.0.1.tar.gz').is_file()
5253

53-
build_directory.remove()
54-
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
55-
result = hatch('build', '-t', 'wheel')
54+
build_directory.remove()
55+
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
56+
result = hatch('build', '-t', 'wheel')
5657

57-
assert result.exit_code == 0, result.output
58-
assert not result.output
58+
assert result.exit_code == 0, result.output
59+
assert not result.output
5960

60-
assert build_directory.is_dir()
61-
assert (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
62-
assert not (build_directory / 'my_app-0.0.1.tar.gz').is_file()
61+
assert build_directory.is_dir()
62+
assert (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
63+
assert not (build_directory / 'my_app-0.0.1.tar.gz').is_file()
6364

64-
build_directory.remove()
65-
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
66-
result = hatch('build', '-t', 'sdist')
65+
build_directory.remove()
66+
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
67+
result = hatch('build', '-t', 'sdist')
6768

68-
assert result.exit_code == 0, result.output
69-
assert not result.output
69+
assert result.exit_code == 0, result.output
70+
assert not result.output
71+
72+
assert build_directory.is_dir()
73+
assert not (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
74+
assert (build_directory / 'my_app-0.0.1.tar.gz').is_file()
75+
76+
def test_legacy(self, hatch, temp_dir, helpers):
77+
path = temp_dir / 'tmp'
78+
path.mkdir()
79+
data_path = temp_dir / 'data'
80+
data_path.mkdir()
81+
82+
(path / 'pyproject.toml').write_text(
83+
"""\
84+
[build-system]
85+
requires = ["setuptools"]
86+
build-backend = "setuptools.build_meta"
87+
"""
88+
)
89+
(path / 'setup.py').write_text(
90+
"""\
91+
import setuptools
92+
setuptools.setup(name="tmp", version="0.0.1")
93+
"""
94+
)
95+
(path / 'tmp.py').write_text(
96+
"""\
97+
print("Hello World!")
98+
"""
99+
)
70100

71-
assert build_directory.is_dir()
72-
assert not (build_directory / 'my_app-0.0.1-py3-none-any.whl').is_file()
73-
assert (build_directory / 'my_app-0.0.1.tar.gz').is_file()
101+
build_directory = path / 'dist'
102+
assert not build_directory.is_dir()
103+
104+
with path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
105+
result = hatch('build')
106+
107+
assert result.exit_code == 0, result.output
108+
assert result.output == helpers.dedent(
109+
"""
110+
Creating environment: build
111+
Checking dependencies
112+
Syncing dependencies
113+
"""
114+
)
115+
116+
assert build_directory.is_dir()
117+
assert (build_directory / 'tmp-0.0.1-py3-none-any.whl').is_file()
118+
assert (build_directory / 'tmp-0.0.1.tar.gz').is_file()
74119

75120

76121
@pytest.mark.allow_backend_process

0 commit comments

Comments
 (0)