Skip to content

Commit

Permalink
replaced instances of .papers/config.json with CONFIG_FILE_LOCAL
Browse files Browse the repository at this point in the history
  • Loading branch information
perrette committed Apr 28, 2023
1 parent c036daf commit c5599e4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
8 changes: 4 additions & 4 deletions papers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from papers.extract import extract_pdf_doi, isvaliddoi, extract_pdf_metadata
from papers.extract import fetch_bibtex_by_doi
from papers.encoding import parse_file, format_file, family_names, format_entries
from papers.config import bcolors, Config, search_config, CONFIG_FILE, DATA_DIR, CONFIG_FILE_LEGACY
from papers.config import bcolors, Config, search_config, CONFIG_FILE, CONFIG_FILE_LOCAL, DATA_DIR, CONFIG_FILE_LEGACY
from papers.duplicate import list_duplicates, list_uniques, edit_entries
from papers.bib import Biblio, FUZZY_RATIO, DEFAULT_SIMILARITY, entry_filecheck, backupfile, isvalidkey
from papers import __version__
Expand Down Expand Up @@ -203,7 +203,7 @@ def installcmd(parser, o, config):
default_filesdir = config.filesdir or "files"

if o.local:
papersconfig = config.file or ".papers/config.json"
papersconfig = config.file or CONFIG_FILE_LOCAL
workdir = Path('.')
bibtex_files = [str(f) for f in sorted(workdir.glob("*.bib"))]
config.gitdir = config.data = os.path.dirname(papersconfig)
Expand Down Expand Up @@ -376,7 +376,7 @@ def uninstallcmd(parser, o, config):
return

if o.recursive:
config.file = search_config([os.path.join(".papers", "config.json")], start_dir=".", default=CONFIG_FILE)
config.file = search_config([CONFIG_FILE_LOCAL], start_dir=".", default=CONFIG_FILE)
config.file = check_legacy_config(config.file)
uninstallcmd(parser, o, config)

Expand Down Expand Up @@ -1022,7 +1022,7 @@ def get_parser(config=None):
def main(args=None):
papers.config.DRYRUN = False # reset in case main() if called directly

configfile = search_config([os.path.join(".papers", "config.json")], start_dir=".", default=CONFIG_FILE)
configfile = search_config([CONFIG_FILE_LOCAL], start_dir=".", default=CONFIG_FILE)
configfile = check_legacy_config(configfile)
if not os.path.exists(configfile):
config = Config()
Expand Down
1 change: 1 addition & 0 deletions papers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

CONFIG_FILE_LEGACY = os.path.join(CONFIG_HOME, 'papersconfig.json')
CONFIG_FILE = os.path.join(DATA_HOME, 'config.json')
CONFIG_FILE_LOCAL = '.papers/config.json'
DATA_DIR = os.path.join(DATA_HOME, 'papers')
CACHE_DIR = os.path.join(CACHE_HOME, 'papers')

Expand Down
8 changes: 4 additions & 4 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import papers
from papers.utils import set_directory
from papers.__main__ import main
from papers.config import CONFIG_FILE, Config
from papers.config import CONFIG_FILE, CONFIG_FILE_LOCAL, Config
from papers.bib import Biblio
# Using python -m papers instead of papers otherwise pytest --cov does not detect the call
PAPERSCMD = f'PYTHONPATH={Path(papers.__file__).parent.parent} python3 -m papers'
Expand Down Expand Up @@ -215,7 +215,7 @@ class LocalInstallTest(BaseTest):
def setUp(self):
super().setUp()
self.papers(f'install --force --local --bibtex {self.mybib} --files {self.filesdir}')
self.config = Config.load(self._path(".papers/config.json"))
self.config = Config.load(self._path(CONFIG_FILE_LOCAL))

class GlobalInstallTest(BaseTest):
def setUp(self):
Expand All @@ -228,11 +228,11 @@ class LocalGitInstallTest(LocalInstallTest):
def setUp(self):
super().setUp()
self.papers(f'install --force --local --git --bibtex {self.mybib} --files {self.filesdir}')
self.config = Config.load(self._path(".papers/config.json"))
self.config = Config.load(self._path(CONFIG_FILE_LOCAL))


