Skip to content

Commit 900a565

Browse files
committed
Convert the trustymail script into a sub-module
Bring the command line functionality directly into the package and use an entry point instead of a script.
1 parent 771e2e7 commit 900a565

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def get_version(version_file):
113113
"pytest",
114114
]
115115
},
116-
scripts=["scripts/trustymail"],
117-
# Conveniently allows one to run the CLI tool as `example`
118-
# entry_points={"console_scripts": ["example = example.example:main"]},
116+
# Conveniently allows one to run the CLI tool as `trustymail`
117+
entry_points={"console_scripts": ["trustymail = trustymail.cli:main"]},
119118
)

src/trustymail/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Code to run if this package is used as a Python module."""
2+
3+
from .cli import main
4+
5+
main()
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
41
"""trustymail: A tool for scanning DNS mail records for evaluating security.
52
Usage:
63
trustymail (INPUT ...) [options]
@@ -58,14 +55,15 @@
5855
import docopt
5956

6057
# Local imports
61-
import trustymail
58+
from . import trustymail
59+
from ._version import __version__
6260

6361
# The default ports to be checked to see if an SMTP server is listening.
6462
_DEFAULT_SMTP_PORTS = {25, 465, 587}
6563

6664

6765
def main():
68-
args = docopt.docopt(__doc__, version=trustymail.__version__)
66+
args = docopt.docopt(__doc__, version=__version__)
6967

7068
# Monkey patching trustymail to make it cache the PSL where we want
7169
if args["--psl-filename"] is not None:
@@ -181,7 +179,3 @@ def mkdir_p(path):
181179
pass
182180
else:
183181
raise
184-
185-
186-
if __name__ == "__main__":
187-
main()

src/trustymail/domain.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import publicsuffix
66

7-
from trustymail import PublicSuffixListReadOnly
8-
from trustymail import PublicSuffixListFilename
9-
from trustymail import trustymail
7+
from . import PublicSuffixListReadOnly, PublicSuffixListFilename
8+
from . import trustymail
109

1110

1211
def get_psl():

src/trustymail/trustymail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import dns.reversename
1616

1717

18-
from trustymail.domain import get_public_suffix, Domain
18+
from .domain import get_public_suffix, Domain
1919

2020
# A cache for SMTP scanning results
2121
_SMTP_CACHE = {}

0 commit comments

Comments
 (0)