Skip to content

Commit

Permalink
docs(changeset): add option to force use Twine credentials for publis…
Browse files Browse the repository at this point in the history
…hing to PyPI
  • Loading branch information
dphuang2 committed Oct 30, 2023
1 parent 94fc6dd commit 8c03fa0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions generator/konfig-dash/.changeset/lemon-tables-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'konfig-cli': minor
---

add option to force use Twine credentials for publishing to PyPI
15 changes: 12 additions & 3 deletions generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,18 @@ const publishScripts = {
version,
gitlabRepositoryId,
skipTag,
useTwine,
}: {
test?: boolean
token?: string
version: string
gitlabRepositoryId?: string
skipTag?: boolean
useTwine?: boolean
}) => {
const repository = test ? '-r testpypi ' : ''
const credentials = token !== undefined ? `-u __token__ -p ${token} ` : ''
const credentials =
token !== undefined && !useTwine ? `-u __token__ -p ${token} ` : ''
const gitTagCommands = generateGitTagCommands({
version,
generator: 'python',
Expand Down Expand Up @@ -323,6 +326,11 @@ export default class Publish extends Command {
description: 'Specify all generators',
exclusive: ['generator'],
}),
useTwine: Flags.boolean({
name: 'twine',
char: 'T',
description: 'Force use TWINE_USERNAME and TWINE_PASSWORD for publishing',
}),
test: Flags.boolean({ name: 'test', char: 't' }),
skipRemoteCheck: Flags.boolean({
name: 'skipRemoteCheck',
Expand Down Expand Up @@ -557,7 +565,8 @@ export default class Publish extends Command {
) {
const pythonConfig = python.parse(generatorConfig)
const usesToken =
pythonConfig.pypiApiTokenEnvironmentVariable !== undefined
pythonConfig.pypiApiTokenEnvironmentVariable !== undefined &&
!flags.useTwine
const testPyPI = flags.test || pythonConfig.testPyPI
if (testPyPI && !usesToken) {
if (!process.env.TEST_TWINE_USERNAME)
Expand Down Expand Up @@ -588,7 +597,6 @@ export default class Publish extends Command {
throw Error(
`Set ${pythonConfig.pypiApiTokenEnvironmentVariable} environment variable to publish to PyPI`
)

if (pythonConfig.gitlabRepositoryId !== undefined) {
if (!process.env.GITLAB_USERNAME)
CliUx.ux.error(
Expand All @@ -603,6 +611,7 @@ export default class Publish extends Command {
script: publishScripts['pypi']({
test: !!testPyPI,
token,
useTwine: flags.useTwine,
version: pythonConfig.version,
gitlabRepositoryId: pythonConfig.gitlabRepositoryId,
skipTag: flags.skipTag,
Expand Down

0 comments on commit 8c03fa0

Please sign in to comment.