class LocalGitLFSInstallTest(LocalInstallTest):
def setUp(self):
super().setUp()
self.papers(f'install --force --local --git --git-lfs --bibtex {self.mybib} --files {self.filesdir}')
self.config = Config.load(self._path(".papers/config.json"))
self.config = Config.load(self._path(CONFIG_FILE_LOCAL))
86 changes: 43 additions & 43 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest
import subprocess as sp
from papers.config import Config
from papers.config import CONFIG_FILE
from papers.config import CONFIG_FILE, CONFIG_FILE_LOCAL
from papers.bib import Biblio
# from pathlib import Path

Expand All @@ -26,9 +26,9 @@ def test_install(self):
self.assertFalse(self._exists(self.filesdir))
self.papers(f'install --force --local --bibtex {self.mybib} --files {self.filesdir}')
# Config file was created:
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
# Values of config file match input:
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
self.assertFalse(config.git)
Expand All @@ -40,13 +40,13 @@ def test_install(self):
def test_install_defaults_no_preexisting_bibtex(self):
self.assertFalse(self._exists(self.mybib))
self.assertFalse(self._exists(self.filesdir))
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))
# pre-existing bibtex?
os.remove(self._path(self.anotherbib))
self.assertFalse(self._exists(self.anotherbib))
self.papers(f'install --force --local')
self.assertTrue(self._exists(".papers/config.json"))
config = Config.load(self._path(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
# self.assertEqual(config.bibtex, os.path.abspath(self._path("papers.bib")))
self.assertEqual(config.bibtex, os.path.abspath(self._path("papers.bib")))
self.assertEqual(config.filesdir, os.path.abspath(self._path("files")))
Expand All @@ -56,64 +56,64 @@ def test_install_defaults_no_preexisting_bibtex(self):
def test_install_defaults_preexisting_bibtex(self):
self.assertFalse(self._exists(self.mybib))
self.assertFalse(self._exists(self.filesdir))
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))
# pre-existing bibtex
self.assertTrue(self._exists(self.anotherbib))
self.assertFalse(self._exists("papers.bib"))
self.papers(f'install --force --local')
self.assertTrue(self._exists(".papers/config.json"))
config = Config.load(self._path(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.anotherbib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path("files")))
self.assertFalse(config.git)


def test_install_defaults_preexisting_pdfs(self):
self.assertFalse(self._exists(self.filesdir))
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))
# pre-existing pdfs folder (pre-defined set of names)
os.makedirs(self._path("pdfs"))
self.papers(f'install --force --local')
self.assertTrue(self._exists(".papers/config.json"))
config = Config.load(self._path(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
# self.assertEqual(config.bibtex, os.path.abspath(self._path("papers.bib")))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.anotherbib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path("pdfs")))
self.assertFalse(config.git)

def test_install_raise(self):
self.papers(f'install --force --local --bibtex {self.mybib} --files {self.filesdir}')
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(self.mybib))
self.assertTrue(self._exists(self.filesdir))
f = lambda : self.papers(f'install --local --bibtex {self.mybib} --files {self.filesdir}')
self.assertRaises(Exception, f)

def test_install_force(self):
self.papers(f'install --force --local --bibtex {self.mybib} --files {self.filesdir}')
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(self.mybib))
self.assertTrue(self._exists(self.filesdir))
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
self.papers(f'install --local --force --bibtex {self.mybib}XX')
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib + "XX")))
# The files folder from previous install was forgotten
self.assertEqual(config.filesdir, os.path.abspath(self._path("files")))
self.assertFalse(config.git)

def test_install_edit(self):
self.papers(f'install --force --local --bibtex {self.mybib} --files {self.filesdir}')
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(self.mybib))
self.assertTrue(self._exists(self.filesdir))
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
self.papers(f'install --local --edit --bibtex {self.mybib}XX')
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib + "XX")))
# The files folder from previous install is remembered
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
Expand All @@ -126,10 +126,10 @@ def test_install_interactive(self):
{self.filesdir}
n
EOF""", shell=True, cwd=self.temp_dir.name)
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(self.mybib))
self.assertTrue(self._exists(self.filesdir))
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
self.assertFalse(config.git)
Expand All @@ -142,10 +142,10 @@ def test_install_interactive(self):
EOF""", shell=True, cwd=self.temp_dir.name)
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(self.mybib))
self.assertTrue(self._exists(self.filesdir))
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib)))
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))

