Skip to content
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

Upgrade tomlkit and bump Hatchling #174

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Unreleased

***Added:***

- Bump the minimum supported version of Hatchling
- Upgrade `tomlkit` for better formatting

### [1.0.0rc16](https://github.com/ofek/hatch/releases/tag/hatch-v1.0.0rc16) - 2022-03-20 ### {: #hatch-v1.0.0rc16 }

***Added:***
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies = [
"pyperclip>=1.8.2",
"rich>=11.2.0",
"tomli-w>=1.0",
"tomlkit>=0.9.2",
"tomlkit>=0.10.1",
"userpath~=1.8",
"virtualenv>=20.13.1",
]
Expand Down
1 change: 1 addition & 0 deletions tests/cli/config/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def test_project_location_complex_set_first_project(hatch, config_file, helpers,
f"""
New setting:
project = "foo"

[projects.foo]
location = "{path}"
"""
Expand Down
54 changes: 19 additions & 35 deletions tests/cli/env/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def test_incompatible_matrix_partial(hatch, helpers, temp_dir, config_file):

@pytest.mark.requires_internet
def test_install_project_default_dev_mode(
hatch, helpers, temp_dir, platform, config_file, default_virtualenv_installed_packages
hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements
):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -760,20 +760,14 @@ def test_install_project_default_dev_mode(

with VirtualEnv(env_path, platform):
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
lines = output.strip().splitlines()
for package in default_virtualenv_installed_packages:
lines.remove(package)
requirements = extract_installed_requirements(output.splitlines())

assert len(lines) == 3
assert lines[0].startswith('editables==')
assert lines[1] == '# Editable install with no version control (my-app==0.0.1)'
assert lines[2].lower() == f'-e {str(project_path).lower()}'
assert len(requirements) == 1
assert requirements[0].lower() == f'-e {str(project_path).lower()}'


@pytest.mark.requires_internet
def test_install_project_no_dev_mode(
hatch, helpers, temp_dir, platform, config_file, default_virtualenv_installed_packages
):
def test_install_project_no_dev_mode(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()

Expand Down Expand Up @@ -826,12 +820,10 @@ def test_install_project_no_dev_mode(

with VirtualEnv(env_path, platform):
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
lines = output.strip().splitlines()
for package in default_virtualenv_installed_packages:
lines.remove(package)
requirements = extract_installed_requirements(output.splitlines())

assert len(lines) == 1
assert lines[0].startswith('my-app @')
assert len(requirements) == 1
assert requirements[0].startswith('my-app @')


@pytest.mark.requires_internet
Expand Down Expand Up @@ -991,7 +983,7 @@ def test_post_install_commands_error(hatch, helpers, temp_dir, config_file):


@pytest.mark.requires_internet
def test_sync_dependencies(hatch, helpers, temp_dir, platform, config_file, default_virtualenv_installed_packages):
def test_sync_dependencies(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()

Expand Down Expand Up @@ -1055,19 +1047,15 @@ def test_sync_dependencies(hatch, helpers, temp_dir, platform, config_file, defa

with VirtualEnv(env_path, platform):
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
lines = output.strip().splitlines()
for package in default_virtualenv_installed_packages:
lines.remove(package)
requirements = extract_installed_requirements(output.splitlines())

assert len(lines) == 4
assert lines[0].startswith('binary==')
assert lines[1].startswith('editables==')
assert lines[2] == '# Editable install with no version control (my-app==0.0.1)'
assert lines[3].lower() == f'-e {str(project_path).lower()}'
assert len(requirements) == 2
assert requirements[0].startswith('binary==')
assert requirements[1].lower() == f'-e {str(project_path).lower()}'


@pytest.mark.requires_internet
def test_features(hatch, helpers, temp_dir, platform, config_file, default_virtualenv_installed_packages):
def test_features(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()

Expand Down Expand Up @@ -1123,12 +1111,8 @@ def test_features(hatch, helpers, temp_dir, platform, config_file, default_virtu

with VirtualEnv(env_path, platform):
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
lines = output.strip().splitlines()
for package in default_virtualenv_installed_packages:
lines.remove(package)

assert len(lines) == 4
assert lines[0].startswith('binary==')
assert lines[1].startswith('editables==')
assert lines[2] == '# Editable install with no version control (my-app==0.0.1)'
assert lines[3].lower() == f'-e {str(project_path).lower()}'
requirements = extract_installed_requirements(output.splitlines())

assert len(requirements) == 2
assert requirements[0].startswith('binary==')
assert requirements[1].lower() == f'-e {str(project_path).lower()}'
2 changes: 1 addition & 1 deletion tests/cli/env/test_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_unknown_type(hatch, helpers, temp_dir_data, config_file):


@pytest.mark.requires_internet
def test_all(hatch, helpers, temp_dir_data, config_file, default_virtualenv_installed_packages):
def test_all(hatch, helpers, temp_dir_data, config_file):
project_name = 'My App'

with temp_dir_data.as_cwd():
Expand Down
15 changes: 12 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,22 @@ def config_file(tmp_path) -> ConfigFile:


@pytest.fixture(scope='session')
def default_virtualenv_installed_packages():
def default_virtualenv_installed_requirements(helpers):
# PyPy installs extra packages by default
with TempVirtualEnv(sys.executable, PLATFORM):
output = PLATFORM.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
lines = output.strip().splitlines()
requirements = helpers.extract_requirements(output.splitlines())

yield lines
yield frozenset(requirements)


@pytest.fixture(scope='session')
def extract_installed_requirements(helpers, default_virtualenv_installed_requirements):
yield lambda lines: [
requirement
for requirement in helpers.extract_requirements(lines)
if requirement not in default_virtualenv_installed_requirements
]


@pytest.fixture
Expand Down
7 changes: 7 additions & 0 deletions tests/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def remove_trailing_spaces(text):
return ''.join(f'{line.rstrip()}\n' for line in text.splitlines(True))


def extract_requirements(lines):
for line in lines:
line = line.rstrip()
if line and not line.startswith('#'):
yield line


def get_current_timestamp():
return datetime.now(timezone.utc).timestamp()

Expand Down
8 changes: 4 additions & 4 deletions tests/venv/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_activation_path_env_var_missing(temp_dir, platform):
assert os.environ[env_var] == 'foo'


def test_context_manager(temp_dir, platform, default_virtualenv_installed_packages):
def test_context_manager(temp_dir, platform, extract_installed_requirements):
venv_dir = temp_dir / 'venv'
venv = VirtualEnv(venv_dir, platform)
venv.create(sys.executable)
Expand All @@ -117,23 +117,23 @@ def test_context_manager(temp_dir, platform, default_virtualenv_installed_packag

# Run here while we have cleanup
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')
assert output.strip().count('==') == len(default_virtualenv_installed_packages)
assert not extract_installed_requirements(output.splitlines())

assert os.environ['PATH'] == str(temp_dir)
assert os.environ['VIRTUAL_ENV'] == 'foo'
for env_var in VirtualEnv.IGNORED_ENV_VARS:
assert os.environ[env_var] == 'foo'


def test_creation_allow_system_packages(temp_dir, platform):
def test_creation_allow_system_packages(temp_dir, platform, extract_installed_requirements):
venv_dir = temp_dir / 'venv'
venv = VirtualEnv(venv_dir, platform)
venv.create(sys.executable, allow_system_packages=True)

with venv:
output = platform.run_command(['pip', 'freeze'], check=True, capture_output=True).stdout.decode('utf-8')

assert output.strip().count('==') > 0
assert len(extract_installed_requirements(output.splitlines())) > 0


def test_python_data(temp_dir, platform):
Expand Down