Closed ehmatthes closed 8 months ago
PlatformDeployer
class?I've been avoiding starting unit tests because I called integration tests unit tests already, and I called e2e tests integration tests. I don't need to wait for renaming those to start actual unit tests.
real_unit_tests
. When renaming other tests, I can easily rename this directory.Command
class.__init__()
create_parser()
add_arguments()
DATABASE_URL
not being in log.__init__()
create_parser()
add_arguments()
handle()
_parse_cli_options()
_start_logging()
_create_log_dir()
_validate_command()
_validate_platform_arg()
(removed)_inspect_system()
_inspect_project()
_ignore_sd_logs()
_strip_secret_key()
_find_git_dir()
_check_git_status()
_diff_output_clean()
_get_dep_man_approach()
_check_using_poetry()
_get_current_requirements()
_get_req_txt_requirements()
_get_pipfile_requirements()
_get_poetry_requirements()
_add_simple_deploy_req()
write_output()
log_info()
execute_subp_run()
execute_command()
_confirm_automate_all()
get_confirmation()
add_packages()
add_package()
_add_req_txt_pkg()
_add_poetry_pkg()
_check_poetry_deploy_group()
_add_pipenv_pkg()
_write_pipfile_pkg()
commit_changes()
write_output()
and log_info()
to be logically consistent.log_info()
needs access to parsed CLI arg --no-logging
, which sets self.log_output
. So if we move it to utils, it will still need a reference to the sd Command
object.$ pip install -e .
get_string_from_output()
execute_subp_run()
command log commands before running them, unless skip_logging
.execute_command()
does this as well.--no-logging
has intended effect._inspect_project()
self.project_name
-> self.local_project_name
?# Get project name. There are a number of ways to get the project name; for now we'll assume the root url config file has not been moved from the default location.
execute_subp_run()
, execute_command()
:
execute_quick_command()
and...execute_slow_command()
. This matches why each of these is called, and needed. Name for purpose, rather than implementation.skip_logging
arg?llog_info(
_check_git_status()
git status --porcelain
, and not use git diff
??? simple_deploy_logs/
INSTALLED_APPS
: M blog/settings.py
-> need to run git diff to see what the change was.INSTALLED_APPS
: M blog/settings.py\n?? simple_deploy_logs/
.gitignore
.capfd
needed?git diff
?
git diff --name-only
and inspect output?(cont. from above)
test_clean_git_status()
test_unacceptable_settings_change()
test_unacceptable_file_changed()
test_sdlogs_exists()
test_add_sdlogs_gitignore()
test_add_sd_installed_apps()
test_sdlogs_exists_add_sdlogs_gitignore()
test_sdlogs_exists_sd_installed_apps()
test_sdlogs_gitignore_sd_installed_apps()
test_sdlogs_exists_sdlogs_gitgnore_sd_installed_apps()
--ignore-unclean-git
check_status_output()
? (No, more redirection probably not helpful.)All tests pass in isolation, but suite fails. ie, test_sdlogs_exists()
fails. Jumping to the temp dir shows this:
% cd ../../pytest-current/blog_project0
eric@Erics-Mac-Studio blog_project0 % git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .gitignore
modified: blog/settings.py
modified: blog/wsgi.py
modified: requirements.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.dockerignore
Dockerfile
fly.toml
no changes added to commit (use "git add" and/or "git commit -a")
That's a bunch of cruft from previous tests that passed:
platform_agnostic_tests/test_git_status_checks.py::test_clean_git_status[req_txt] PASSED [ 3%]
platform_agnostic_tests/test_git_status_checks.py::test_unacceptable_settings_change[req_txt] PASSED [ 6%]
platform_agnostic_tests/test_git_status_checks.py::test_unacceptable_file_changed[req_txt] PASSED [ 10%]
platform_agnostic_tests/test_git_status_checks.py::test_sdlogs_exists[req_txt] FAILED [ 13%]
msp.reset_test_project()
has module scope, but should have function scope?pytest platforms/
10s -> 30s)reset_test_project_function()
to test_git_status_checks.py
module, and set autouse=True
. (Good, it's being called every time, but still not letting all tests pass.)run_simple_deploy()
from running for this module? Maybe a conditional autouse? Even though it's not doing anything, it's causing tests to run 3x! (Override fixture in this specific module; SO answer.)test_unacceptable_settings_change
individually.test_unacceptable_settings_change
as part of suite.simple_deploy_logs/
is added to .gitignore? (Already done.)parse_req_txt()
toml
to requirements.txt?From a unit test run, this output is failing the git status check:
% git status --porcelain
M .gitignore
(b_env) eric@Erics-MacBook-Air blog_project0 % git diff --unified=0
diff --git a/.gitignore b/.gitignore
index 9c96d1b..4279ffb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,0 +9,3 @@ db.sqlite3
+
+# Ignore logs from simple_deploy.
+simple_deploy_logs/
# Ignore logs...
comment.)prep_automate_all()
Right now, prep_automate_all()
is called from simple_deploy. The only thing after it is adding simple_deploy as a requirement. This is a bunch of complexity with little benefit. The only benefit was not adding simple_deploy as a requirement until after prepping automate-all. But we've already added a log file. People can use Git to undo changes if they decide to abandon simple_deploy.
prep_automate_all()
from simple_deploy's handle()
to PlatformDeployer.deploy()
.validate_platform()
from deploy()
as well.handle()
cleanupplatform_deployer()
be created later, now that most platform-specific work has been moved out of simple_deploy.py? (Yes. It means making a couple minor modifications to user's project before confirming preliminary status, but these can easily be rolled back by user.)add_package()
already check if the package is present? If so, remove that check from each of the pkg_manager-specific methods.--automate-all
._add_poetry_pkg()
toml
library.)I saw one issue around newlines, with a diff that included a + and - of the same line. I'm not sure if that would be a common thing, or if that was a weird one-off issue. Keep this out for now, but keep it here in case it comes up again.
def test_clean_diff():
diff_output = dedent(
"""\
diff --git a/blog/settings.py b/blog/settings.py
index 6d40136..6395c5a 100644
--- a/blog/settings.py
+++ b/blog/settings.py
@@ -39,0 +40 @@ INSTALLED_APPS = [
+ 'simple_deploy',
@@ -134 +135 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
-LOGIN_URL = 'users:login'
\\ No newline at end of file
+LOGIN_URL = 'users:login'"""
)
cleaned_diff = sd_utils._clean_diff(diff_output.splitlines())
assert cleaned_diff == ["+ 'simple_deploy',"]
def _clean_diff(diff_lines):
...
# Ignore changes that relate to newlines, like this:
# -LOGIN_URL = 'users:login' <-- this line
# \\ No newline at end of file
# +LOGIN_URL = 'users:login'""" <--- and this line
# Remove the + or -, and find any lines that are repeated.
changes = [l[1:] for l in lines]
changes_to_remove = [c for c in changes if changes.count(c) == 2]
lines = [l for l in lines if l[1:] not in changes_to_remove]
The only platform-specific work that's still being done in simple_deploy is confirming the user wants to use a platform that only has preliminary support. But that work can be done after platform-agnostic work is done. This means all platform-specific work is done entirely in the platform-specific deployer module.
platofrm_deployer
object to end of handle()
.confirm_automate_all()
to platform-specific modules.confirm_preliminary()
from platform-specific deployer modules.
--automate-all
needs some unit tests! (Noted in #285)_confirm_automate_all()
should be moved to either simple_deploy, or maybe even utils.
_confirm_use_attached_db()
arg issue. Should it return True during automate-all runs?
The Fly refactoring work in #269 is going well. It's pointing to some simple_deploy refactoring that I want to keep separate from that issue, because it will affect all platforms.
sd_utils
and aplatform_utils
.Deployer
classes. (Don't check this task until all refactoring work is done; make sure reflects final state of refactoring work.) (Focus on this to after implementing plugin model.)execute_subp_run()
should log the commands that are run. That will remove a bunch of extraneous log lines from the platform-specific deploy modules.