diff --git a/.hgignore b/.hgignore
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_LmhnaWdub3Jl..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_LmhnaWdub3Jl 100644
--- a/.hgignore
+++ b/.hgignore
@@ -56,8 +56,6 @@
 doc/build
 doc/html
 doc/man
-MANIFEST
-MANIFEST.in
 patches
 mercurial/__modulepolicy__.py
 mercurial/__version__.py
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000000000000000000000000000000000000..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_TUFOSUZFU1QuaW4=
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,5 @@
+include mercurial/__version__.py
+include doc/*.html
+include doc/*.1 doc/*.5 doc/*.8
+include doc/html/*.html
+include doc/man/*.1
diff --git a/Makefile b/Makefile
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_TWFrZWZpbGU=..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_TWFrZWZpbGU= 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,6 @@
 export LANGUAGE=C
 export LC_ALL=C
 TESTFLAGS ?= $(shell echo $$HGTESTFLAGS)
-OSXVERSIONFLAGS ?= $(shell echo $$OSXVERSIONFLAGS)
 CARGO = cargo
 
 # Set this to e.g. "mingw32" to use a non-default compiler.
@@ -43,7 +42,7 @@
 	@echo 'Commonly used make targets:'
 	@echo '  all          - build program and documentation'
 	@echo '  install      - install program and man pages to $$PREFIX ($(PREFIX))'
-	@echo '  install-home - install with setup.py install --home=$$HOME ($(HOME))'
+	@echo '  install-home - install with pip install --user'
 	@echo '  local        - build for inplace usage'
 	@echo '  tests        - run all tests in the automatic test suite'
 	@echo '  test-foo     - run only specified tests (e.g. test-merge1.t)'
@@ -63,7 +62,7 @@
 local:
 	$(PYTHON) -m venv $(VENV_NAME) --clear --upgrade-deps
 	MERCURIAL_SETUP_MAKE_LOCAL=1 $(VENV_NAME)/$(PYBINDIRNAME)/python -m \
-	  pip install -e . -v --config-settings --global-option=$(PURE)
+	  pip install -e . -v --config-settings --global-option="$(PURE)"
 	env HGRCPATH= $(VENV_NAME)/$(PYBINDIRNAME)/hg version
 
 build:
@@ -87,7 +86,7 @@
 	find contrib doc hgext hgext3rd i18n mercurial tests hgdemandimport \
 		\( -name '*.py[cdo]' -o -name '*.so' \) -exec rm -f '{}' ';'
 	rm -rf .venv_*
-	rm -f MANIFEST MANIFEST.in hgext/__index__.py tests/*.err
+	rm -f hgext/__index__.py tests/*.err
 	rm -f mercurial/__modulepolicy__.py
 	if test -d .hg; then rm -f mercurial/__version__.py; fi
 	rm -rf build mercurial/locale
@@ -101,8 +100,8 @@
 
 install: install-bin install-doc
 
-install-bin: build
-	$(PYTHON) setup.py $(PURE) install --root="$(DESTDIR)/" --prefix="$(PREFIX)" --force
+install-bin:
+	$(PYTHON) -m pip install --prefix="$(PREFIX)" --force -v --config-settings --global-option="$(PURE)"
 
 install-chg: build-chg
 	make -C contrib/chg install PREFIX="$(PREFIX)"
@@ -112,8 +111,8 @@
 
 install-home: install-home-bin install-home-doc
 
-install-home-bin: build
-	$(PYTHON) setup.py $(PURE) install --home="$(HOME)" --prefix="" --force
+install-home-bin:
+	$(PYTHON) -m pip install --user --force -v --config-settings --global-option="$(PURE)"
 
 install-home-doc: doc
 	cd doc && $(MAKE) $(MFLAGS) PREFIX="$(HOME)" install
@@ -121,13 +120,5 @@
 install-rhg: build-rhg
 	install -m 755 rust/target/release/rhg "$(PREFIX)"/bin/
 
-MANIFEST-doc:
-	$(MAKE) -C doc MANIFEST
-
-MANIFEST.in: MANIFEST-doc
-	hg manifest | sed -e 's/^/include /' > MANIFEST.in
-	echo include mercurial/__version__.py >> MANIFEST.in
-	sed -e 's/^/include /' < doc/MANIFEST >> MANIFEST.in
-
 dist:	tests dist-notests
 
@@ -132,6 +123,6 @@
 dist:	tests dist-notests
 
-dist-notests:	doc MANIFEST.in
+dist-notests:	doc
 	TAR_OPTIONS="--owner=root --group=root --mode=u+w,go-w,a+rX-s" $(PYTHON) setup.py -q sdist
 
 check: tests
@@ -238,33 +229,6 @@
 $(packaging_targets):
 	$(MAKE) -C contrib/packaging $(MAKEFLAGS) $@
 
-osx:
-	rm -rf build/mercurial
-	/usr/bin/python2.7 setup.py install --optimize=1 \
-	  --root=build/mercurial/ --prefix=/usr/local/ \
-	  --install-lib=/Library/Python/2.7/site-packages/
-	make -C doc all install DESTDIR="$(PWD)/build/mercurial/"
-        # Place a bogon .DS_Store file in the target dir so we can be
-        # sure it doesn't get included in the final package.
-	touch build/mercurial/.DS_Store
-	make -C contrib/chg \
-	  HGPATH=/usr/local/bin/hg \
-	  PYTHON=/usr/bin/python2.7 \
-	  DESTDIR=../../build/mercurial \
-	  PREFIX=/usr/local \
-	  clean install
-	mkdir -p $${OUTPUTDIR:-dist}
-	HGVER=$$(python contrib/genosxversion.py $(OSXVERSIONFLAGS) build/mercurial/Library/Python/2.7/site-packages/mercurial/__version__.py) && \
-	OSXVER=$$(sw_vers -productVersion | cut -d. -f1,2) && \
-	pkgbuild --filter \\.DS_Store --root build/mercurial/ \
-	  --identifier org.mercurial-scm.mercurial \
-	  --version "$${HGVER}" \
-	  build/mercurial.pkg && \
-	productbuild --distribution contrib/packaging/macosx/distribution.xml \
-	  --package-path build/ \
-	  --version "$${HGVER}" \
-	  --resources contrib/packaging/macosx/ \
-	  "$${OUTPUTDIR:-dist/}"/Mercurial-"$${HGVER}"-macosx"$${OSXVER}".pkg
 
 pyoxidizer:
 	$(PYOXIDIZER) build --path ./rust/hgcli --release
@@ -309,4 +273,4 @@
 	dist dist-notests check tests rust-tests check-code format-c \
 	update-pot pyoxidizer pyoxidizer-windows-tests pyoxidizer-macos-tests \
 	$(packaging_targets) \
-	osx pytype-docker
+	pytype-docker
diff --git a/doc/Makefile b/doc/Makefile
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_ZG9jL01ha2VmaWxl..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_ZG9jL01ha2VmaWxl 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -29,6 +29,8 @@
 
 .PHONY: all man html install clean knownrefs
 
+all: man html
+
 # Generate a list of hg commands and extensions.
 commandlist.txt: $(GENDOC)
 	${GENDOCCMD} commandlist > $@.tmp
@@ -135,7 +137,7 @@
 # - help topics: topic-foo (html), hgfoo (man)
 # - extensions: ext-foo (html), hgext-foo (man)
 #
-# Man pages for commands are in section 1 (user commands), topics and 
+# Man pages for commands are in section 1 (user commands), topics and
 # extensions are in section 7 (miscellanea)
 #
 # NOTE: topics and extension are temporarily disabled for man pages because
@@ -158,9 +160,6 @@
 # Also add the HTML index page
 HTML+=$(HTMLOUT)/index.html
 
-
-all: man html
-
 man: $(MAN)
 
 html: $(HTML)
@@ -206,13 +205,6 @@
 	$(PYTHON) runrst html --hg-individual-pages $(RSTARGS) --halt warning \
 	  --link-stylesheet --stylesheet-path style.css $(BUILDDIR)/$*.gendoc.txt $@
 
-MANIFEST: man html
-# tracked files are already in the main MANIFEST
-	$(RM) $@
-	for i in $(MAN) $(HTML); do \
-	  echo "doc/$$i" >> $@ ; \
-	done
-
 install: man
 	for i in $(MAN) ; do \
 	  subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \
@@ -225,4 +217,4 @@
 # $(HTML) only has the basic topics, so we need to delete $(HTMLOUT)/*.html and
 # other similar files "by hand" here.
 clean:
-	$(RM) $(MAN) $(HTML) common.txt $(SOURCES) MANIFEST *.gendoc.txt $(BUILDFILES) $(BUILDDIR)/*.gendoc.* $(HTMLOUT)/*.html
+	$(RM) $(MAN) $(HTML) common.txt $(SOURCES) *.gendoc.txt $(BUILDFILES) $(BUILDDIR)/*.gendoc.* $(HTMLOUT)/*.html
diff --git a/tests/run-tests.py b/tests/run-tests.py
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_dGVzdHMvcnVuLXRlc3RzLnB5..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_dGVzdHMvcnVuLXRlc3RzLnB5 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3425,6 +3425,7 @@
         if self.options.pure:
             os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure"
             os.environ["HGMODULEPOLICY"] = "py"
+            os.environ.pop("HGWITHRUSTEXT", None)
         if self.options.rust:
             os.environ["HGMODULEPOLICY"] = "rust+c"
         if self.options.no_rust:
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_dGVzdHMvdGVzdC1jaGVjay1jb2RlLnQ=..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_dGVzdHMvdGVzdC1jaGVjay1jb2RlLnQ= 100644
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -65,6 +65,7 @@
   CONTRIBUTING
   CONTRIBUTORS
   COPYING
+  MANIFEST.in
   Makefile
   README.rst
   hg
diff --git a/tests/test-hghave.t b/tests/test-hghave.t
index 24b9d6ffc6d35e823290abdeae98fb2bc6a3a29d_dGVzdHMvdGVzdC1oZ2hhdmUudA==..257f7b59d77e2c59b5eed1931ae90a3aaa7c464c_dGVzdHMvdGVzdC1oZ2hhdmUudA== 100644
--- a/tests/test-hghave.t
+++ b/tests/test-hghave.t
@@ -1,5 +1,7 @@
   $ . "$TESTDIR/helpers-testrepo.sh"
 
+  $ . "$TESTDIR/helper-runtests.sh"
+
 Testing that hghave does not crash when checking features
 
   $ hghave --test-features 2>/dev/null