-
Notifications
You must be signed in to change notification settings - Fork 99
Updating find_unused_modules script #3760
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
Conversation
The PR preview for c4b9779 is available at theforeman-foreman-documentation-preview-pr-3760.surge.sh No diff compared to the current base |
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.
Tested locally; it works as expected:
$ ./guides/scripts/find_unused_modules.py
proc_configuring-repositories-katello.adoc
proc_configuring-repositories-foreman-el.adoc
proc_configuring-repositories-satellite.adoc
proc_configuring-repositories-orcharhino.adoc
$ echo $?
0
There are still false positives but this is much much better than before. Thanks Avital.
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.
Something that I came across when playing with #3741 was the :sourcemap
option in https://docs.asciidoctor.org/asciidoctor/latest/api/options/
Tracks the file and line number for each parsed block. Useful for tooling applications where the association between the converted output and the source file is important.
https://docs.asciidoctor.org/asciidoctor/latest/api/sourcemap/ is a longer document that shows asciidoctor internally keeps track of all the files it uses. It actually made me think about creating debug outputs where we display within the rendered guide the actual source location for each paragraph.
Taking it back to this script: would it make sense to adopt a strategy of actually rendering all guides in all flavors and then look at which files it actually used? That way we're not guessing. It will also catch edge cases where we use variables in filenames.
@ekohl Pity we didn't know about this while we were still committed to Asciidoc! 😄 At the moment, it's probably best to keep our tools as generic as possible. The effects of the d/s tooling changes are still a mystery. When we know more, we can think about updating our tools. |
I couldn't help myself: #!/usr/bin/env ruby
# frozen_string_literal: true
require 'asciidoctor'
BUILDS = %w[
foreman-el
foreman-deb
katello
satellite
orcharhino
].freeze
BASE_DIR = File.dirname(__dir__)
included = Set.new
Dir.glob(File.join(BASE_DIR, '*', 'master.adoc')).each do |path|
BUILDS.each do |build|
doc = Asciidoctor.load_file(
path,
doctype: :book,
safe: :safe,
base_dir: BASE_DIR,
attributes: { 'build' => build }
)
included += doc.catalog[:includes].keys
end
end
all_modules = Dir.glob(File.join(BASE_DIR, 'common', 'modules', '**', '*.adoc'))
absolute_included = included.map { |path| File.join(BASE_DIR, "#{path}.adoc") }
puts all_modules - absolute_included $ guides/scripts/find_modules
asciidoctor: ERROR: master.adoc: line 5: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman.adoc
asciidoctor: ERROR: master.adoc: line 21: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman-contributors.adoc
asciidoctor: ERROR: master.adoc: line 5: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman.adoc
asciidoctor: ERROR: master.adoc: line 21: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman-contributors.adoc
asciidoctor: ERROR: master.adoc: line 11: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman.adoc
asciidoctor: ERROR: master.adoc: line 12: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/katello.adoc
asciidoctor: ERROR: master.adoc: line 21: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman-contributors.adoc
asciidoctor: ERROR: master.adoc: line 28: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/katello-contributors.adoc
asciidoctor: ERROR: master.adoc: line 5: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman.adoc
asciidoctor: ERROR: master.adoc: line 21: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman-contributors.adoc
asciidoctor: ERROR: master.adoc: line 5: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman.adoc
asciidoctor: ERROR: master.adoc: line 21: include file not found: /home/ekohl/dev/foreman-documentation/guides/topics/foreman-contributors.adoc
/home/ekohl/dev/foreman-documentation/guides/common/modules/con_configuring-keycloak-wildfly-authentication-with-piv-cards-for-project.adoc
/home/ekohl/dev/foreman-documentation/guides/common/modules/snip_prerequisites-content-for-sles.adoc This is a different approach. I'm ignoring the errors from the release notes for now. It shows a false positive for Then it finds |
That's because I'm setting the
This should be The whole file: #!/usr/bin/env ruby
# frozen_string_literal: true
require 'asciidoctor'
BUILDS = %w[
foreman-el
foreman-deb
katello
satellite
orcharhino
].freeze
BASE_DIR = File.dirname(__dir__)
included = Set.new
Dir.glob(File.join(BASE_DIR, '*', 'master.adoc')).each do |path|
BUILDS.each do |build|
doc = Asciidoctor.load_file(
path,
doctype: :book,
safe: :safe,
base_dir: File.dirname(path),
attributes: { 'build' => build }
)
included += doc.catalog[:includes].keys
end
end
all_modules = Dir.glob(File.join(BASE_DIR, 'common', 'modules', '**', '*.adoc'))
absolute_included = included.map { |path| File.join(BASE_DIR, "#{path}.adoc") }
puts all_modules - absolute_included Now the output is: $ guides/scripts/find_modules
/home/ekohl/dev/foreman-documentation/guides/common/modules/con_configuring-keycloak-wildfly-authentication-with-piv-cards-for-project.adoc
/home/ekohl/dev/foreman-documentation/guides/common/modules/snip_prerequisites-content-for-sles.adoc |
What changes are you introducing?
Added a line to detect snippets included in modules.
Added a comment that script does not work on file includes that contain attributes. User will have to ignore those files in the output.
Why are you introducing these changes? (Explanation, links to references, issues, etc.)
Snippets included in modules were reported as false positives.
Anything else to add? (Considerations, potential downsides, alternative solutions you have explored, etc.)
I tested this with a fake snippet. It was detected.
No style review required.
Checklists
Please cherry-pick my commits into: