diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index 27beed2..7960c35 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -172,8 +172,8 @@ because ctypes access libraries in a platform-dependent manner, it is recommended that you create a configuration file to help glymur properly find the openjp2 library. You may create the configuration file as follows:: - $ mkdir ~/.glymur - $ cd ~/.glymur + $ mkdir -p ~/.config/glymur + $ cd ~/.config/glymur $ cat > glymurrc << EOF > [library] > openjp2: /opt/openjp2-svn/lib/libopenjp2.so diff --git a/glymur/__init__.py b/glymur/__init__.py index 3525b6a..795d3d9 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -8,7 +8,7 @@ def _glymurrc_fname(): Search order: 1) current working directory 2) environ var GLYMURCONFIGDIR - 3) HOME/.glymur/glymurrc + 3) $HOME/.config/glymur/glymurrc """ # Current directory. @@ -62,15 +62,15 @@ def _config(): def _get_configdir(): """Return string representing the configuration directory. - Default is HOME/.glymur. You can override this with the GLYMURCONFIGDIR - environment variable. + Default is $HOME/.config/glymur. You can override this with the + GLYMURCONFIGDIR environment variable. """ if 'GLYMURCONFIGDIR' in os.environ: return os.environ['GLYMURCONFIGDIR'] if 'HOME' in os.environ: - return os.path.join(os.environ['HOME'], '.glymur') + return os.path.join(os.environ['HOME'], '.config', 'glymur') import warnings import sys diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index b4ca59a..5579c8a 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -641,7 +641,7 @@ class TestJp2k(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_home_dir_missing_config_dir(self): - # Verify no exception is raised if $HOME is missing .glymur directory. + # Verify no exception is raised if $HOME is missing .config directory. with tempfile.TemporaryDirectory() as tdir: with patch.dict('os.environ', {'HOME': tdir}): # Misconfigured new configuration file should @@ -649,6 +649,24 @@ class TestJp2k(unittest.TestCase): with self.assertWarns(UserWarning) as cw: imp.reload(glymur) + @unittest.skipIf(sys.hexversion < 0x03020000, + "Uses features introduced in 3.2.") + def test_home_dir_missing_glymur_rc_dir(self): + # Should warn but not error if $HOME/.config but no glymurrc dir. + with tempfile.TemporaryDirectory() as tdir: + # We need the subdirectory to be specifically named as ".config" + # in order for this test to work. A specifically-named temporary + # directory does not seem to be possible, so try to symlink it. + # Supposedly the symlink gets cleaned up with tdir gets cleaned up. + with tempfile.TemporaryDirectory(suffix=".config", dir=tdir) \ + as tdir_config: + os.symlink(tdir_config, os.path.join(tdir, '.config')) + with patch.dict('os.environ', {'HOME': tdir}): + # Misconfigured new configuration file should + # be rejected. + with self.assertWarns(UserWarning) as cw: + imp.reload(glymur) + def test_xmp_attribute(self): # Verify that we can read the XMP packet in our shipping example file. j = Jp2k(self.jp2file)