Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

134 fix psl args #135

Closed

Conversation

Matthew-Grayson
Copy link
Contributor

🗣 Description

--psl-filename=FILENAME and --psl-read-only now work as advertised.

Remove monkey patches in domain.py. Remove PublicSuffixListFilename / PublicSuffixListReadOnly initialization in __main__.py; set default values in docopt usage pattern to compensate. Pass filename and readonly as a json file between cli.py and domain.py.

Additionally, removed several constants/variables from cli.py that are no longer needed after updating usage pattern. Trustymail now prints the docopt args dictionary. This is useful for confirming the default values are being used (feel free to remove this after testing).

💭 Motivation and context

This closes issue #134

🧪 Testing

  1. Create fresh python environment
  2. Run pip install git+https://github.com/Matthew-Grayson/trustymail@134-fix-psl-args
  3. Run trustymail cisa.gov
  4. Confirm that default values are correct in statement printed to cli
  5. Run trustymail --psl-filename=testfilename.dat cisa.gov
  6. Confirm creation of testfilename.dat
  7. If needed, cd to directory of testfilename.dat
  8. Change mtime of psl by running python3 -c "from os import utime; os.utime('testfilename.dat', (1330712280, 1330712292))"
  9. Confirm that last modified time of testfilename.dat is changed
  10. Run trustymail --psl-filename=testfilename.dat --psl-read-only cisa.gov
  11. Confirm testfilname.dat is not overwritten
  12. Run trustymail --psl-filename=testfilename.dat cisa.gov
  13. Confirm that testfilename.dat is overwritten

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All future TODOs are captured in issues, which are referenced
    in code comments.
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All relevant repo and/or project documentation has been updated
    to reflect the changes in this PR.
  • Tests have been added and/or modified to cover the changes in this PR.
  • All new and existing tests pass.

✅ Pre-merge checklist

  • Revert dependencies to default branches.
  • Finalize version.

✅ Post-merge checklist

  • Create a release.

Comment on lines +71 to +73
# Write the arguments to a file for use by the trustymail library
with open('env.json', 'w') as env:
json.dump(args, env)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worse than a monkey patch and a complete non-starter to me as it breaks the API of this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted; I'll make an adjustment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcdonnnj Thanks for the feedback. What are your thoughts on adding arguments (readonly, filename) to domain.get_psl and moving the call to get_psl to cli.py?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to look at the least destructive way to fix this as I believe the monkey patch may only be an issue for the CLI. This package is used in other projects so I lean very conservatively against breaking changes that are not strictly necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants