Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing custom cache directory name through ini option (issue #2543) #2551

Closed
wants to merge 9 commits into from
Closed

Conversation

RockBomber
Copy link
Contributor

No description provided.

@@ -14,7 +14,8 @@
class Cache(object):
def __init__(self, config):
self.config = config
self._cachedir = config.rootdir.join(".cache")
cache_dirname = config.getini("cache_dirname")
self._cachedir = config.rootdir.join(cache_dirname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.join will deconstruct absolute arguments into relative paths

>>> py.path.local().join('/bin')
local('/home/ronny/Projects/pytest-dev/pytest/bin')

>>> py.path.local().join('/bin', abs=1)
local('/bin')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to bring this further, people might also use ~ as shortcut form home, and py.path doesnt autoresolve those

so correctness unfortunately needs a few more tests and cases handled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this option is not for setting cache path. It is for change default name of cache directory, wich is created in rootdir.
ini option for setting cache path is so more difficult feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RockBomber good point, in that case, how about warn/fail in case its an absolute path or it starts with ~ until someone implements a more complete solution

Copy link
Member

@nicoddemus nicoddemus Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also my understanding that this was supposed to be relative to the rootdir.

I'm curious, why do you guys say it would be more difficult to support absolute paths? Can't we assume:

  1. If relative path, relative to rootdir;
  2. If absolute path, just use it as it is;

I think this might be an interim solution for #1089 for example. We might even consider calling os.path.expandvars on the variable, which would allow users to specify $XDG_CONFIG_DIR as the cache directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'll try to add an appropriate warning or error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure, unless I'm missing something (and please clarify me if I am), wouldn't be just as easy to support both relative and absolute paths as I mentioned above?

I like the idea of supporting relative and absolute paths because we can eventually change the default to $XDG_CACHE_DIR as discussed in #1089.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.139% when pulling 76b8e32 on RockBomber:features into 0303d95 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 92.14% when pulling cac1892 on RockBomber:features into 0303d95 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 92.14% when pulling 123c139 on RockBomber:features into 0303d95 on pytest-dev:features.



class Cache(object):
def __init__(self, config):
self.config = config
self._cachedir = config.rootdir.join(".cache")
cache_dirname = config.getini("cache_dirname")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather name this cache_dir instead so we can support absolute paths in the future.

cache_dirname = config.getini("cache_dirname")
if _isabs(_expanduser(cache_dirname)):
raise ValueError("cache dirname must be relative path, not absolute")
self._cachedir = config.rootdir.join(cache_dirname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to create a staticmethod Cache.cache_dir_from_config(config) which contains this logic; this would enhance the readability and also allow you to unittest the logic inside it more easily.

@@ -262,3 +262,11 @@ Builtin configuration file options

This tells pytest to ignore deprecation warnings and turn all other warnings
into errors. For more information please refer to :ref:`warnings`.

.. confval:: cache_dirname

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

""")
testdir.makepyfile(test_errored='def test_error():\n assert False')
testdir.runpytest()
assert os.path.exists('custom_cache_dirname')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this is passing... does testdir change the cwd of the test?

You might be more explicit here either way:

assert testdir.tmpdir.join('custom_cache_dirname').isdir()

assert os.path.exists('custom_cache_dirname')

@pytest.mark.parametrize('custom_cache_dirname', [
pytest.param('/tmp/mycache', marks=pytest.mark.skipif(sys.platform == 'win32',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use just os.path.abspath('tmp') and it will work for all platforms, no need to parametrize for each.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 92.142% when pulling 6cc52c1 on RockBomber:features into 0303d95 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 92.142% when pulling 867aaeb on RockBomber:features into 0303d95 on pytest-dev:features.

@RockBomber
Copy link
Contributor Author

I will do new pull request with support both absolute and relative pathes

@RockBomber RockBomber closed this Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants