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

Add Code Linting and Implementation of Hypermodern Python #185

Conversation

MRichards99
Copy link
Collaborator

This PR will close #165.

The related issue was originally meant for adding the capability for a code linter, but this branch has become an implementation of the Hypermodern Python guide (https://cjolowicz.github.io/posts/hypermodern-python-01-setup/). This means I've added code linting, Nox as a way of launching things easily (including unit tests when I finally get round to them), Poetry as an improved way of tracking the API's Python dependencies and making use of commit hooks using Pre Commit.

The README has a long section (https://github.com/ral-facilities/datagateway-api/tree/feature/add-code-linting-%23165#creating-dev-environment-and-api-setup) about how this all works, so instead of repeating myself here, going to look over there should explain how these changes work. That section should explain how to create a dev environment ready to start contributing code to this repo with some brief instructions on common usages for the tools.

There are a couple of things to keep in mind; the code has not been linted yet, this branch is just about adding the infrastructure. There's a big long list outputted by flake8 so I think it's better to make the changes in a separate branch. For this reason, the pre commit hooks don't lint any code - I will add this once I've finished doing the linting (otherwise the hooks wouldn't let me commit anything!).

This PR also makes a change suggested by @ajkyffin, which adds a directory which stores common and src to make the code installable as a single Python package. As suggested, I've kept test and util outside of this directory because that's not code to be used in production.

- As per Hypermodern Python guide
- As suggested by Alan, a top level directory is required to make this repo ready for production use. This is also required for Poetry
…dencies

- This will help keep consistent versions of flake8 etc being installed between developers, to prevent incosistent linting/safety outputs
- Done by `pre-commit run --all-files`
- These files have been replaced by the use of Poetry to store the API's dependencies
@MRichards99 MRichards99 linked an issue Nov 2, 2020 that may be closed by this pull request
- This is so flake8 can correctly detect which import statements are bringing in local code, so said statements can be ordered in a consistent style
- This is the suggested line length defined by Black, which flake8 is configured to also follow
- S311 (from Bandit) states "Standard pseudo-random generators are not suitable for security/cryptographic purposes.". The generator script doesn't generate data that would be vulnerable to security (no keys or anything of that nature is created using the random library) hence this status code is ignored
- In production, this will be used to store the API's logs in /var/log/
- Also remove an unused variable that I noticed
@agbeltran agbeltran requested a review from VKTB November 26, 2020 11:25
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
MRichards99 and others added 4 commits December 4, 2020 13:35
Co-authored-by: Viktor Bozhinov <45173816+VKTB@users.noreply.github.com>
- Also added a command to generate this tree in the future (I just used to update it manually).
…ties/datagateway-api into feature/add-code-linting-#165
@MRichards99 MRichards99 requested a review from VKTB December 8, 2020 10:58
- Most likely caused when I merged other branches after I created the PR
- The commit also includes a rebuilt openapi.yaml
@MRichards99 MRichards99 mentioned this pull request Dec 9, 2020
2 tasks
MRichards99 and others added 4 commits December 18, 2020 15:42
- This fixes a PermissionError that was found when using these Nox sessions on Windows
- This is a replacement solution for the tmp_dir option/fix, so that's now been removed
…#184

Apply Fixes suggested by Linting Tools
@MRichards99 MRichards99 merged commit ca0efc6 into feature/remove-sql-dependency-from-backends-#154 Jan 4, 2021
@MRichards99 MRichards99 deleted the feature/add-code-linting-#165 branch January 4, 2021 15:53
@MRichards99 MRichards99 restored the feature/add-code-linting-#165 branch January 4, 2021 15:54
@MRichards99 MRichards99 deleted the feature/add-code-linting-#165 branch January 4, 2021 15:54
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.

Impose Code Linter & Run it on the repo
3 participants