![]() """Returns the name of the latest (most recent) file Get_latest_file('example', 'files','randomtext011.*.txt')Īnd then you might think that the way to call it is not trivial and want to document it: let's use a docstring ! def get_latest_file(path, *paths): You can take inspiration of the os.path.join even further and change the order of your arguments (and completely remove the branching): def get_latest_file(path, *paths): Instead, fullpath = os.path.join(path, file_pattern) is what you are looking for. I would recommend None Don't repeat yourselfĪs you can see, the two branches of your if else are very similar.īut joining paths like this is not very pythonic (and might cause problems on windows). Return os.path.split(max(list_of_files,key=os.path.getctime))įirst of all, I think that your variable names are quite good. List_of_files = glob.glob(''.format(path, file_pattern)) ![]() Inside my example/files directory are 3 files which were, for this example, created on the dates specified in the file name:Įxample/files/Įxample/files/Įxample/files/ import os.pathĭef get_latest_file(file_pattern,path=None): Taking a step back, it reads a bit janky and I was curious what steps or what resources I could look into to help me make this more friendly. I wrote a small function to help me find the latest file in a directory. py files it finds in that directory.I'm a bit new to Python and sort of learning on my own. If you wanted to provide more details about the directory checking up front, maybe something like this:įor each provided directory, mypy will type check every package it finds in that directory and its immediate subdirectories, and it will type check all. For more details about how exactly this is done, see Mapping file paths to modules. In addition, mypy will type check the contents of any provided directories. The above command tells mypy it should type check all of the provided files together. ![]() In addition, mypy will recursively type check the entire contents of any provided directories.įor more details about how exactly this is done, see Mapping file paths to modules. Links to further documentation are already provided right after the sample command, so no need to add those.Īnd the online docs could be changed from: Pass in any files or folders you want to type check: Mypy will recursively traverse any provided folders to find. Pass in any files or folders you want to type check. I suggest removing the references to "recursive", keeping things concise by leaving the directory rules a bit vague, and pointing to where the procedure is described in greater detail.įor example, the help text could be changed from: But like suggested, I think the solution to this particular issue is to update the help text and docs so that they aren't misleading. I understand that I can address the issue by invoking mypy differently. Stopping after one subdirectory level is hardly what I'd call recursive. But neither of the immediate subdirectories src or test contain an _init_.py, so they aren't checked. setup.py is contained directly therein, so that one is checked. ![]() , the current directory doesn't contain an _init_.py, so the above logic applies. immediate subdirectories with an _init_.py file) are checked as toplevel Python packages. All packages contained directly therein (i.e.All *.py files contained directly therein are checked as toplevel Python modules.not directly containing an _init_.py file) are checked as follows: A link to further details is helpfully provided right after this, where we learn how it actually works:ĭirectories that don’t represent Python packages (i.e. I think the words "recursively" and "entire" are strong signals that it will descend down into every directory looking for every. In addition, mypy will recursively type check the entire contents of any provided directories. The description from the online docs is similar, although it doesn't specifically say it finds. And that's fine, I have no problem invoking it that way, but the behavior doesn't match what I'd expect given the documentation. To check everything, I need to invoke it as mypy setup.py src/ tests/. However, setup.py is the only one it checks. ![]() py filesīased on this statement, I expect that invoking mypy via mypy. So this is a src layout, not a namespace package. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |