sloria / tinynetrc Goto Github PK
View Code? Open in Web Editor NEWRead and write .netrc files in Python
License: MIT License
Read and write .netrc files in Python
License: MIT License
Using a context manager to manage opening and saving of the netrc might be a more idiomatic API.
with Netrc() as netrc:
netrc['surge.surge.sh'] = {
'login': '[email protected]',
'password': 'secret'
}
Currently if I use Travis for testing then using this library makes tests fail as it does not gracfully fail if it does not find the .netrc file.
==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_siteship.py ____________________
.tox/py36/lib/python3.6/site-packages/tinynetrc.py:38: in __init__
file = os.path.join(os.environ['HOME'], ".netrc")
.tox/py36/lib/python3.6/os.py:669: in __getitem__
raise KeyError(key) from None
E KeyError: 'HOME'
During handling of the above exception, another exception occurred:
tests/test_siteship.py:11: in <module>
from siteship import cli
siteship/cli.py:14: in <module>
netrc = Netrc()
.tox/py36/lib/python3.6/site-packages/tinynetrc.py:40: in __init__
raise OSError("Could not find .netrc: $HOME is not set")
E OSError: Could not find .netrc: $HOME is not set
When .netrc file is not present in the user's home directory, trying to save a new entry triggers FileNotFoundError
.
Can this library automatically create one when .netrc
is not found?
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
Calling Netrc#save
will overwrite ~/.netrc and remove comments. It would be great if comments were preserved.
python3.8/site-packages/tinynetrc-1.3.0-py3.8.egg/tinynetrc.py:5:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
from collections import MutableMapping, defaultdict
One feature of https://pypi.org/project/safe-netrc/ which appears to be missing is the ability to override the default location with NETRC
fwiw, https://github.com/evertrol/newrc appears to be the only other netrc alternative available atm.
There doesn't seem to be any way to create a new .netrc
file when none already exists. What's the recommendation?
One user-side workaround is to create an empty .netrc
if one doesn't already exist, but that's pretty ugly - we also have to replicate the internal default-file stuff you do in your __init__
method:
# When .netrc exists:
with tinynetrc.Netrc() as netrc:
netrc[host] = {'login': username, 'password': password}
# When .netrc might not exist:
import os
fname = os.path.join(os.path.expanduser('~'), '.netrc')
with open(fname, 'a'):
pass
with tinynetrc.Netrc(fname) as netrc:
netrc[host] = {'login': username, 'password': password}
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.