Skip to content

Use logging instead of print for informational statements #451

@drcrallen

Description

@drcrallen

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

outfile = sys.stdout
defaults to using stdout but the print statements above corrupt the stdout file by printing a bunch of logging statements

if args.version:
print(version("sqlacodegen"))
return
if not args.url:
print("You must supply a url\n", file=sys.stderr)
parser.print_help()
return
if citext:
print(f"Using sqlalchemy-citext {version('sqlalchemy-citext')}")
if geoalchemy2:
print(f"Using geoalchemy2 {version('geoalchemy2')}")
if pgvector:
print(f"Using pgvector {version('pgvector')}")
# Use reflection to fill in the metadata
engine_args = _parse_engine_args(args.engine_arg)
engine = create_engine(args.url, **engine_args)
metadata = MetaData()
tables = args.tables.split(",") if args.tables else None
schemas = args.schemas.split(",") if args.schemas else [None]
options = set(args.options.split(",")) if args.options else set()
# Instantiate the generator
generator_class = generators[args.generator].load()
generator = generator_class(metadata, engine, options)
if not generator.views_supported:
name = generator_class.__name__
print(
f"VIEW models will not be generated when using the '{name}' generator",
file=sys.stderr,
)

Instead, there should be a way to configure Logging to redirect the print statements to somewhere else (or suppress them altogether!)

Use case

  1. sqlacodegen command which redirects stdout to a generated file (ex: from a docker exec command)
  2. Do anything which causes one of the print statements to fire, like use pgvector.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions