Skip to content

Commit

Permalink
Tests: Misc package manager test improvements (#1738)
Browse files Browse the repository at this point in the history
Backports some test naming/strategy improvements from the
CNB, along with some general classic-specific clean-ups.

Towards #1616.
GUS-W-17679633.
  • Loading branch information
edmorley authored Jan 27, 2025
1 parent b90a475 commit 4c4cb7a
Show file tree
Hide file tree
Showing 57 changed files with 182 additions and 327 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ verify_ssl = true
name = "pypi"

[packages]
urllib3 = "*"

[dev-packages]

[requires]
python_version = "3.13"
18 changes: 18 additions & 0 deletions spec/fixtures/multiple_package_managers/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions spec/fixtures/pip_basic/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This shouldn't be installed, since requirements-test.txt should only be used on Heroku CI.
pytest
File renamed without changes.
2 changes: 2 additions & 0 deletions spec/fixtures/pip_basic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This tests that the setup.py fallback is not used when other package manager files exist.
raise RuntimeError("setup.py should not be run!")
2 changes: 2 additions & 0 deletions spec/fixtures/pip_compiled/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A quick to install package that relies on the Python headers from the base image.
git+https://github.com/pypa/wheel.git@0.44.0#egg=extension.dist&subdirectory=tests/testdata/extension.dist
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions spec/fixtures/pip_pysqlite3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pysqlite3
30 changes: 0 additions & 30 deletions spec/fixtures/pipenv_and_requirements_txt/Pipfile.lock

This file was deleted.

1 change: 0 additions & 1 deletion spec/fixtures/pipenv_and_requirements_txt/requirements.txt

This file was deleted.

11 changes: 2 additions & 9 deletions spec/fixtures/pipenv_basic/setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
# This file is here to confirm we don't try and create the fallback requirements
# file containing '-e .' when using Pipenv.

from setuptools import setup

setup(
name='test',
install_requires=['six'],
)
# This tests that the setup.py fallback is not used when other package manager files exist.
raise RuntimeError("setup.py should not be run!")
2 changes: 2 additions & 0 deletions spec/fixtures/poetry_basic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This tests that the setup.py fallback is not used when other package manager files exist.
raise RuntimeError("setup.py should not be run!")
6 changes: 0 additions & 6 deletions spec/fixtures/requirements_compiled/requirements.txt

This file was deleted.

17 changes: 0 additions & 17 deletions spec/fixtures/requirements_txt_and_poetry_lock/poetry.lock

This file was deleted.

6 changes: 0 additions & 6 deletions spec/fixtures/requirements_txt_and_poetry_lock/pyproject.toml

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions spec/fixtures/requirements_txt_and_setup_py/setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion spec/hatchet/ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:buildpacks) { [:default, 'heroku-community/inline'] }

context 'when using pip' do
let(:app) { Hatchet::Runner.new('spec/fixtures/ci_requirements', buildpacks:) }
let(:app) { Hatchet::Runner.new('spec/fixtures/ci_pip', buildpacks:) }

it 'installs both normal and test dependencies and uses cache on subsequent runs' do
app.run_ci do |test_run|
Expand Down
4 changes: 2 additions & 2 deletions spec/hatchet/django_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

context 'when Django is installed but manage.py does not exist' do
let(:app) { Hatchet::Runner.new('spec/fixtures/requirements_django_latest') }
let(:app) { Hatchet::Runner.new('spec/fixtures/django_latest') }

it 'skips collectstatic' do
app.deploy do |app|
Expand All @@ -44,7 +44,7 @@

context 'when DISABLE_COLLECTSTATIC=1' do
let(:app) do
Hatchet::Runner.new('spec/fixtures/requirements_django_latest', config: { 'DISABLE_COLLECTSTATIC' => '1' })
Hatchet::Runner.new('spec/fixtures/django_latest', config: { 'DISABLE_COLLECTSTATIC' => '1' })
end

