democritus-project / d8s-file-system Goto Github PK
View Code? Open in Web Editor NEWDemocritus functions for working with files and directories.
License: GNU Lesser General Public License v3.0
Democritus functions for working with files and directories.
License: GNU Lesser General Public License v3.0
Currently, if the directory_files_read function is unable to read one file in a directory, it raises an exception and does so in a way that is difficult to handle.
For example, let's say there are four files in a directory and the directory_files_read
reads the first two correctly but fails with a UnicodeDecodeError
on the third:
for path, contents in directory_files_read(directory_path, recursive=False):
...
There is no good way I'm aware of to handle this failure in a way that would let you skip the error and move on.
I believe the best solution is to add error handling into this function.
Record this in the docs so this function shows up when someone searches for "rename".
I believe the file_owner_name
function only works on unix machines. Validate this is the case and, if so, update it or write a corresponding function to work on Windows.
Python version (e.g. 3.9.1): 3.10.9
Version of this project being used (e.g. 1.2021.01.13): Last version via pip.
Other info (if applicable): N/A
I tried installing democritus_file_system
because it's in the requirements_dev.txt
of the html-to-json project, but I'm getting an error that breaks the installation:
$ pip --version
pip 23.0
$ pip install -r requirements_dev.txt
Collecting black
Using cached black-23.1.0-py3-none-any.whl (174 kB)
Collecting bump2version
Using cached bump2version-1.0.1-py2.py3-none-any.whl (22 kB)
Collecting codecov
Using cached codecov-2.1.12-py2.py3-none-any.whl (16 kB)
Collecting democritus_file_system
Using cached democritus_file_system-2021.1.2701.tar.gz (12 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/fb/3d/191c46b705d7b9fbce09f09ae10e7f8aa1f635bb5dbc75ae5702c207fa8c/democritus_file_system-2021.1.2701.tar.gz (from https://pypi.org/simple/democritus-file-system/): Requested democritus_file_system from https://files.pythonhosted.org/packages/fb/3d/191c46b705d7b9fbce09f09ae10e7f8aa1f635bb5dbc75ae5702c207fa8c/democritus_file_system-2021.1.2701.tar.gz (from -r requirements_dev.txt (line 4)) has inconsistent version: expected '2021.1.2701', but metadata has '2021.1.27'
Using cached democritus_file_system-2021.1.2101.tar.gz (12 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/9e/b4/8e1126961c5bf794e5477541c45b08608a160b8211cb31108918df8050ff/democritus_file_system-2021.1.2101.tar.gz (from https://pypi.org/simple/democritus-file-system/): Requested democritus_file_system from https://files.pythonhosted.org/packages/9e/b4/8e1126961c5bf794e5477541c45b08608a160b8211cb31108918df8050ff/democritus_file_system-2021.1.2101.tar.gz (from -r requirements_dev.txt (line 4)) has inconsistent version: expected '2021.1.2101', but metadata has '2021.1.21'
ERROR: Could not find a version that satisfies the requirement democritus_file_system (from versions: 2021.1.2101, 2021.1.2701)
ERROR: No matching distribution found for democritus_file_system
I expected the installation of democritus_file_system
not to fail.
I've isolated the error messages from the installation of this package, by trying to install it separately:
$ pip install democritus_file_system
Collecting democritus_file_system
Using cached democritus_file_system-2021.1.2701.tar.gz (12 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/fb/3d/191c46b705d7b9fbce09f09ae10e7f8aa1f635bb5dbc75ae5702c207fa8c/democritus_file_system-2021.1.2701.tar.gz (from https://pypi.org/simple/democritus-file-system/): Requested democritus_file_system from https://files.pythonhosted.org/packages/fb/3d/191c46b705d7b9fbce09f09ae10e7f8aa1f635bb5dbc75ae5702c207fa8c/democritus_file_system-2021.1.2701.tar.gz has inconsistent version: expected '2021.1.2701', but metadata has '2021.1.27'
Using cached democritus_file_system-2021.1.2101.tar.gz (12 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Discarding https://files.pythonhosted.org/packages/9e/b4/8e1126961c5bf794e5477541c45b08608a160b8211cb31108918df8050ff/democritus_file_system-2021.1.2101.tar.gz (from https://pypi.org/simple/democritus-file-system/): Requested democritus_file_system from https://files.pythonhosted.org/packages/9e/b4/8e1126961c5bf794e5477541c45b08608a160b8211cb31108918df8050ff/democritus_file_system-2021.1.2101.tar.gz has inconsistent version: expected '2021.1.2101', but metadata has '2021.1.21'
ERROR: Could not find a version that satisfies the requirement democritus_file_system (from versions: 2021.1.2101, 2021.1.2701)
ERROR: No matching distribution found for democritus_file_system
N/A.
I don't have much clues as to why this fails. Any help is appreciated, thanks !
(See issue title)
This is a common use-case that would be helpful to have.
I recommend writing a function with the following signature:
def directory_replace_text_in_files(directory_path: str, old: str, new: str, *, recursive: bool = False) -> Iterator[str]:
...
For the directory path, it would be nice to accept a Pathlib.Path or str. The function should yield file_paths that were updated.
For example, rather than having directory_subdirectory_names
and directory_subdirectory_paths
, simply have directory_subdirectories(dir_path: str, return_paths: bool = False)
where the return_paths
flag determines whether the returned items are paths or file names.
This would involve consolidating and simplifying the code and interfaces in this library.
This ticket also involves changing the function calls in all of the democritus libraries that use these functions.
Created from a todo:
# TODO: I think there is a better way to return this data. Rather than ['foo', 'subfoo'], I'd like to see something like:
# {
# 'foo': {
# 'subfoo': {}
# }
# }
HELP WANTED ๐ : If you'd like to take this challenge on, please let me know! Even if you're new to Python and/or github, this is a great place to start and I'd be happy to help walk you through this challenge as much as you need - don't hesitate to ask.
This particular issue will give you some exposure to writing a relatively simple function, working with strings in Python, and writing some tests.
We already have a file_extension
function to find a file extension. Now, we'd like to have a function which, given a file name (e.g. foo.py
), returns the file name without the extension (e.g. foo
). I propose the function should be named file_name_strip_extension
, but am open to other suggestions.
If you're interested in taking this challenge on, comment on this issue and I'll assign it to you.
This enables https://github.com/democritus-project/meta/issues/3.
e.g.:
file_name_extension('foo.py') => 'py'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.