Skip to content

Commit

Permalink
Merge pull request #201 from davidbrochart/fix_multipy
Browse files Browse the repository at this point in the history
Fix multi python package publishing
  • Loading branch information
blink1073 authored Nov 23, 2021
2 parents 78f587f + 2f3c903 commit 1bc9790
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/source/get_started/making_first_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ already uses Jupyter Releaser.
owner2/repo2,token2
```

If you have multiple Python packages in one repository, you can point to them as follows:
If you have multiple Python packages in the same repository, you can point to them as follows:

```text
owner1/repo1/path/to/package1,token1
owner1/repo1/path/to/package2,token1
owner1/repo1/path/to/package2,token2
```

- If the repo generates npm release(s), add access token for [npm](https://docs.npmjs.com/creating-and-viewing-access-tokens), saved as `NPM_TOKEN` in "Secrets".
Expand Down
4 changes: 2 additions & 2 deletions docs/source/how_to_guides/convert_repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ A. Prep the `jupyter_releaser` fork:
owner2/repo2,token2
```

If you have multiple Python packages in one repository, you can point to them as follows:
If you have multiple Python packages in the same repository, you can point to them as follows:

```text
owner1/repo1/path/to/package1,token1
owner1/repo1/path/to/package2,token1
owner1/repo1/path/to/package2,token2
```

- [ ] If needed, add access token for [npm](https://docs.npmjs.com/creating-and-viewing-access-tokens), saved as `NPM_TOKEN`.
Expand Down
6 changes: 3 additions & 3 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def main(force):
envvar="RH_PYTHON_PACKAGES",
default=["."],
multiple=True,
help="The list of paths to Python packages",
help='The list of strings of the form "path_to_package:name_of_package"',
)
]

Expand Down Expand Up @@ -291,7 +291,7 @@ def prep_git(ref, branch, repo, auth, username, git_url):
def bump_version(version_spec, version_cmd, python_packages):
"""Prep git and env variables and bump version"""
prev_dir = os.getcwd()
for python_package in python_packages:
for python_package in [p.split(":")[0] for p in python_packages]:
os.chdir(python_package)
lib.bump_version(version_spec, version_cmd)
os.chdir(prev_dir)
Expand Down Expand Up @@ -387,7 +387,7 @@ def build_python(dist_dir, python_packages):
"""Build Python dist files"""
prev_dir = os.getcwd()
clean = True
for python_package in python_packages:
for python_package in [p.split(":")[0] for p in python_packages]:
os.chdir(python_package)
if not util.PYPROJECT.exists() and not util.SETUP_PY.exists():
util.log(
Expand Down
24 changes: 17 additions & 7 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,15 @@ def publish_assets(
if npm_token:
util.run("npm whoami")

res = python_package.split(":")
python_package_path = res[0]
if len(res) == 2:
python_package_name = res[1].replace("-", "_")
else:
python_package_name = ""

if len(glob(f"{dist_dir}/*.whl")):
twine_token = python.get_pypi_token(release_url, python_package)
twine_token = python.get_pypi_token(release_url, python_package_path)

if dry_run:
# Start local pypi server with no auth, allowing overwrites,
Expand All @@ -413,12 +420,15 @@ def publish_assets(
name = Path(path).name
suffix = Path(path).suffix
if suffix in [".gz", ".whl"]:
env = os.environ.copy()
env["TWINE_PASSWORD"] = twine_token
# NOTE: Do not print the env since a twine token extracted from
# a PYPI_TOKEN_MAP will not be sanitized in output
util.retry(f"{twine_cmd} {name}", cwd=dist_dir, env=env)
found = True
if name.startswith(
python_package_name
): # FIXME: not enough to know it's the right package
env = os.environ.copy()
env["TWINE_PASSWORD"] = twine_token
# NOTE: Do not print the env since a twine token extracted from
# a PYPI_TOKEN_MAP will not be sanitized in output
util.retry(f"{twine_cmd} {name}", cwd=dist_dir, env=env)
found = True
elif suffix == ".tgz":
# Ignore already published versions
try:
Expand Down

0 comments on commit 1bc9790

Please sign in to comment.