Repository navigation
Add logging features - #143
Conversation
|
@tfardet that should be easier to follow ! |
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## master #143 +/- ##
=======================================
Coverage 92.29% 92.30%
=======================================
Files 117 117
Lines 3791 3795 +4
=======================================
+ Hits 3499 3503 +4
Misses 292 292
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
@tgrandje I don't think the later commits should have been added to this branch, could you revert these changes, please? EDIT: If you're not familiar with git, you can just make a new branch from |
|
Yes, @tfardet I have blundered (again) with git; I tried to import this branch into a local project... That was done through github's interface and I'm searching for the appropriate way to rollback. |
f759dc1 to
5789cb2
Compare
|
@tfardet thanks for your tip, I think this is ok now... |
There was a problem hiding this comment.
Well, this was a big PR ^^"
Thanks for the hard work @tgrandje and @lgeo3 !
There are a few things that need changing and some things that should be removed (you can just copy the old code where it belongs and push it with the new commits to "undo" the changes)
@hadrilec there are a few decisions to be made regarding what people using the library should see by default; I tagged you on the comments where I think discussion is needed so you can just search for your handle
| def warning_file(missingFile, foundFile): | ||
|
|
||
| print(f"Data file missing in the zip file:\n{missingFile}") | ||
| msg = f"Data file missing in the zip file:\n{missingFile}\n" |
There was a problem hiding this comment.
Why do we need the newline at the end?
There was a problem hiding this comment.
We do not need it ; but it may be easier to read the log if it is splitted among multiple lines (as it used to be with multiple prints).
There was a problem hiding this comment.
while developing the package, I might have thought back then that it was easier to read, feel free to remove it
|
|
||
| else: | ||
| print("No column-specific metadata has been found for this file") | ||
| logger.info("No column-specific metadata has been found for this file") |
There was a problem hiding this comment.
Sounds more like a warning to me
There was a problem hiding this comment.
I'm not sure metadata are meant to be found each time (you still get a dataframe), but yes we could definitely change it to warning.
There was a problem hiding this comment.
Indeed, it should be a warning
There was a problem hiding this comment.
In fact,_add_metadata isn't used anymore in the project and has been "commented out" (transformed into a string to be precise) since that commit. @hadrilec should we remove it altogether ?
There was a problem hiding this comment.
Unless I have not understood this commit, I think the message is still relevant. @tgrandje could you please elaborate on why you think the message should be removed? Thanks
There was a problem hiding this comment.
I confirm that this function has been commented out:
There was a problem hiding this comment.
@hadrilec I didn't comment it out, it's due to your previous PR (might be because the function is not called anymore in the project ?)
| print("Please report this issue") | ||
| msg += "No replacement file has been found\n" | ||
| msg += "Please report this issue !" | ||
| logger.error(msg) |
There was a problem hiding this comment.
Unfortunately we need to separate here:
- an error in the
ifblock - a warning in the
elseblock
One cannot just use error for both after the if-else block
There was a problem hiding this comment.
I'd say this is still an error if you tried to get a file and no file has been found (wether or not you found a replacement file which may be outdated). But in case we want to change the behaviour we could use a getattr. Something like this :
if blah:
method = "warning"
else:
method = "error"
getattr(logger, method)("Blah")
There was a problem hiding this comment.
cc @hadrilec for discussion (I have no strong opinion here)
| labels = labels.reset_index(drop=True) | ||
| else: | ||
| print("Columns labels not found in metadata") | ||
| logger.info("Columns labels not found in metadata") |
There was a problem hiding this comment.
Same comment about metadata (I'm not sure if there are case when this is "normal")
There was a problem hiding this comment.
indeed, it should be a warning
| n_query = len(qCount.index) | ||
|
|
||
| # print("n query in 1 min : %s" % n_query) | ||
| # logger.info("n query in 1 min : %s" % n_query) |
There was a problem hiding this comment.
delete or uncomment (moving it to debug)? cc @hadrilec
| # time.sleep(1) | ||
| _warning_query_limit() | ||
| # print("\nWai!ting time - %s secs" % waiting_time)' | ||
| # logger.info("\nWai!ting time - %s secs" % waiting_time)' |
| ) | ||
| else: | ||
| print(f"Token has been created") | ||
| logger.debug(f"Token has been created") |
There was a problem hiding this comment.
I'm not sure you need to "info" that : it the token generation fails, you get an exception anyway, so that seems obvious to me.
There was a problem hiding this comment.
the way I see it, someone not working on pynsee may want to check that all went well (e.g. to confirm an error in their script does not come from there), whereas debug is strictly limited to things that require an understanding of the library's internals and that would be used to debug of the library itself (and not just of a script using the library)
There was a problem hiding this comment.
it should be printed as an info message
| @@ -0,0 +1,24 @@ | |||
| [tool.poetry] | |||
|
Btw @tfardet : will git keep the nested conversations at the right place if I push further comits ? |
it should, unless the commit changes that line (in which case the conversation is hidden as "outdated" by default, if I remember correctly; note that this is github specific, btw, PRs do not exist in git) |
Revert to current master (including black formatting)
_get_geodata is not used in _add_insee_dep anymore
* black formatting * explicit exceptions
Fix proxies declaration and process each one separately (in case only one proxy is set among http / https)
Move session with "with statement" for automatic closure
Use a with statement which will revert the default configuration on closure.
Add link to log with error entry + add link to infered dataframe returned by the function.
* removed "\n" * black formating
revert to master
* revert to master * black formating * fix docstring on get_geo_list * explicit exceptions * print -> logger.info (awaiting review)
* revert to master * black formatting * fix proxies declaration (in case of only one of http/https proxy is set) * explicit exceptions * fix urllib3 warnings catchment with "with statement" for automatic reversal
* black formatting * change logger's level to info on self-update entry
Remove blank lines from log
* revert to master * black formatting
explicit exception
Reset logger's levels in get_seirene_data and search_sirene + black formatting
* revert to master * black formatting * print -> logger * fix proxies declaration (in case of any one http / https missing)
Black formatting + set logger's level to info on token creation
|
@tfardet this should handle the most problematic conflicts and the case where there was no debate (I'll let you resolve conversation in any case). I've also taken the liberty to commit small changes on the side (mostly one bug on proxies declaration, explicit exceptions and remove the call of unused submodules) ; that was done only when I had to rewrite a file to resolve the major conflicts. |
* reset session closure from master * quick and dirty fix for session recreation during multiprocess (can be caused by _get_data_with_bbox's self call) to preserve proxies, backoff strategy, etc.
Black formatting has changed a bit more of get_legal_entity but this is not relevant.
|
Alright, so I think we resolved all discussions, just summing it up here so it's easier to see:
PS: @tgrandje you'll have to do a pull from upstream and resolve the conflicts so that we can merge the PR since something else was merged into master in the meantime |
* Refatorization of PR's code according to reviews * Added an harmonisation of caching info for macrodata (specifying the downloaded file's location) * Black formatting
| @lru_cache(maxsize=None) | ||
| def _get_geo_list_simple(geo, progress_bar=False): | ||
|
|
||
| def _get_geo_list_simple(geo, date=None, progress_bar=False): |
| import pandas as pd | ||
| from tqdm import trange | ||
| import numpy as np | ||
| from requests.exceptions import RequestException |
| insee_folder = _create_insee_folder() | ||
| file_localdata = insee_folder + "/" + filename | ||
|
|
||
| RENAME = { |
| @lru_cache(maxsize=None) | ||
| def _warning_get_new_city(): | ||
| print("\ndate is None, by default it supposed to be ten years before current year") | ||
| logger.info( |
There was a problem hiding this comment.
@hadrilec I thought we had answered all question, but I'm actually not sure we dealt with this one...
|
|
||
| if len(list_obs) > 0: | ||
| obs_series = pd.concat(list_obs).reset_index(drop=True) | ||
| obs_series = pd.concat(list_obs) |
There was a problem hiding this comment.
Ok, that one's on me; can't see how I missed the changes to master in this file, but I'll correct this asap.
| dict_attr[a] = attr_series[a]._value | ||
|
|
||
| col_attr = list(dict_attr.keys()) | ||
| attr_series = pd.DataFrame(dict_attr, columns=col_attr, index=[0]).reset_index(drop=True) |
|
@tfardet ok, so I think I'm done here. As you said, big PR and so I missed your last comments (which explains the multiple commits here). Some things where not explicitly discussed, but I think that it should be good enough as it is. Btw, I've also taken the liberty to reset the ex-prints from macrodata and harmonised it with all other caching/restoring files' logging system. I've also kept your suggestion about "pynsee_query_print" in _request_insee to keep it simple, but I think your first assumption (ie that we don't need it anymore) should be better in the long run. I've still a strange feeling about the warning on credentials. I'm convinced there are as many (or less) risks when using environment variables as with plain strings in a script file (which won't trigger any warnings). Or am I missing something here ? |
almost, sorry (see review above)
Good.
Credential management is currently as bad as it gets and if someone could have a look and improve it, that would be great; in the meantime, however, better make sure that people get notified about the fact that they are not using the process that is described in the tutorial, just in case they did a set and forget in some profile file and then updated their credentials via the script (or just decided to try to use a one-time credential via the library's API). |
|
I agree that credentials management can be improved. Using the os variable |
|
To be clear, I'm perfectly happy with the credentials management de way it is :-) . I just disagree with the fact that environment variables need more caution (and thus warnings) than regular variables stored in a script (especially with init_con storing uncrypted credentials in the user's directory under the hood) . Noted about pynsee_query_print, I'll change that. |
* remove pynsee_query_print * black formatting
* revert get_insee to master * black formatting
|
@tfardet I just finished reverting _get_insee to master. But I don't see anything in the code which relates to any caching of data ? The file is deleted (Which explains why I didn't harmonised the message with other "caching" messages and let the level be debug for now.) |
|
@tfardet did you had the time to review the last changes? |
|
@tgrandje I don't think my last series of comments where addressed: |
|
@tfardet it was adressed (sorry: I thought I had commented it but apparently not explicitly enough). |
tfardet
left a comment
There was a problem hiding this comment.
@tgrandje mhh... you're right... I don't understand why it appears changed in the review interface... GitHub is really getting worse and worse since MS acquired it...
Anyways, looks good on my side, I restarted the failed job, just waiting to see whether it succeeds (or what went wrong if it doesn't)
|
Alright, it's in, thanks for the hard work! |
Co-authored-by: thomas.grandjean <[email protected]> Former-commit-id: 071a680
Starting anew, replace all prints by logging features.
Logging's levels should be cautiously reviewed.
To activate the "verbose" mode, use the following :