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

load project-specific configuration as well as user-specific #1469

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Nov 14, 2022

so that you can configure a plugin per-project

Completed Tasks

  • I have read the [Contributing Guide][contrib].
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).

so that you can configure a plugin per-project
Copy link
Owner

@lsegal lsegal left a comment

Choose a reason for hiding this comment

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

Added a few specific comments that would bar this from being accepted. In general I'm noticing quite a few breaking changes which are a blocker for merging. There are also a few deprecations, many of which do not seem necessary. It seems to me like project based configuration could be implemented in a completely additive fashion rather than changing any existing behaviors.

Overall, however, I think a little bit more thought needs to be put into the semantics of this feature for it to be valuable to various users / use cases. As it stands, it seems as though "project directory" is loosely defined by this PR as the current working directory, which is not exactly the most reliable way to do this. I think at the very least, this would need to be documented, but more accurately, I don't think you can really define a "project directory" without the ability to customize said directory. That makes this PR a little bit harder to build, as it would (ideally) require CLI options for users to configure / customize where their "project" is. Also, as a small sidenote here, I notice you only support the config file and not the full directory, which I think some users may have an issue with. Supporting this approach would lead to a bigger maintenance burden than implementing it correctly the first time around.

Another more generalized approach to this problem would be to simply go the node_modules route and search for a .yard directory in each parent directory to the root, followed by a ~/.yard search. This would be compatible with eventually supporting #1230 as a final lookup location.

tl;dr simply implementing better lookup semantics for the .yard config directory would probably solve a lot of the needs for a project specific environment. Alternatively, simply having a CLI options that is also configurable via environment variable that points to said config dir / file / etc would probably solve 99% of the use cases here, even without directory lookup semantics.

Comment on lines +95 to +98
USER_CONFIG_DIR = File.expand_path('~/.yard')

# The main configuration YAML file.
CONFIG_FILE = File.join(CONFIG_DIR, 'config')
# @deprecated Use {USER_CONFIG_DIR}
CONFIG_DIR = USER_CONFIG_DIR
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure this is a necessary deprecation-- it seems arbitrary to name this USER_CONFIG_DIR when there does not seem to be a "project config directory" equivalent anyway.


# File listing all ignored plugins
# @deprecated Set `ignored_plugins` in the {CONFIG_FILE} instead.
IGNORED_PLUGINS = File.join(CONFIG_DIR, 'ignored_plugins')
IGNORED_PLUGINS = File.join(USER_CONFIG_DIR, 'ignored_plugins')
Copy link
Owner

Choose a reason for hiding this comment

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

It seems as though IGNORED_PLUGINS would not support project configuration? Seems like an omission in functionality.

def self.read_config_file
if File.file?(CONFIG_FILE)
# @see config_file
def self.read_config_file(config_file)
Copy link
Owner

Choose a reason for hiding this comment

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

Requiring a parameter would be a breaking change. Why not default to using CONFIG_FILE?

Comment on lines +130 to +140
def self.config_file(dir)
File.join(dir, 'config')
end

def self.load_project_config_file
load_config_file(config_file(".yard"))
end

def self.load_user_config_file
load_config_file(config_file(USER_CONFIG_DIR))
end
Copy link
Owner

Choose a reason for hiding this comment

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

These should be documented (and whichever are not intended to be used should be marked @private).

Comment on lines +5 to +9
before do
allow(File).to receive(:file?).with(".yard/config").and_return(false)
allow(File).to receive(:file?).with(".yardopts").and_return(false)
end

Copy link
Owner

Choose a reason for hiding this comment

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

I would expect to see actual tests for the new APIs:

  1. load_config_file is missing tests.
  2. read_config_file behavior seems to be missing tests.

Some of this may already be tested via wider unit tests, but there should at least be a few scenarios for the theoretical project based usage.

@ccutrer
Copy link
Contributor Author

ccutrer commented Jan 6, 2023

Ooh yay, YARD isn't abandoned!

I'm a little surprised at the pushback to the assumption that "project dir" == .. Isn't this how everything else in YARD works, right down to a .yardopts file? Is it even possible to run YARD anywhere except for from the project root? But that's okay... given a .yardopts file, I think it's reasonable to just add an explicit option to specify an explicit config dir.

That said, this is one of my bigger PRs, and it's been a while since I've worked on it. I have several others - most of them I have not even sent as PRs, since I just started pointing my project at my own fork of YARD. If the others go well, I'll start sending more PR, and then consider putting in the time addressing the comments on this one.

@lsegal
Copy link
Owner

lsegal commented Jan 6, 2023

I'm a little surprised at the pushback to the assumption that "project dir" == .

The issue isn't the assumption / default behavior, it's the lack of configurability. It's fine to assume the default, but YARD supports configuration of all of the other values, up to and including where the .yardopts file lives, where the .yardoc cache lives, and where any outputs go. The main issue here is that this PR has no such escape hatch / configuration.

@ccutrer
Copy link
Contributor Author

ccutrer commented Jan 6, 2023

I'm a little surprised at the pushback to the assumption that "project dir" == .

The issue isn't the assumption / default behavior, it's the lack of configurability. It's fine to assume the default, but YARD supports configuration of all of the other values, up to and including where the .yardopts file lives, where the .yardoc cache lives, and where any outputs go. The main issue here is that this PR has no such escape hatch / configuration.

👍 ah okay, that makes more sense. I'll probably just re-implement as a switch to change the config dir, making sure that switch will be applied if it's in a yardopts file. That will be sufficient for my needs.

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.

2 participants