Context
- Created: September 2020
- Author: Renier Kramer, renier.kramer@hdsr.nl
- Python version: >3.5
Description
A python project that serves as an interface for finding directories and files by combining best of both worlds: glob/rglob (speed) and regex (flexibility).
Usage path_finder.FileFinder
# pip install path-finder
# pip install pathlib
from pathlib import Path
from path_finder import FileFinder
start_dir1 = Path('start_search_from_this_dir')
start_dir2 = Path('and_start_search_from_this_dir')
limit_depth = True
depth = 2 # 2, so search in start_dir1, subdir and subsubdirs (same for start_dir2)
filename_regex = '^[0-9]{8}_blabla'
extension = '.csv' # choose from ('.jpg', '.png', '.txt', '.xml', '.csv', '.xlsx', '.pdf', '.h5', '.nc', '.zip')
file_finder = FileFinder(
multi_start_dir=[start_dir1, start_dir2],
extension=extension,
limit_depth=True,
depth=depth,
filename_regex=filename_regex
)
paths = file_finder.paths # returns a List[Path]
paths_empty_files = file_finder.paths_empty_file # returns a List[Path]
Usage path_finder.DirFinder
# pip install path-finder (or conda install --channel hdsr-mid path-finder)
# pip install pathlib
from pathlib import Path
from path_finder import DirFinder
dir_finder = DirFinder(
single_start_dir=Path('start_search_from_this_dir')
exclude_empty_dirs=True,
limit_depth=True,
depth=0, # so only search in single_start_dir
)
paths = dir_finder.paths # returns a List[Path]
paths_empty_files = dir_finder.paths_empty_file # returns a List[Path]
License
Releases
Contributions
All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome. Issues are posted on: https://github.com/hdsr-mid/path_finder/issues
Test coverage (release v1.6)
---------- coverage: platform win32, python 3.7.11-final-0 ---
Name Stmts Miss Cover
------------------------------------------------
path_finder\__init__.py 2 0 100%
path_finder\base.py 45 8 82%
path_finder\dir_finder.py 65 11 83%
path_finder\file_finder.py 58 0 100%
setup.py 10 10 0%
------------------------------------------------
TOTAL 180 29 84%
Conda general tips
Build conda environment (on Windows) from any directory using environment.yml:
Note1: prefix is not set in the enviroment.yml as then conda does not handle it very well Note2: env_directory can be anywhere, it does not have to be in your code project
> conda env create --prefix <env_directory><env_name> --file <path_to_project>/environment.yml
# example: conda env create --prefix C:/Users/xxx/.conda/envs/project_xx --file C:/Users/code_projects/xx/environment.yml
> conda info --envs # verify that <env_name> (project_xx) is in this list
Start the application from any directory:
> conda activate <env_name>
At any location:
> (<env_name>) python <path_to_project>/main.py
Test the application:
> conda activate <env_name>
> cd <path_to_project>
> pytest # make sure pytest is installed (conda install pytest)
List all conda environments on your machine:
At any location:
> conda info --envs
Delete a conda environment:
Get directory where environment is located
> conda info --envs
Remove the enviroment
> conda env remove --name <env_name>
Finally, remove the left-over directory by hand
Write dependencies to environment.yml:
The goal is to keep the .yml as short as possible (not include sub-dependencies), yet make the environment reproducible. Why? If you do 'conda install matplotlib' you also install sub-dependencies like pyqt, qt icu, and sip. You should not include these sub-dependencies in your .yml as:
- including sub-dependencies result in an unnecessary strict environment (difficult to solve when conflicting)
- sub-dependencies will be installed when dependencies are being installed
> conda activate <conda_env_name>
Recommended:
> conda env export --from-history --no-builds | findstr -v "prefix" > --file <path_to_project>/environment_new.yml
Alternative:
> conda env export --no-builds | findstr -v "prefix" > --file <path_to_project>/environment_new.yml
--from-history:
Only include packages that you have explicitly asked for, as opposed to including every package in the
environment. This flag works regardless how you created the environment (through CMD or Anaconda Navigator).
--no-builds:
By default, the YAML includes platform-specific build constraints. If you transfer across platforms (e.g.
win32 to 64) omit the build info with '--no-builds'.
Pip and Conda:
If a package is not available on all conda channels, but available as pip package, one can install pip as a dependency. Note that mixing packages from conda and pip is always a potential problem: conda calls pip, but pip does not know how to satisfy missing dependencies with packages from Anaconda repositories.
> conda activate <env_name>
> conda install pip
> pip install <pip_package>
The environment.yml might look like:
channels:
- defaults
dependencies:
- <a conda package>=<version>
- pip
- pip:
- <a pip package>==<version>
You can also write a requirements.txt file:
> pip list --format=freeze > <path_to_project>/requirements.txt
Metadata
Release files for path-finder 1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| path_finder-1.7.tar.gz | 8.4 kB | Without provenance | Details for path_finder-1.7.tar.gz |
Release files / path_finder-1.7.tar.gz
| Download URL | path_finder-1.7.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02fffccf594372e2ad8f61edbab5de35bc2faf2dc240f08675ef36a0894c0766
|
|
BLAKE2b-256 checksum How to use checksums |
c6d82de7fd37ec23ad9f862faae90ddadbec22083d8da974e1872ad129f63027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11
|
Security for path-finder 1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.