-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6b95e6
commit ec715ec
Showing
10 changed files
with
242 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,85 @@ | ||
use aqora_config::ReadMe; | ||
use mime::Mime; | ||
use std::path::Path; | ||
use std::path::{Path, PathBuf}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ReadMeError { | ||
pub enum ReadmeError { | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
#[error("Readme not found")] | ||
#[error("README not found")] | ||
NotFound, | ||
#[error("Readme content type not supported. Only markdown and plaintext supported")] | ||
#[error("README content type not supported. Only markdown and plaintext supported")] | ||
ContentTypeNotSupported, | ||
} | ||
|
||
pub async fn read_readme( | ||
pub async fn get_readme_path( | ||
project_dir: impl AsRef<Path>, | ||
readme: Option<&ReadMe>, | ||
) -> Result<Option<String>, ReadMeError> { | ||
) -> Result<Option<PathBuf>, ReadmeError> { | ||
let path = match readme { | ||
Some(ReadMe::Table { | ||
ref file, | ||
text, | ||
text: _, | ||
content_type, | ||
}) => { | ||
let path: Option<&Path> = file.as_deref().map(str::as_ref); | ||
if let Some(content_type) = content_type { | ||
let mime: Mime = content_type | ||
.parse() | ||
.map_err(|_| ReadMeError::ContentTypeNotSupported)?; | ||
.map_err(|_| ReadmeError::ContentTypeNotSupported)?; | ||
if !(mime.type_() == mime::TEXT | ||
&& (mime.subtype() == mime::PLAIN || mime.subtype() == "markdown")) | ||
{ | ||
return Err(ReadMeError::ContentTypeNotSupported); | ||
return Err(ReadmeError::ContentTypeNotSupported); | ||
} | ||
} | ||
if let Some(text) = text { | ||
return Ok(Some(text.to_owned())); | ||
} | ||
path | ||
path.map(|p| p.to_path_buf()) | ||
} | ||
Some(ReadMe::RelativePath(ref path)) => Some(path.as_ref()), | ||
Some(ReadMe::RelativePath(ref path)) => Some(PathBuf::from(path)), | ||
None => None, | ||
}; | ||
let path = if let Some(path) = path { | ||
project_dir.as_ref().join(path) | ||
} else { | ||
let mut dir = tokio::fs::read_dir(&project_dir).await?; | ||
let mut path = None; | ||
while let Some(entry) = dir.next_entry().await? { | ||
match entry.file_name().to_string_lossy().to_lowercase().as_str() { | ||
"readme.md" | "readme.txt" => {} | ||
_ => continue, | ||
} | ||
let metadata = entry.metadata().await?; | ||
if !metadata.is_file() { | ||
continue; | ||
} | ||
path = Some(entry.path()); | ||
break; | ||
|
||
if let Some(path) = path { | ||
return Ok(Some(path)); | ||
} | ||
|
||
let mut dir = tokio::fs::read_dir(&project_dir).await?; | ||
while let Some(entry) = dir.next_entry().await? { | ||
match entry.file_name().to_string_lossy().to_lowercase().as_str() { | ||
"readme.md" | "readme.txt" => {} | ||
_ => continue, | ||
} | ||
if let Some(path) = path { | ||
path | ||
} else { | ||
return Ok(None); | ||
let metadata = entry.metadata().await?; | ||
if metadata.is_file() { | ||
return Ok(Some(entry.path())); | ||
} | ||
} | ||
|
||
Ok(None) | ||
} | ||
|
||
pub async fn read_readme( | ||
project_dir: impl AsRef<Path>, | ||
readme: Option<&ReadMe>, | ||
) -> Result<Option<String>, ReadmeError> { | ||
let path = match get_readme_path(project_dir, readme).await? { | ||
Some(path) => path, | ||
None => return Ok(None), | ||
}; | ||
|
||
match path | ||
.extension() | ||
.map(|ext| ext.to_string_lossy().to_lowercase()) | ||
.as_deref() | ||
{ | ||
Some("md") | Some("txt") | None => {} | ||
_ => { | ||
return Err(ReadMeError::ContentTypeNotSupported); | ||
} | ||
_ => return Err(ReadmeError::ContentTypeNotSupported), | ||
} | ||
|
||
if !tokio::fs::try_exists(&path).await? { | ||
return Err(ReadMeError::NotFound); | ||
return Err(ReadmeError::NotFound); | ||
} | ||
|
||
Ok(Some(tokio::fs::read_to_string(path).await?)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# aqora | ||
.aqora | ||
.venv | ||
__aqora__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
![Aqora Score Badge](https://img.shields.io/badge/score-0-4328e5?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAIWSURBVHgBjZI/bBJxFMe//5x3BE9D2waCeZiEwNxECcbHSwmGt3qZkwcnB2Q0cFAR6d2Mk6KgcHNQSeHwmJaJ06XYmICprEq1PbaUk7ugJ93p1ToYPpb3svv5fve5/2+P8IRjqqdS4MGiwDTQFx1f2stx4+Kip7Mi3KsKIVj87Kq7zj2z/qoJoajK15IAzTtxVlRiREFIi2ZB6Hg57yoIHEpC0k7lTGL16oRLTk3JFQmGcjkgkA0H4gEBWfSWShyHFIoet+/EyCbh9GJ2B+hx24JvILU2SwiYhyCA4Q5feb6I3bRskyLGMuN6ZriEAsBqo9z3nhYkY/F0Q8BQznUjSQuvBseV9sshNzbArU0zdAAWbOsejOYOmpzY7ZiSJL+hMJKQoqeXh+qkuOogCuj48h4tlyg5Qncw/z3brKrjoLbfRlTfQWwQ46w6zRmHM7edn5Zd8xi5t9EH8MVVUN0B5aPcvcWmwKHxX2+c7Jtm5ddsaf4K2z9WEXrYznT2axXOVlLGg7JNdYf1BxCI6ynHpReUYvv4aVrfU1wdk8ResDel1V8r5XBBsj7wzie8NyLxgE7Q94nKL6h17B3Pglet+2N91hfK0+sxLEx0V9rgtfzM9feXdpsr6DRLI2V8SLw3PtmJ7xN58Z92rPqC37yeaPU7Pa/ffDq0wSyGKPHXav+9OBxVD215HW64k1vSp7ZI6/+d34DKO3EcR6BAbMAAAAASUVORK5CYII=&labelColor=eceafc&link=http://localhost:8080/competitions/test) | ||
rr | ||
![Aqora badge](https://img.shields.io/badge/aqora-4328e5?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAIWSURBVHgBjZI%2FbBJxFMe%2F7%2F5x3BE9D2waCeZiEwNxECcbHSwmGt3qZkwcnB2Q0cFAR6d2Mk6KgcHNQSeHwmJaJ06XYmICprEq1PbaUk7ugJ93p1ToYPpb3svv5fve5%2F2%2BP8IRjqqdS4MGiwDTQFx1f2stx4%2BKip7Mi3KsKIVj87Kq7zj2z%2FqoJoajK15IAzTtxVlRiREFIi2ZB6Hg57yoIHEpC0k7lTGL16oRLTk3JFQmGcjkgkA0H4gEBWfSWShyHFIoet%2B%2FEyCbh9GJ2B%2Bhx24JvILU2SwiYhyCA4Q5feb6I3bRskyLGMuN6ZriEAsBqo9z3nhYkY%2FF0Q8BQznUjSQuvBseV9sshNzbArU0zdAAWbOsejOYOmpzY7ZiSJL%2BhMJKQoqeXh%2BqkuOogCuj48h4tlyg5Qncw%2Fz3brKrjoLbfRlTfQWwQ46w6zRmHM7edn5Zd8xi5t9EH8MVVUN0B5aPcvcWmwKHxX2%2Bc7Jtm5ddsaf4K2z9WEXrYznT2axXOVlLGg7JNdYf1BxCI6ynHpReUYvv4aVrfU1wdk8ResDel1V8r5XBBsj7wzie8NyLxgE7Q94nKL6h17B3Pglet%2B2N91hfK0%2BsxLEx0V9rgtfzM9feXdpsr6DRLI2V8SLw3PtmJ7xN58Z92rPqC37yeaPU7Pa%2FffDq0wSyGKPHXav%2B9OBxVD215HW64k1vSp7ZI6%2F%2Bd34DKO3EcR6BAbMAAAAASUVORK5CYII%3D&labelColor=eceafc&link=https%3A%2F%2Faqora.io%2Fcompetitions%2Ftest%2F) | ||
|
||
# test Submission | ||
|
||
You can find a template notebook in `submission/solution.ipynb`. | ||
Fill in your solution. You can run the notebook locally to test your | ||
solution by running the following in the terminal | ||
|
||
```bash | ||
aqora test | ||
``` | ||
|
||
And when you are ready to submit run | ||
|
||
```bash | ||
aqora upload | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[project] | ||
name = "submission" | ||
version = "0.1.3" | ||
requires-python = ">=3.8" | ||
readme = "README.md" | ||
|
||
# You can add dependencies with `aqora add` | ||
dependencies = [] | ||
|
||
[build-system] | ||
requires = [ | ||
"uv>=0.4.20", | ||
"setuptools>=75", | ||
"wheel>=0.44", | ||
] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["."] | ||
[tool.setuptools.package-data] | ||
submission = ["*"] | ||
|
||
[tool.aqora] | ||
type = "submission" | ||
competition = "test" | ||
|
||
[tool.aqora.refs] | ||
solution = { path = "submission.solution", notebook = true } |
Oops, something went wrong.