Workspaces vs namespaces #1162
vladimirvrabely
started this conversation in
General
Replies: 1 comment
-
Yeah - you can jang it around with bash and it works fine. There are some matters of taste to work out so I'm not committing this yet but here are a couple of scripts that do what you suggest. Assumptions
Create a NamespaceI have a zsh script called
autoload colors; colors
rm -r "${1}"
rye init "${1}" --virtual
cd "${1}"
print -P "Adding…\n%F{green}[tool.rye.workspace]\nmembers = [\"${namespace}_*\"]%f"
print -P "to %F{cyan}./${1}/pyproject.toml%f"
echo "\n[tool.rye.workspace]\nmembers = [\"${1}_*\"]" >> ./pyproject.toml
cp ../mkpkg.sh . Create a PackageThe other script,
autoload colors; colors
namespace=${PWD##*/}
subdir="${namespace}_${1}"
print -P "\nCreating the %F{cyan}${1}%f project in %F{cyan}…/${namespace}/${subdir}/%f"
rye init --script "${subdir}/"
mkdir "${subdir}/src/${namespace}"
mv "${subdir}/src/${subdir}" "${subdir}/src/${namespace}"
mv "${subdir}/src/${namespace}/${subdir}" "${subdir}/src/${namespace}/${1}"
tree --filesfirst
print -P "\nRemoving %F{red}_${1}%f from"
print -P "%F{green}[tool.hatch.build.targets.wheel]%f"
print -P "%F{green}packages = [\"src/${namespace}%f%F{red}_${1}%f%F{green}\"]%f"
print -P "in %F{cyan}${subdir}/pyproject.toml%f"
sed -i '' "/\[tool.hatch.build.targets.wheel\]/,/^\[/ s/src\/${namespace}_${1}/src\/${namespace}/" ${subdir}/pyproject.toml
print -P "%F{red}${namespace}_%f%F{green}${1} = \"${namespace}_${1}\"%f"
print -P "\nRemoving %F{red}${namespace}_%f from"
print -P "%F{green}[projects.scripts]%f"
print -P "in %F{cyan}${subdir}/pyproject.toml%f\n"
sed -i '' "/\[project.scripts\]/,/^/ s/\"${namespace}-${1}\"/${1}/" ${subdir}/pyproject.toml
print -P "\nTurning %F{green}${namespace}%f%F{red}_%f%F{green}${1}%f"
print -P "into %F{green}${namespace}%f%F{red}.%f%F{green}${1}%f"
print -P "in %F{green}[projects.scripts]%f"
print -P "in %F{cyan}${subdir}/pyproject.toml%f"
sed -i '' "/\[project.scripts\]/,/^/ s/_/./g" ${subdir}/pyproject.toml
if ! grep -q '^\[tool.rye.workspace\]' pyproject.toml; then
print -P "Adding…\n%F{green}[tool.rye.workspace]\nmembers = [\"${namespace}_*\"]%f"
print -P "to %F{cyan}./pyproject.toml%f"
echo "\n[tool.rye.workspace]\nmembers = [\"${namespace}_*\"]" >> ../pyproject.toml
fi Example~ % source mknsp.sh namespace
namespace % source mkpkg.sh project
namespace % source mkpkg.sh library
namespace % rye sync
namespace % rye run project
namespace % rye run library
Usage
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
rye
introduces workspaces to manage multiple packages which seems to be inspired by cargo workspaces in Rust.Interestingly, the provided workspace example uses a prefix for workspace members. I'm wondering what is the relation to Python namespaces?
The
rye
documentation doesn't seem to mention namespaces at all. Does it support them? Are workspaces meant to be an alternative to namespaces or are they complementary? Do you have any suggestions or opionions here? (I couldn't find any related issue or discussion)Beta Was this translation helpful? Give feedback.
All reactions