Skip to main content

Table of Contents

  1. Salient: A simple SQLAlchemy Linter
    1. What is it?
    2. Why?
    3. Simple and Naive
      1. The Benefits of Naivete
      2. Trade-Offs
    4. The Name
    5. Usage
    6. Current State
    7. Requirements
    8. Contributing

Salient: A simple SQLAlchemy Linter

What is it?

Salient is a rather simple, naive, even simplistic, linter for SQLAlchemy class based models.

Why?

I wrote this after discovering that a SA model in a project I work on had a table column that was defined once and then redefined with a different definition later in the model. I have also found that unnecessary nullable=True and index=False can be found all over the place. I wrote this after discovering that a SA model in a project I work on had a table column that was defined once and then redefined with a different definition later in the model. I have also found that unnecessary nullable=True and index=False can be found all over the place.

Simple and Naive

Salient takes few options and parses SA models in a naive manner. Salient does not currently use an AST or a finite state machine to parse source code. Rather it parses like you might with grep.

The Benefits of Naivete

Salient should be simple to understand and to maintain.

Trade-Offs

Salient assumes a Python module contains one SA class based model, so if you have a module with multiple classes and they have column names in common you would need to separate them or not check for redefined columns. This also means that if you have nullable=True in a module being linted outside of a column definition the linter is going to be most unhappy with you.

The Name

Salient comes from my abbreviating SQLAlchemy as SA and it being a linter, SAli[e]nt.

Usage

The idea, and hope, is that your SA models live in their own directory separate from other source code. Salient probably won't break if it sees other source, but it was really intended to mostly look at SA models.

poetry run python salient.py -rni src/app/models/*.py

1 file(s) with errors were found.

examples/all_problems.py
  Redefined Columns - unoriginal_column_name:
    16: Column(Integer)
    19: Column(Boolean)
  Unnecessary nullable=True:
    17:     col_1 = Column(nullable=True)
  Unnecessary index=False:
    18:     col_2 = Column(index=False)

You can run with the -h or --help parameter for more options.

usage: salient.py [-h] [-n] [-i] [-r] [--config CONFIG] [-R RECURSIVE] [-1 STOP_AFTER_FIRST_ERROR] files [files ...]

positional arguments:
  files                 files to lint

optional arguments:
  -h, --help            show this help message and exit
  -n, --nullable-true   Check for unnecessary nullable=True
  -i, --index-false     Check for unnecessary index=False
  -r, --redefined-column
                        Check for columns that are redefined.
  --config CONFIG       Load options from CONFIG FILE.
  -R, --recursive       If FILES includes directories scan those as well
  -1 STOP_AFTER_FIRST_ERROR, --stop-after-first-error STOP_AFTER_FIRST_ERROR
                        stop after first error

Current State

Alpha / MVP

  • Believed to do what it says on the tin, but YMMV
  • Not all command line options are implemented. (help, and the three linting rules work, that is all)
  • Doesn't recurse subdirectories
  • Doesn't currently use a config file, and no environment variables have been implemented.
  • Still has TODOs in the code. :)
  • Mostly untested, but the most complex of the linters is tested.
  • PRs welcome!

Requirements

  • Python 3.8 or above.
    • I've set the Poetry config to require Python 3.8 or above. I don't believe anything is preventing use with 3.7, but I am not opposed to throwing in a walrus here and there if it is the best way to do something.
  • Poetry, any modern version.

Contributing

  • Code is formatted with the latest version of Black.
  • MyPy isn't configured yet, but please use typehints. (Not everything is typehinted, but the project is a day old at the time of this writing!)
  • New code should be tested.

Metadata

Release files for salient 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for salient 0.1.1
File Size Uploaded Provenance
Salient-0.1.1.tar.gz 5.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for salient 0.1.1
File Interpreter ABI Platform
Salient-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / Salient-0.1.1.tar.gz

Download URL Salient-0.1.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9bb494c6b08bf6b2b2ae71c43f75dfc8d09ff7a75451f3bee23ac8656e5c0989
BLAKE2b-256 checksum
How to use checksums
2dc1cceeb59b6a3ec440cba8ec9ca3e45b5d3680c24b0132883b698fd5ab3921
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.0 CPython/3.8.6 Linux/5.8.0-7625-generic

Release files / Salient-0.1.1-py3-none-any.whl

Download URL Salient-0.1.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23adf94daa75063f8a93596df07bca71f0b08124ad1e956b6f86f53572276a88
BLAKE2b-256 checksum
How to use checksums
f4d1a2bc62c33316c7465463a29f90295277419cd1bee2a6b8caf9ccc5004c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.0 CPython/3.8.6 Linux/5.8.0-7625-generic

Security for salient 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page