grading_checker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2292bd3d0df83ef4c8c9b2011f1d4e5d2127aa07852ab8da97fee63cc3c0dc66
4
+ data.tar.gz: 7daea1c9fe6e4cf517a8028c1afdd651f42b1bb3d39923206be32cefb1c24c17
5
+ SHA512:
6
+ metadata.gz: 92fd669a680bfdeedc72aa298352395e000b40e11cecc5afa76d1500cf8a2de988e51cc6761e4625cf11afb1f8ddc2220442ef462c0e22f3831e43e4ea951c2c
7
+ data.tar.gz: 2e03441a59665e03bd00cf1d835eed96ca0e42d9e30981811ee302cf2274c0c861b97a8ab22e15049c22003d2c1eed561c4b23d52b09f9e76ce0d71f9034ad4c
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Layout/IndentationWidth:
11
+ Width: 4
12
+
13
+ Bundler/OrderedGems:
14
+ Enabled: false
15
+
16
+ Style/ClassAndModuleChildren:
17
+ Enabled: false
18
+
19
+ Layout/EmptyLinesAroundClassBody:
20
+ Enabled: false
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
24
+
25
+ Layout/EmptyLinesAroundModuleBody:
26
+ EnforcedStyle: empty_lines
27
+
28
+ Style/RedundantReturn:
29
+ Enabled: false
30
+
31
+ Layout/CaseIndentation:
32
+ EnforcedStyle: case
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-02-24
4
+
5
+ - Initial release of `GradingChecker`.
6
+ - Validates `grading.yml` and `submit.yml` configuration files.
7
+ - Checks for duplicate submission names in `submit.yml`.
8
+ - Ensures a valid `grading.yml` structure in the root directory and subdirectories.
9
+ - Reports errors and provides clear feedback on misconfigurations.
10
+ - Supports command-line execution with an optional directory argument.
11
+ - Added `--help` flag to display usage instructions.
12
+ - Returns appropriate exit codes (`0` for success, `1` for validation errors).
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Martijn Stegeman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # GradingChecker
2
+
3
+ GradingChecker is a tool designed to validate grading configuration files (`grading.yml` and `submit.yml`) in a given directory.
4
+ It is intended to be used on courseware repositories for the [Course Site](https://github.com/stgm/course-site).
5
+ This tool ensures that submission names are unique and that grading configurations follow the expected structure.
6
+
7
+ ## Features
8
+
9
+ - Checks for duplicate submission names in `submit.yml` files.
10
+ - Validates the structure of `grading.yml` files in the root and subdirectories.
11
+ - Reports errors and provides clear feedback on misconfigurations.
12
+ - Supports a simple command-line interface.
13
+
14
+ ## Installation
15
+
16
+ To install the gem:
17
+
18
+ ```sh
19
+ gem install grading_checker
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Run the command to validate grading configurations:
25
+
26
+ ```sh
27
+ grading_checker [DIRECTORY]
28
+ ```
29
+
30
+ - If no directory is provided, the current directory is used.
31
+ - The tool will scan for `grading.yml` and `submit.yml` files and report any issues.
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stgm/grading_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/stgm/grading_checker/blob/main/CODE_OF_CONDUCT.md).
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the GradingChecker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/stgm/grading_checker/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "grading_checker"
4
+
5
+ # Usage explanation
6
+ if ARGV.include?("--help") || ARGV.include?("-h")
7
+ puts <<~HELP
8
+ Usage: grading_checker [DIRECTORY]
9
+
10
+ Validates grading.yml and submit.yml files in the specified DIRECTORY.
11
+ If no directory is provided, the current working directory is used.
12
+
13
+ Checks performed:
14
+ - Ensures no duplicate submission names in submit.yml files.
15
+ - Validates the structure of grading.yml files in the root and subdirectories.
16
+ - Reports errors if any issues are found.
17
+
18
+ Exit codes:
19
+ 0 - All checks passed.
20
+ 1 - Validation errors detected.
21
+
22
+ Options:
23
+ -h, --help Show this help message and exit.
24
+ HELP
25
+ exit 0
26
+ end
27
+
28
+ root_path = ARGV[0] || Dir.pwd
29
+ file_manager = GradingChecker::FileManager.new(root_path)
30
+ validator = GradingChecker::GradingYAMLValidator.new(file_manager)
31
+ validator.validate_duplicate_submit_names!
32
+ validator.validate_root_grading_config!
33
+ validator.validate_subdir_configs!
34
+ validator.report_success("all grading.yml files seem to be valid")
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GradingChecker
4
+
5
+ VERSION = "0.1.0"
6
+
7
+ end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "grading_checker/version"
4
+ require "rainbow"
5
+ require "yaml"
6
+ require "pathname"
7
+ require "ripper"
8
+
9
+ module GradingChecker
10
+
11
+ class Error < StandardError; end
12
+
13
+ class FileManager
14
+ attr_reader :root_path
15
+
16
+ def initialize(root_path)
17
+ @root_path = Pathname.new(root_path)
18
+ end
19
+
20
+ def load_yaml(file_path)
21
+ return {} unless file_path.exist?
22
+
23
+ YAML.load_file(file_path, aliases: true) || {}
24
+ rescue StandardError => e
25
+ abort("Error loading YAML file: #{file_path}\n#{e.message}")
26
+ end
27
+
28
+ def find_grading_ymls
29
+ @root_path.find.select { |path| path.file? && path.basename.to_s == "grading.yml" }
30
+ end
31
+
32
+ def find_submit_ymls
33
+ @root_path.find.select { |path| path.file? && path.basename.to_s == "submit.yml" }
34
+ end
35
+
36
+ def merge_configs(grades1, grades2)
37
+ first_without_grades = grades1.reject { |k, _| %w[templates grades calculation].include?(k) }
38
+ second_without_grades = grades2.reject { |k, _| %w[templates grades calculation].include?(k) }
39
+
40
+ merged_grades = (grades1["grades"] || {}).merge(grades2["grades"] || {})
41
+ merged_calculation = (grades1["calculation"] || {}).merge(grades2["calculation"] || {})
42
+ merged_rest = first_without_grades.merge(second_without_grades)
43
+ merged_rest["grades"] = merged_grades
44
+ merged_rest["calculation"] = merged_calculation
45
+
46
+ merged_rest
47
+ end
48
+ end
49
+
50
+ class GradingYAMLValidator
51
+ VALID_GRADE_TYPES = %w[pass float integer points].freeze
52
+ VALID_SUBGRADE_TYPES = %w[integer pass boolean float].freeze
53
+ DEFAULT_GRADE_TYPE = "float"
54
+
55
+ GREEN = Rainbow(":)").green
56
+ RED = Rainbow(":(").red
57
+
58
+ def initialize(file_manager)
59
+ @file_manager = file_manager
60
+ end
61
+
62
+ def validate_root_grading_config!
63
+ @root_config = @file_manager.load_yaml(@file_manager.root_path.join("grading.yml"))
64
+ validate_yaml_structure(@root_config, "grading.yml")
65
+ end
66
+
67
+ def validate_subdir_configs!
68
+ @file_manager.find_grading_ymls.each do |path|
69
+ next if path.dirname == @file_manager.root_path
70
+
71
+ merged_config = @file_manager.merge_configs(@root_config, @file_manager.load_yaml(path))
72
+ validate_yaml_structure(merged_config, path.relative_path_from(@file_manager.root_path).to_s)
73
+ end
74
+ end
75
+
76
+ def validate_duplicate_submit_names!
77
+ submit_names = Hash.new { |hash, key| hash[key] = [] }
78
+
79
+ submit_ymls = @file_manager.find_submit_ymls
80
+ submit_ymls.each do |path|
81
+ submit_config = @file_manager.load_yaml(path)
82
+ next unless submit_config.is_a?(Hash) && submit_config.key?("name")
83
+
84
+ submit_names[submit_config["name"]] << path.relative_path_from(@file_manager.root_path).to_s
85
+ end
86
+
87
+ duplicate_submits = submit_names.select { |_, paths| paths.size > 1 }
88
+
89
+ if duplicate_submits.any?
90
+ report_error("duplicate submit names found in submit.yml:")
91
+ duplicate_submits.each do |name, paths|
92
+ puts " - #{name} appears in: #{paths.join(", ")}"
93
+ end
94
+ exit(1)
95
+ else
96
+ report_success("no duplicate submit names found in #{submit_ymls.size} submit.yml configs")
97
+ end
98
+ end
99
+
100
+ def validate_yaml_structure(config, file_name)
101
+ validate_section(config, "templates") do |templates|
102
+ templates.each do |key, value|
103
+ unless value.is_a?(Hash) && value.key?("type")
104
+ report_error("template #{key} must be a hash with a 'type' key")
105
+ exit(1)
106
+ end
107
+ end
108
+ end
109
+
110
+ validate_section(config, "grades") do |grades|
111
+ grades.each do |grade, details|
112
+ grade_type = details["type"] || DEFAULT_GRADE_TYPE
113
+ unless VALID_GRADE_TYPES.include?(grade_type)
114
+ report_error("grade #{grade} has an invalid type: #{grade_type}. Must be one of #{VALID_GRADE_TYPES.join(", ")}")
115
+ exit(1)
116
+ end
117
+ end
118
+ end
119
+
120
+ validate_module_definitions(config)
121
+
122
+ validate_section(config, "calculation") do |calculation|
123
+ calculation.each do |calc, details|
124
+ unless details.is_a?(Hash)
125
+ report_error("calculation #{calc} must be a hash of weighted components")
126
+ exit(1)
127
+ end
128
+ end
129
+ end
130
+
131
+ report_success(file_name)
132
+ end
133
+
134
+ def validate_section(config, section)
135
+ return unless config.key?(section)
136
+
137
+ unless config[section].is_a?(Hash)
138
+ report_error("#{section.capitalize} section must be a hash")
139
+ exit(1)
140
+ end
141
+ yield(config[section]) if block_given?
142
+ end
143
+
144
+ def validate_module_definitions(config)
145
+ return unless config.is_a?(Hash)
146
+
147
+ grade_keys = config["grades"]&.keys || []
148
+
149
+ config.each do |key, value|
150
+ next unless value.is_a?(Hash) && value.key?("submits")
151
+
152
+ unless value["submits"].is_a?(Hash)
153
+ report_error("module definition #{key} has an invalid submits section: it must be a hash.")
154
+ exit(1)
155
+ end
156
+
157
+ value["submits"].each_key do |submit_key|
158
+ unless grade_keys.include?(submit_key)
159
+ report_error("module definition #{key} references a non-existent grade: #{submit_key}")
160
+ exit(1)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def report_success(message)
167
+ puts "#{GREEN} #{message}"
168
+ end
169
+
170
+ def report_error(message)
171
+ puts "#{RED} #{message}"
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,4 @@
1
+ module GradingChecker
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grading_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martijn Stegeman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: For courseware repositories
14
+ email:
15
+ - martijn@stgm.nl
16
+ executables:
17
+ - grading_checker
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - exe/grading_checker
28
+ - lib/grading_checker.rb
29
+ - lib/grading_checker/version.rb
30
+ - sig/grading_checker.rbs
31
+ homepage: https://github.com/stgm/grading_checker
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.14
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Check grading configs
54
+ test_files: []