Expand All @@ -155,7 +155,7 @@ def test_install_interactive(self):
y
n
EOF""", shell=True, cwd=self.temp_dir.name)
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib + "XX")))
# The files folder from previous install is remembered
self.assertEqual(config.filesdir, os.path.abspath(self._path(self.filesdir)))
Expand All @@ -167,7 +167,7 @@ def test_install_interactive(self):
y
n
EOF""", shell=True, cwd=self.temp_dir.name)
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.mybib + "XX")))
# The files folder from previous install was forgotten
self.assertEqual(config.filesdir, os.path.abspath(self._path("files")))
Expand All @@ -180,7 +180,7 @@ def test_install_interactive(self):
reset
n
EOF""", shell=True, cwd=self.temp_dir.name)
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.bibtex, None)
# The files folder from previous install was forgotten
self.assertEqual(config.filesdir, None)
Expand All @@ -194,7 +194,7 @@ def test_install_interactive(self):
y
y
EOF""", shell=True, cwd=self.temp_dir.name)
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
## by default another bib is detected, because it starts with a (sorted)
self.assertEqual(config.bibtex, os.path.abspath(self._path(self.anotherbib)))
# The files folder from previous install was forgotten
Expand Down Expand Up @@ -226,17 +226,17 @@ class TestInstallEditor(TestBaseInstall):

def test_install(self):
self.papers(f'install --force --local --editor "subl -w"')
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertEqual(config.editor, "subl -w")


class TestDefaultLocal(LocalInstallTest):
def test_install(self):
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self.config.local)
self.papers(f'install --edit')
self.assertTrue(self._exists(".papers/config.json"))
config = Config.load(self._path(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertTrue(config.local)

class TestDefaultLocal2(GlobalInstallTest):
Expand Down Expand Up @@ -268,7 +268,7 @@ class TestGitInstall(TestBaseInstall):

def test_install_gitlfs(self):
self.papers(f'install --local --no-prompt --git-lfs')
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertTrue(config.git)
# self.assertTrue(self._exists(".git"))

Expand Down Expand Up @@ -296,7 +296,7 @@ def test_install_interactive(self):
y
y
EOF""")
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertTrue(config.git)
self.assertTrue(config.gitlfs)

Expand All @@ -305,23 +305,23 @@ def test_install_interactive2(self):
y
n
EOF""")
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertTrue(config.git)
self.assertFalse(config.gitlfs)

def test_install_interactive3(self):
self.papers(f"""install --local --filesdir files --bibtex bibbib.bib << EOF
n
EOF""")
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertFalse(config.git)
self.assertFalse(config.gitlfs)

def test_install_interactive4(self):
self.papers(f"""install --local --filesdir files --bibtex bibbib.bib << EOF
EOF""")
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertFalse(config.git)
self.assertFalse(config.gitlfs)

Expand All @@ -330,7 +330,7 @@ def test_install_interactive5(self):
y
EOF""")
config = Config.load(self._path(".papers/config.json"))
config = Config.load(self._path(CONFIG_FILE_LOCAL))
self.assertTrue(config.git)
self.assertFalse(config.gitlfs)

Expand Down Expand Up @@ -428,25 +428,25 @@ def test_undo(self):

class TestUninstall(LocalInstallTest):
def test_uninstall(self):
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.papers(f'uninstall')
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))


class TestUninstall2(GlobalInstallTest):
def test_uninstall(self):
self.assertTrue(self._exists(CONFIG_FILE))
self.papers(f'install --force --local')
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(CONFIG_FILE))
self.papers(f'uninstall')
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(CONFIG_FILE))

def test_uninstall(self):
self.papers(f'install --force --local')
self.assertTrue(self._exists(".papers/config.json"))
self.assertTrue(self._exists(CONFIG_FILE_LOCAL))
self.assertTrue(self._exists(CONFIG_FILE))
self.papers(f'uninstall --recursive')
self.assertFalse(self._exists(".papers/config.json"))
self.assertFalse(self._exists(CONFIG_FILE_LOCAL))
self.assertFalse(self._exists(CONFIG_FILE))

0 comments on commit c5599e4

Please sign in to comment.