Skip to content

Commit

Permalink
Add netrc tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ejohb committed Aug 2, 2024
1 parent c375487 commit 556b1e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
11 changes: 10 additions & 1 deletion fmtr/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import fmtr.tools.platform_tools as platform
import fmtr.tools.random_tools as random
import fmtr.tools.string_tools as string
import fmtr.tools.spaces_tools as spaces

from fmtr.tools.import_tools import MissingExtraMockModule
from fmtr.tools.path_tools import Path
Expand Down Expand Up @@ -70,6 +69,16 @@
except ImportError as exception:
unicode = MissingExtraMockModule('unicode', exception)

try:
from fmtr.tools import netrc_tools as netrc
except ImportError as exception:
netrc = MissingExtraMockModule('netrc', exception)

try:
from fmtr.tools import spaces_tools as spaces
except ImportError as exception:
spaces = MissingExtraMockModule('spaces', exception)


__all__ = [
'config',
Expand Down
11 changes: 11 additions & 0 deletions fmtr/tools/netrc_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from functools import lru_cache

from tinynetrc import Netrc

LOGIN = 'login'
PASSWORD = 'password'


@lru_cache
def get():
return Netrc()
19 changes: 8 additions & 11 deletions fmtr/tools/spaces_tools.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import sys
from os import getenv, path
from os import getenv

import importlib
import logging
import subprocess
from pathlib import Path

from fmtr.tools import netrc_tools


def run():
FMTR_LOG_LEVEL = getenv('FMTR_LOG_LEVEL', 'INFO')
logging.getLogger().setLevel(FMTR_LOG_LEVEL)

dir_home = Path(path.expanduser("~")).absolute()

MODULE_NAME = getenv('PACKAGE_NAME')
if not MODULE_NAME:
raise KeyError('No MODULE_NAME set.')
Expand All @@ -29,13 +28,11 @@ def run():
if not PIP_PASSWORD:
raise KeyError('No PIP_PASSWORD set.')

lines_nrc = [
f'machine {PIP_INDEX_URL}',
f'login {PIP_USERNAME}',
f'password {PIP_PASSWORD}'
]

(dir_home / '.netrc').write_text('\n'.join(lines_nrc))
with netrc_tools.get() as netrc_obj:
netrc_obj[PIP_INDEX_URL] = {
netrc_tools.LOGIN: PIP_USERNAME,
netrc_tools.PASSWORD: PIP_PASSWORD
}

print(f'Starting {MODULE_NAME}...')

Expand Down
4 changes: 3 additions & 1 deletion requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'profiling': ['contexttimer'],
'docker.api': ['docker'],
'unicode': ['Unidecode'],
'version': ['semver']
'version': ['semver'],
'spaces': ['netrc'],
'netrc': ['tinynetrc']
}


Expand Down

0 comments on commit 556b1e6

Please sign in to comment.