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

Restructure utils.py to its own package #915

Merged
merged 26 commits into from
Apr 24, 2023
Merged

Conversation

michplunkett
Copy link
Collaborator

@michplunkett michplunkett commented Apr 12, 2023

Status

Ready for review.

Description of Changes

Changed utils.py file from a gigantic mono-file to a package with more specialized files.

Fixes: #913

Tests and linting

  • I have rebased my changes on current develop
  • pytests pass in the development environment on my local machine
  • pre-commit checks pass

@michplunkett michplunkett self-assigned this Apr 12, 2023
from .validators import state_validator, url_validator


db = SQLAlchemy()
model_encoding = "utf-8"
Copy link
Collaborator Author

@michplunkett michplunkett Apr 12, 2023

Choose a reason for hiding this comment

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

We could remove this now that the constant isn't a circular reference.

@michplunkett michplunkett marked this pull request as ready for review April 12, 2023 04:49
@michplunkett
Copy link
Collaborator Author

Gonna run the tests on my local sometime tomorrow.

@@ -89,5 +89,6 @@ help: ## Print this message and exit
| sort \
| column -s ':' -t

.PHONY: attach
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a missing PHONY.

Copy link
Collaborator

@abandoned-prototype abandoned-prototype left a comment

Choose a reason for hiding this comment

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

Firstly, Thank you very much for doing this!
One nit: Was it intentional to change utils.py to util, getting rid of the plural? It appears that generally we are leaning towards the plural in the naming here.

Finally, I did remember an issue that we ran into in the past, that prevented us from using absolute imports. I tested it locally and I believe it is still an issue, so I created #916 to change that. So in short, I #916 should be merged first and then this one should be fine :)

)


def get_or_create(session, model, defaults=None, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering if this get_or_create could be getting its own file or something? Since it's also imported from util/forms.py seemingly increasing the change of running into more circular imports in the future. But if you think it's fine, I am okay leaving it as it is

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we're good now, I think we can keep it where it's at. I'll add a note to the top of it tho signaling that it could be something we move to its own file should a circular import arise.

@michplunkett
Copy link
Collaborator Author

michplunkett commented Apr 23, 2023

That's good to know! I'll make the change from util to utils now!

Edit: Done. ✅

Comment on lines +96 to +97
# Operating system files
**/.DS_Store
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was getting this file if I opened up anything in finder on my comp.

@@ -15,7 +15,7 @@
sys.path.insert(0, os.path.dirname(current_app.root_path))

from app.models import Face, db # noqa: E402
from app.utils import crop_image # noqa: E402
from app.utils.cloud import crop_image # noqa: E402
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I felt weird changing a migration file, but it seems it was necessary.

@michplunkett michplunkett added tech debt python Pull requests that update Python code labels Apr 24, 2023
Copy link
Collaborator

@abandoned-prototype abandoned-prototype left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks again for taking on this project!

@abandoned-prototype abandoned-prototype merged commit d2d59b4 into develop Apr 24, 2023
@abandoned-prototype abandoned-prototype deleted the util_restructure branch April 24, 2023 06:33
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 6, 2023
* Move utils to its own package

* Move constants to own file

* Update Makefile

* Update forms.py

* Update test_utils.py

* Use absolute imports

* Update 59e9993c169c_change_faces_to_thumbnails.py

* Update .gitignore
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 25, 2023
* Move utils to its own package

* Move constants to own file

* Update Makefile

* Update forms.py

* Update test_utils.py

* Use absolute imports

* Update 59e9993c169c_change_faces_to_thumbnails.py

* Update .gitignore
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 5, 2023
* Move utils to its own package

* Move constants to own file

* Update Makefile

* Update forms.py

* Update test_utils.py

* Use absolute imports

* Update 59e9993c169c_change_faces_to_thumbnails.py

* Update .gitignore
AetherUnbound pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 9, 2023
* Move utils to its own package

* Move constants to own file

* Update Makefile

* Update forms.py

* Update test_utils.py

* Use absolute imports

* Update 59e9993c169c_change_faces_to_thumbnails.py

* Update .gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code tech debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restructure utils.py file to its own package
2 participants