Skip to content

Commit 5fecac5

Browse files
authored
Revert "samconfig debug level logging fixed; documentation updated (#2891)" (#2918)
This reverts commit 2a13a69.
1 parent 1e91773 commit 5fecac5

File tree

8 files changed

+56
-96
lines changed

8 files changed

+56
-96
lines changed

designs/sam-config.md

+3-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Today users of SAM CLI need to invoke the CLI directly with all parameters suppl
99

1010
for e.g: `sam build --use-container --debug`
1111

12-
But often, during the lifecycle of building and deploying a serverless application. The same commands get run repeatedly to build, package and deploy, before solidifying into the final application.
12+
But often, during the lifecycle of building and deploying a serverless application. the same commands get run repeatedly to build, package and deploy, before solidifying into the final application.
1313

1414
These CLI commands are often long and have many changing parts.
1515

@@ -45,33 +45,16 @@ The suite of commands supported by SAM CLI would be aided by looking for a confi
4545

4646
This configuration would be used for specifiying the parameters that each of SAM CLI commands use and would be in TOML format.
4747

48-
Running a SAM CLI command now automatically looks for `samconfig.toml` file and if it finds it, it passes parameter through to the CLI.
49-
50-
Every command which uses parameters from the configuration file, prints out the location of `samconfig.toml` file it parses.
48+
Running a SAM CLI command now automatically looks for `samconfig.toml` file and if its finds it goes ahead with parameter passthroughs to the CLI.
5149

5250
```
5351
sam build
54-
Config file location: /home/xxxxxxxxxx/projects/app-samconfig/samconfig.toml
52+
Default Config file location: samconfig.toml
5553
..
5654
..
5755
..
5856
```
5957

60-
If no configuration file can be found at the project root directory, the command output will contain a warning.
61-
62-
```
63-
sam local invoke -t ./out/build/template.yaml
64-
Config file '/home/xxxxxxxxx/projects/app-samconfig/out/build/samconfig.toml' does not exist
65-
..
66-
..
67-
..
68-
```
69-
70-
Where is my `samconfig.toml`?
71-
---------------------------------
72-
73-
SAM CLI always expects `samconfig.toml` to be in the project root directory (where the template file is located). When neither template nor config file is specified through cli options, both of them are expected to be in the current working directory where SAM CLI command is running. However, when `--template-file` is used to point to the directory without config file, addition of `--config-file` option enables the use of `samconfig.toml`.
74-
7558
Why `samconfig.toml` not under `.aws-sam` directory?
7659
---------------------------------
7760

samcli/cli/cli_config_file.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ def __call__(self, config_path, config_env, cmd_names):
5757

5858
samconfig = SamConfig(config_file_dir, config_file_name)
5959

60-
# bringing samconfig file location up to info level,
61-
# to improve UX and make it clear where we're looking for samconfig file
62-
if samconfig.exists():
63-
click.echo(f"Config file location: {samconfig.path()}")
64-
else:
65-
click.secho(f"Config file '{samconfig.path()}' does not exist", fg="yellow")
60+
# Enable debug level logging by environment variable "SAM_DEBUG"
61+
if os.environ.get("SAM_DEBUG", "").lower() == "true":
62+
LOG.setLevel(logging.DEBUG)
63+
64+
LOG.debug("Config file location: %s", samconfig.path())
65+
66+
if not samconfig.exists():
67+
LOG.debug("Config file '%s' does not exist", samconfig.path())
6668
return resolved_config
6769

6870
try:
@@ -234,10 +236,8 @@ def decorator_customize_config_file(f):
234236
config_file_param_decls = ("--config-file",)
235237
config_file_attrs["help"] = (
236238
"The path and file name of the configuration file containing default parameter values to use. "
237-
"Its default value is 'samconfig.toml' in project root directory. Project root directory is defined by the "
238-
"template file location. When using config file and specifing --template-file SAM CLI expects samconfig.toml "
239-
"and the template file to be in the same directory. Alternatively, if --config-file is explicitly specified, "
240-
"it can point to a custom samconfig.toml location. For more information about configuration files, see "
239+
"Its default value is 'samconfig.toml' in project directory. For more information about configuration files, "
240+
"see: "
241241
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html."
242242
)
243243
config_file_attrs["default"] = "samconfig.toml"

samcli/cli/main.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def print_cmdline_args(func):
7474
"""
7575

7676
def wrapper(*args, **kwargs):
77+
if kwargs.get("config_file") and kwargs.get("config_env"):
78+
config_file = kwargs["config_file"]
79+
config_env = kwargs["config_env"]
80+
LOG.debug("Using config file: %s, config environment: %s", config_file, config_env)
7781
LOG.debug("Expand command line arguments to:")
7882
cmdline_args_log = ""
7983
for key, value in kwargs.items():
@@ -111,17 +115,8 @@ def cli(ctx):
111115
112116
The AWS Serverless Application Model extends AWS CloudFormation to provide a simplified way of defining the
113117
Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.
114-
115-
SAM CLI commands run in the project root directory which is the directory with SAM template file
116-
(template.{yml|yaml|json}). If no template file is specified explicitly, SAM CLI looks it up in the current
117-
working directory (where SAM CLI is running).
118-
119-
SAM CLI options can be either passed directly to the commands and/or stored in the config file (samconfig.toml),
120-
which is expected to be in the project root directory by default. It is also possible to specify a custom directory
121-
for the config file if necessary.
122-
123-
More in-depth guide about the SAM specification:
124-
https://github.com/aws/serverless-application-model.
118+
You can find more in-depth guide about the SAM specification here:
119+
https://github.com/awslabs/serverless-application-model.
125120
"""
126121
if global_cfg.telemetry_enabled is None:
127122
enabled = True

samcli/cli/options.py

-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ def callback(ctx, param, value):
2020
state.debug = value
2121
return value
2222

23-
# NOTE: --debug option should be eager to be evaluated before other parameters and to set log level to DEBUG
24-
# before any other option/parameter processing will require to output debug info.
25-
# Otherwise parameters are evaluated according to their order and if --debug is specified at the end of the command
26-
# some debug output can be lost
27-
# https://click.palletsprojects.com/en/7.x/advanced/#callback-evaluation-order
2823
return click.option(
2924
"--debug",
30-
is_eager=True,
3125
expose_value=False,
3226
is_flag=True,
3327
envvar="SAM_DEBUG",

samcli/commands/_utils/options.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,7 @@ def template_click_option(include_build=True):
217217
callback=partial(get_or_default_template_file_name, include_build=include_build),
218218
show_default=True,
219219
is_eager=True,
220-
help="AWS SAM template which references built artifacts for resources in the template (if applicable). "
221-
"Template file defines the root directory of the project and allows to point SAM CLI to the directory "
222-
"for build, local invocation etc. If template file is not specified explicitly SAM CLI expects it to be "
223-
"in the current working directory (where it is running). When using config file and specifing --template-file "
224-
"SAM CLI expects samconfig.toml and the template file to be in the same directory."
225-
"Alternatively, if --config-file is explicitly specified, it can point to a custom samconfig.toml location."
220+
help="AWS SAM template which references built artifacts for resources in the template. (if applicable)"
226221
if include_build
227222
else "AWS SAM template file.",
228223
)

tests/integration/buildcmd/build_integ_base.py

-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ def _verify_invoke_built_function(self, template_path, function_logical_id, over
172172
process_execute.process.wait()
173173

174174
process_stdout = process_execute.stdout.decode("utf-8")
175-
if process_stdout.startswith("Config file"):
176-
*_, process_stdout = process_stdout.partition("\n")
177175
self.assertEqual(json.loads(process_stdout), expected_result)
178176

179177

tests/integration/buildcmd/test_build_cmd.py

+22-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
"""
2-
Integration tests for Build comand
3-
"""
4-
5-
import logging
6-
import os
7-
import random
1+
import re
82
import shutil
93
import sys
10-
from pathlib import Path
4+
import os
5+
import logging
6+
import random
117
from unittest import skipIf
8+
from pathlib import Path
9+
from parameterized import parameterized, parameterized_class
10+
from subprocess import Popen, PIPE, TimeoutExpired
1211

1312
import pytest
14-
from parameterized import parameterized, parameterized_class
15-
from samcli.lib.utils import osutils
16-
from tests.testing_utils import (
17-
CI_OVERRIDE,
18-
IS_WINDOWS,
19-
RUNNING_ON_CI,
20-
SKIP_DOCKER_MESSAGE,
21-
SKIP_DOCKER_TESTS,
22-
run_command,
23-
)
2413

14+
from samcli.lib.utils import osutils
2515
from .build_integ_base import (
2616
BuildIntegBase,
27-
BuildIntegRubyBase,
28-
CachedBuildIntegBase,
2917
DedupBuildIntegBase,
30-
IntrinsicIntegBase,
18+
CachedBuildIntegBase,
19+
BuildIntegRubyBase,
3120
NestedBuildIntegBase,
21+
IntrinsicIntegBase,
22+
)
23+
from tests.testing_utils import (
24+
IS_WINDOWS,
25+
RUNNING_ON_CI,
26+
CI_OVERRIDE,
27+
run_command,
28+
SKIP_DOCKER_TESTS,
29+
SKIP_DOCKER_MESSAGE,
3230
)
3331

3432
LOG = logging.getLogger(__name__)
@@ -190,8 +188,8 @@ def test_unsupported_runtime(self):
190188
LOG.info(cmdlist)
191189
process_execute = run_command(cmdlist, cwd=self.working_dir)
192190
self.assertEqual(1, process_execute.process.returncode)
193-
output = "\n".join(process_execute.stdout.decode("utf-8").strip().splitlines())
194-
self.assertIn("Build Failed", output)
191+
192+
self.assertIn("Build Failed", str(process_execute.stdout))
195193

196194

197195
@skipIf(
@@ -1143,8 +1141,7 @@ def test_with_wrong_builder_specified_python_runtime(self, use_container):
11431141
# This will error out.
11441142
command = run_command(cmdlist, cwd=self.working_dir)
11451143
self.assertEqual(command.process.returncode, 1)
1146-
output = "\n".join(command.stdout.decode("utf-8").strip().splitlines())
1147-
self.assertIn("Build Failed", output)
1144+
self.assertEqual(command.stdout.strip(), b"Build Failed")
11481145

11491146
def _verify_built_artifact(self, build_dir, function_logical_id, expected_files):
11501147

tests/integration/init/test_init_command.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
"""
2-
Integration tests for init command
3-
"""
4-
import os
5-
import shutil
6-
import tempfile
7-
from pathlib import Path
8-
from subprocess import PIPE, Popen, TimeoutExpired
91
from unittest import TestCase
102

113
from parameterized import parameterized
4+
from subprocess import Popen, TimeoutExpired, PIPE
5+
import os
6+
import shutil
7+
import tempfile
128
from samcli.lib.utils.packagetype import IMAGE, ZIP
139

10+
from pathlib import Path
11+
1412
TIMEOUT = 300
1513

1614

@@ -227,7 +225,7 @@ def test_init_command_no_interactive_missing_name(self):
227225
You can also re-run without the --no-interactive flag to be prompted for required values.
228226
"""
229227

230-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
228+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
231229

232230
def test_init_command_no_interactive_apptemplate_location(self):
233231
stderr = None
@@ -265,7 +263,7 @@ def test_init_command_no_interactive_apptemplate_location(self):
265263
--location
266264
"""
267265

268-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
266+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
269267

270268
def test_init_command_no_interactive_runtime_location(self):
271269
stderr = None
@@ -303,7 +301,7 @@ def test_init_command_no_interactive_runtime_location(self):
303301
--location
304302
"""
305303

306-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
304+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
307305

308306
def test_init_command_no_interactive_base_image_location(self):
309307
stderr = None
@@ -341,7 +339,7 @@ def test_init_command_no_interactive_base_image_location(self):
341339
--location
342340
"""
343341

344-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
342+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
345343

346344
def test_init_command_no_interactive_base_image_no_dependency(self):
347345
stderr = None
@@ -381,7 +379,7 @@ def test_init_command_no_interactive_base_image_no_dependency(self):
381379
You can also re-run without the --no-interactive flag to be prompted for required values.
382380
"""
383381

384-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
382+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
385383

386384
def test_init_command_no_interactive_packagetype_location(self):
387385
stderr = None
@@ -419,7 +417,7 @@ def test_init_command_no_interactive_packagetype_location(self):
419417
--location
420418
"""
421419

422-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
420+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
423421

424422
def test_init_command_no_interactive_base_image_no_packagetype(self):
425423
stderr = None
@@ -457,7 +455,7 @@ def test_init_command_no_interactive_base_image_no_packagetype(self):
457455
You can also re-run without the --no-interactive flag to be prompted for required values.
458456
"""
459457

460-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
458+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
461459

462460
def test_init_command_wrong_packagetype(self):
463461
stderr = None
@@ -491,7 +489,7 @@ def test_init_command_wrong_packagetype(self):
491489
_get_command()
492490
)
493491

494-
self.assertIn(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
492+
self.assertEqual(errmsg.strip(), "\n".join(stderr.strip().splitlines()))
495493

496494

497495
class TestInitWithArbitraryProject(TestCase):

0 commit comments

Comments
 (0)