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

Features/#59 move resource management to importlib resources #119

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

adelmemariani
Copy link

It is intended to address the issues#59 'Move resource management to importlib.resources'

@gnn gnn self-requested a review March 3, 2021 21:44
@@ -12,16 +12,25 @@
import egon.data.processing.openstreetmap as process_osm
import egon.data.importing.zensus as import_zs

from importlib_resources import files
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a third party library import. According to "CONTRIBUTING.rst" this should be placed in a section between builtin imports and package local imports. But I see that others messed up the import order before you already.
Also, the importlib-resources package should be added to the depen dencies in "setup.py".

Copy link
Author

Choose a reason for hiding this comment

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

Done! thanks.

print('*-*-*-*-*-*')
print(os.path.abspath(os.path.join(os.path.dirname(
__file__ ), '..', '..', 'processing', 'vg250')))
print(files('egon.data.processing').joinpath('vg250'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you removed those changes in a later commit, I think you committed them by accident and know that such debug statements usually shouldn't be part of published commits. But now that I see how you used those statements, let me point out, that you could also have tried them out in an interactive console session, obviating the need to write them into a file in the first place.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks.

@@ -85,7 +88,9 @@ def serve(context):
@click.version_option(version=egon.data.__version__)
@click.pass_context
def main(context, **kwargs):
os.environ["AIRFLOW_HOME"] = os.path.dirname(egon.data.airflow.__file__)
#os.environ["AIRFLOW_HOME"] = os.path.dirname(egon.data.airflow.__file__)
os.environ["AIRFLOW_HOME"] = os.path.dirname(files(egon.data.airflow).joinpath('__init__.py'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line exceeds the 79 character limit. Also os.path.dirname just removes the '__init__.py' component, so files(egon.data.airflow) should suffice.

Copy link
Author

Choose a reason for hiding this comment

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

Using the files(egon.data.airflow) yields TypeError: str expected, not PosixPath. So, I changed it to str(files(egon.data.airflow)). I hope adding str() is ok.

os.path.dirname(__file__), osm_config["target"]["path"]
#os.path.dirname(__file__),
files(import_openstreetmap),
osm_config["target"]["path"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no reason to split up the original line. Our automatic code formatting tool will join them again anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks.

os.path.dirname(__file__), osm_config["target"]["path"]
#os.path.dirname(__file__),
files(import_openstreetmap),
osm_config["target"]["path"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will also be joined when formatting code.

@@ -16,7 +17,8 @@ def credentials():
Complete DB connection information
"""
# Read database configuration from docker-compose.yml
package_path = egon.data.__path__[0]
#package_path = egon.data.__path__[0]
package_path = files('egon.data')
Copy link
Collaborator

Choose a reason for hiding this comment

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

When the package has been imported, you can also just write files(egon.data), guarding against typos.

@@ -6,6 +6,7 @@

from importlib_resources import files


Copy link
Collaborator

Choose a reason for hiding this comment

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

This style change is correct, but should be done in a separate commit. Ideally, style changes should be separate from changes modifying behaviour.

Copy link
Collaborator

@gnn gnn left a comment

Choose a reason for hiding this comment

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

Please remove the commented code and fix the minor style infringements.

Copy link
Collaborator

@gnn gnn left a comment

Choose a reason for hiding this comment

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

Ideally these changes would be split up into two commits, with separate explanatory commit messages.

Copy link
Collaborator

@gnn gnn left a comment

Choose a reason for hiding this comment

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

Sorry, I misclicked. This should have been a request for changes, not a comment. Please remove the commented code and fix the import ordering.

#os.path.abspath(os.path.join(os.path.dirname(
# __file__ ), '..', '..', 'processing', 'vg250'))
files('egon.data.processing').joinpath('vg250')

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think files('egon.data.processing.vg250') should do the same.

khelfen pushed a commit that referenced this pull request Nov 8, 2024
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.

2 participants