it 'skips collectstatic' do
Expand Down
92 changes: 92 additions & 0 deletions spec/hatchet/package_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,96 @@
end
end
end

# TODO: Deprecate/sunset the setup.py file fallback.
context 'when there is only a setup.py' do
let(:app) { Hatchet::Runner.new('spec/fixtures/setup_py_only') }

it 'installs packages from setup.py using pip' do
app.deploy do |app|
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
remote: -----> Python app detected
remote: -----> Using Python #{DEFAULT_PYTHON_MAJOR_VERSION} specified in .python-version
remote: -----> Installing Python #{DEFAULT_PYTHON_FULL_VERSION}
remote: -----> Installing pip #{PIP_VERSION}
remote: -----> Installing dependencies using 'pip install --editable .'
remote: Obtaining file:///tmp/build_.*
remote: .+
remote: Installing collected packages: six, test
remote: Successfully installed six-.+ test-0.0.0
REGEX
end
end
end

# This case will be turned into an error in the future.
context 'when there are multiple package manager files' do
let(:app) { Hatchet::Runner.new('spec/fixtures/multiple_package_managers') }

it 'outputs a warning and builds with the first listed' do
app.deploy do |app|
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX))
remote: -----> Python app detected
remote:
remote: ! Warning: Multiple Python package manager files were found.
remote: !
remote: ! Exactly one package manager file should be present in your app's
remote: ! source code, however, several were found:
remote: !
remote: ! Pipfile.lock \\(Pipenv\\)
remote: ! requirements.txt \\(pip\\)
remote: ! poetry.lock \\(Poetry\\)
remote: !
remote: ! For now, we will build your app using the first package manager
remote: ! listed above, however, in the future this warning will become
remote: ! an error.
remote: !
remote: ! Decide which package manager you want to use with your app, and
remote: ! then delete the file\\(s\\) and any config from the others.
remote:
remote:
remote: ! Note: We recently added support for the package manager Poetry.
remote: ! If you are using a third-party Poetry buildpack you must remove
remote: ! it, otherwise the requirements.txt file it generates will cause
remote: ! the warning above.
remote:
remote: -----> Using Python #{DEFAULT_PYTHON_MAJOR_VERSION} specified in .python-version
remote: -----> Installing Python #{DEFAULT_PYTHON_FULL_VERSION}
remote: -----> Installing pip #{PIP_VERSION}
remote: -----> Installing Pipenv #{PIPENV_VERSION}
remote: -----> Installing dependencies using 'pipenv install --deploy'
remote: Installing dependencies from Pipfile.lock \\(.+\\)...
REGEX
end
end
end

context 'when the package manager has changed since the last build' do
let(:app) { Hatchet::Runner.new('spec/fixtures/pip_basic') }

it 'clears the cache before installing with the new package manager' do
app.deploy do |app|
FileUtils.rm('requirements.txt')
FileUtils.cp(FIXTURE_DIR.join('poetry_basic/pyproject.toml'), '.')
FileUtils.cp(FIXTURE_DIR.join('poetry_basic/poetry.lock'), '.')
app.commit!
app.push!
expect(clean_output(app.output)).to include(<<~OUTPUT)
remote: -----> Python app detected
remote: -----> Using Python #{DEFAULT_PYTHON_MAJOR_VERSION} specified in .python-version
remote: -----> Discarding cache since:
remote: - The package manager has changed from pip to poetry
remote: -----> Installing Python #{DEFAULT_PYTHON_FULL_VERSION}
remote: -----> Installing Poetry #{POETRY_VERSION}
remote: -----> Installing dependencies using 'poetry sync --only main'
remote: Installing dependencies from lock file
remote:
remote: Package operations: 1 install, 0 updates, 0 removals
remote:
remote: - Installing typing-extensions (4.12.2)
remote: -----> Discovering process types
OUTPUT
end
end
end
end
Loading

0 comments on commit 4c4cb7a

Please sign in to comment.