-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Paths in config file are relative to the config file. #1376
Conversation
Awesome! I'll have to take a closer look when I have some time. |
Just found an issue: plugins aren't getting normalized properly. Should have it fixed soon too. |
All ready now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the specific comments below, we should also update the docs and add something to the release notes.
mkdocs/config/base.py
Outdated
""" | ||
The schema is a Python dict which maps the config name to a validator. | ||
""" | ||
|
||
self._schema = schema | ||
self._schema_keys = set(dict(schema).keys()) | ||
self.fname = fname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not crazy about naming this fname
. Considering its intended use, we don't care about the "name" of the file, but rather the "path" to the file. Using fname
indicates to me that I only need to pass in the name of the file, not the full path. However, in actual use, I need to pass in the absolute path (and it might even work if I left off the filename). Therefore, let's indicate that with the name used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe config_path
?
mkdocs/config/config_options.py
Outdated
|
||
config_dir = os.path.dirname(config.fname) | ||
value = os.path.join(config_dir, value) | ||
config[key_name] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than a pre-validation method, perhaps an abspath
method would make more sense. Then anywhere we need an absolute path, just pass the value into the self.abspath
method. And let's put it on the BaseConfigOption
class so its available everywhere.
Note that you missed the custom_dir
sub-setting of the theme setting here. That is not in a FilesystemObject
subclass. And its entirely possible that Plugins could use various of the BaseConfigOption
sub-classes or even create their own. to validate their own sub-settings. The point is, this ability to convert a relative path to an absolute path should be available from everywhere within the config validation classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I just realized the problem with this. The config (which contains the base path) is only available from the pre_validation
and post_validation
methods. Therefore, we can only do this from there.
Hmm, for some reason the AppVeyor py33 tests are running on Python 2.7. |
The py33 tests are being handled in #1453. Guess we can move on with this issue by updating the docs/release notes. |
We care about the "path" not the "file name". And we were already using config_file_path in someplaces. Therefore, we should use it everywhere.
Guess I broke this when I rebased.
Fixes mkdocs#1291 and made possable by the work in mkdocs#1376.
|
||
Previously any relative paths in the various configuration options were | ||
resolved relative to the current working directory. They are now resolved | ||
relative to the configuration file. As the documentation has always encouraged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waylan I couldn't find it anywhere in the docs, but what about for inherited config files? Are the paths in those inherited config files relative to the parent config file or the child config file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't necro-bump and especially don't tag people while doing so.
The answer is here
mkdocs/docs/user-guide/configuration.md
Lines 1047 to 1048 in ae4a639
As a reminder, all path based configuration options must be relative to the | |
primary configuration file and MkDocs does not alter the paths when merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(you can ask a question as a Discussion instead)
Ran into #543 today, saw that no one had started working on this, so decided to take a stab at it. I used
pre_validation
to coerce relative paths to absolute paths, which worked for my use case.Two things I wasn't sure of where to go with:
Config.load_file
is passed something without a filename? I found a few tests where that was the case, but couldn't think of a use case otherwise. I reverted to the current behavior in this scenario (relative paths are left alone, so they're relative to the current working directory)./tmp
, and relied on the existence./docs
in order to pass validation. I cleaned up the tests, but usedtempfile.TemporaryDirectory
, which doesn't exist in py<3.2. Installingbackports.tempfile
took care of that, but made the imports a little more complex (you'll see them in the*_tests.py
files).Thanks for making this project available!
Fixes #543